You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Karl Fogel <kf...@newton.ch.collab.net> on 2002/07/15 06:59:52 UTC
[PATCH] identity tables for i18n (second chance for review)
Hi, this is a forwarded patch from Marcus Comstedt <ma...@mc.pp.se>,
to do unity conversion more efficiently and reliably when xlating. It
looks quite sane to me, and I'd like to apply it. I've posted it here
once before, but there were other discussions going on at the time and
I'm not sure if anyone saw it. Here's a second chance for review.
Please let me know if there's any reason not to apply this; the patch
seems right to me, but I'm not the world's greatest i18n expert
either.
* i18n/unix/xlate.c
(make_identity_table): New function to create a sbcs_table that
performs unity conversion. See apr_xlate_open.
(apr_xlate_open): When topage and frompage are the same,
make_identity_table is used to create a shortcut instead of
calling iconv_open. The reason being that iconv_open can fail in
this case.
Submitted by: Marcus Comstedt <ma...@mc.pp.se>
Reviewed by: Karl Fogel <kf...@collab.net>
Index: i18n/unix/xlate.c
===================================================================
RCS file: /home/cvspublic/apr/i18n/unix/xlate.c,v
retrieving revision 1.26
diff -u -r1.26 xlate.c
--- i18n/unix/xlate.c 8 Jun 2002 18:53:13 -0000 1.26
+++ i18n/unix/xlate.c 28 Jun 2002 14:52:34 -0000
@@ -219,6 +219,14 @@
}
#endif /* HAVE_ICONV */
+static void make_identity_table(apr_xlate_t *convset)
+{
+ int i;
+ convset->sbcs_table = apr_palloc(convset->pool, 256);
+ for (i=0; i<256; i++)
+ convset->sbcs_table[i] = i;
+}
+
apr_status_t apr_xlate_open(apr_xlate_t **convset, const char *topage,
const char *frompage, apr_pool_t *pool)
{
@@ -251,6 +259,12 @@
set found to non-zero if found in the cache
#endif
+ if (!found && !strcmp(topage, frompage)) {
+ /* to and from are the same */
+ found = 1;
+ make_identity_table(new);
+ }
+
#ifdef HAVE_ICONV
if (!found) {
new->ich = iconv_open(topage, frompage);
@@ -259,7 +273,8 @@
}
found = 1;
check_sbcs(new);
- }
+ } else
+ new->ich = (iconv_t)-1;
#endif /* HAVE_ICONV */
if (found) {