X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpropername.c;h=381a7a72cbafe178f3f81149812f948ed753060c;hb=5b63b76064a130bdaadb1fda7ab50e82896446e1;hp=0d3681e264aeeadef797d80dfa30bb06c756557c;hpb=c9678b023ef80b4a807e39a0b225b6b4acc58fb1;p=gnulib.git diff --git a/lib/propername.c b/lib/propername.c index 0d3681e26..381a7a72c 100644 --- a/lib/propername.c +++ b/lib/propername.c @@ -1,5 +1,5 @@ /* Localization of proper names. - Copyright (C) 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2006-2009 Free Software Foundation, Inc. Written by Bruno Haible , 2006. This program is free software: you can redistribute it and/or modify @@ -31,9 +31,7 @@ #include "trim.h" #include "mbchar.h" -#if HAVE_MBRTOWC -# include "mbuiter.h" -#endif +#include "mbuiter.h" #include "localcharset.h" #include "c-strcase.h" #include "xstriconv.h" @@ -60,7 +58,6 @@ mbsstr_trimmed_wordbounded (const char *string, const char *sub) break; else { -#if HAVE_MBRTOWC if (MB_CUR_MAX > 1) { mbui_iterator_t string_iter; @@ -117,7 +114,6 @@ mbsstr_trimmed_wordbounded (const char *string, const char *sub) string = tsub_in_string + mb_len (mbui_cur (string_iter)); } else -#endif /* HAVE_MBRTOWC */ { bool word_boundary_before; const char *p; @@ -205,15 +201,32 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8) # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \ || _LIBICONV_VERSION >= 0x0105 { + char *converted_translit; + size_t len = strlen (locale_code); char *locale_code_translit = XNMALLOC (len + 10 + 1, char); memcpy (locale_code_translit, locale_code, len); memcpy (locale_code_translit + len, "//TRANSLIT", 10 + 1); - name_converted_translit = alloc_name_converted_translit = + converted_translit = xstr_iconv (name_utf8, "UTF-8", locale_code_translit); free (locale_code_translit); + + if (converted_translit != NULL) + { +# if !_LIBICONV_VERSION + /* Don't use the transliteration if it added question marks. + glibc's transliteration falls back to question marks; libiconv's + transliteration does not. + mbschr is equivalent to strchr in this case. */ + if (strchr (converted_translit, '?') != NULL) + free (converted_translit); + else +# endif + name_converted_translit = alloc_name_converted_translit = + converted_translit; + } } # endif #endif @@ -229,7 +242,10 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8) name_converted_translit != NULL ? name_converted_translit : name_ascii); - if (translation != name_ascii) + /* See whether we have a translation. Some translators have not understood + that they should use the UTF-8 form of the name, if possible. So if the + translator provided a no-op translation, we ignore it. */ + if (strcmp (translation, name_ascii) != 0) { /* See whether the translation contains the original name. */ if (mbsstr_trimmed_wordbounded (translation, name_ascii) @@ -270,7 +286,7 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8) } } -#ifdef TEST +#ifdef TEST1 # include int main (int argc, char *argv[]) @@ -281,3 +297,15 @@ main (int argc, char *argv[]) return 0; } #endif + +#ifdef TEST2 +# include +# include +int +main (int argc, char *argv[]) +{ + setlocale (LC_ALL, ""); + printf ("%s\n", proper_name_utf8 ("Franc,ois Pinard", "Fran\303\247ois Pinard")); + return 0; +} +#endif