Mercurial > hg > octave-kai > gnulib-hg
annotate lib/propername.c @ 14612:6ef4f1f39105
Revert "use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE"
This reverts commit 349d7fe0e307d59d508b3579317ee8d4eacfeb9c.
Revert accidentally-pushed patch. Not yet ready.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Mon, 25 Apr 2011 10:38:33 +0200 |
parents | b427a1938336 |
children | 376ca4146b05 |
rev | line source |
---|---|
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Localization of proper names. |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
13885
diff
changeset
|
2 Copyright (C) 2006-2011 Free Software Foundation, Inc. |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 Written by Bruno Haible <bruno@clisp.org>, 2006. |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 (at your option) any later version. |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 GNU General Public License for more details. |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 #include <config.h> |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 /* Specification. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include "propername.h" |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <ctype.h> |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <stdbool.h> |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <stdio.h> |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 #include <stdlib.h> |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 #include <string.h> |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 #if HAVE_ICONV |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 # include <iconv.h> |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 #endif |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 #include "trim.h" |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 #include "mbchar.h" |
10954
a0bbe1a6f787
Remove HAVE_MBRTOWC conditionals. Use mbrtowc unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
10225
diff
changeset
|
34 #include "mbuiter.h" |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 #include "localcharset.h" |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 #include "c-strcase.h" |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 #include "xstriconv.h" |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 #include "xalloc.h" |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 #include "gettext.h" |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 /* Tests whether STRING contains trim (SUB), starting and ending at word |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 boundaries. |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 Here, instead of implementing Unicode Standard Annex #29 for determining |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 word boundaries, we assume that trim (SUB) starts and ends with words and |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 only test whether the part before it ends with a non-word and the part |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 after it starts with a non-word. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 static bool |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 mbsstr_trimmed_wordbounded (const char *string, const char *sub) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 char *tsub = trim (sub); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 bool found = false; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 for (; *string != '\0';) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 const char *tsub_in_string = mbsstr (string, tsub); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 if (tsub_in_string == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
58 break; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
60 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
61 if (MB_CUR_MAX > 1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
62 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
63 mbui_iterator_t string_iter; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
64 bool word_boundary_before; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
65 bool word_boundary_after; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
67 mbui_init (string_iter, string); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
68 word_boundary_before = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
69 if (mbui_cur_ptr (string_iter) < tsub_in_string) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
70 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
71 mbchar_t last_char_before_tsub; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
72 do |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
73 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
74 if (!mbui_avail (string_iter)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
75 abort (); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
76 last_char_before_tsub = mbui_cur (string_iter); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
77 mbui_advance (string_iter); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
78 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
79 while (mbui_cur_ptr (string_iter) < tsub_in_string); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
80 if (mb_isalnum (last_char_before_tsub)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
81 word_boundary_before = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
82 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
84 mbui_init (string_iter, tsub_in_string); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
85 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
86 mbui_iterator_t tsub_iter; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
88 for (mbui_init (tsub_iter, tsub); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
89 mbui_avail (tsub_iter); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
90 mbui_advance (tsub_iter)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
91 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
92 if (!mbui_avail (string_iter)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
93 abort (); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
94 mbui_advance (string_iter); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
95 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
96 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
97 word_boundary_after = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
98 if (mbui_avail (string_iter)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
99 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
100 mbchar_t first_char_after_tsub = mbui_cur (string_iter); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
101 if (mb_isalnum (first_char_after_tsub)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
102 word_boundary_after = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
103 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
105 if (word_boundary_before && word_boundary_after) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
106 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
107 found = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
108 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
109 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
111 mbui_init (string_iter, tsub_in_string); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
112 if (!mbui_avail (string_iter)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
113 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
114 string = tsub_in_string + mb_len (mbui_cur (string_iter)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
115 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
116 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
117 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
118 bool word_boundary_before; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
119 const char *p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
120 bool word_boundary_after; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
122 word_boundary_before = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
123 if (string < tsub_in_string) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
124 if (isalnum ((unsigned char) tsub_in_string[-1])) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
125 word_boundary_before = false; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
127 p = tsub_in_string + strlen (tsub); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
128 word_boundary_after = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
129 if (*p != '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
130 if (isalnum ((unsigned char) *p)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
131 word_boundary_after = false; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
132 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
133 if (word_boundary_before && word_boundary_after) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
134 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
135 found = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
136 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
137 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
139 if (*tsub_in_string == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
140 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
141 string = tsub_in_string + 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
142 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
143 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
145 free (tsub); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 return found; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
147 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
148 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
149 /* Return the localization of NAME. NAME is written in ASCII. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
150 |
14612
6ef4f1f39105
Revert "use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE"
Jim Meyering <meyering@redhat.com>
parents:
14610
diff
changeset
|
151 const char * |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 proper_name (const char *name) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 /* See whether there is a translation. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 const char *translation = gettext (name); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 if (translation != name) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 /* See whether the translation contains the original name. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 if (mbsstr_trimmed_wordbounded (translation, name)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
161 return translation; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
163 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
164 /* Return "TRANSLATION (NAME)". */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
165 char *result = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
166 XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
168 sprintf (result, "%s (%s)", translation, name); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
169 return result; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
170 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
171 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
172 else |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
173 return name; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
174 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
175 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
176 /* Return the localization of a name whose original writing is not ASCII. |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
177 NAME_UTF8 is the real name, written in UTF-8 with octal or hexadecimal |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
178 escape sequences. NAME_ASCII is a fallback written only with ASCII |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
179 characters. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
181 const char * |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
182 proper_name_utf8 (const char *name_ascii, const char *name_utf8) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
183 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
184 /* See whether there is a translation. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
185 const char *translation = gettext (name_ascii); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
186 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
187 /* Try to convert NAME_UTF8 to the locale encoding. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 const char *locale_code = locale_charset (); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 char *alloc_name_converted = NULL; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
190 char *alloc_name_converted_translit = NULL; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
191 const char *name_converted = NULL; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
192 const char *name_converted_translit = NULL; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 const char *name; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
194 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
195 if (c_strcasecmp (locale_code, "UTF-8") != 0) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
196 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
197 #if HAVE_ICONV |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
198 name_converted = alloc_name_converted = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
199 xstr_iconv (name_utf8, "UTF-8", locale_code); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
200 |
13885 | 201 # if (((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2) \ |
202 && !defined __UCLIBC__) \ | |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
203 || _LIBICONV_VERSION >= 0x0105 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
204 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
205 char *converted_translit; |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
206 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
207 size_t len = strlen (locale_code); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
208 char *locale_code_translit = XNMALLOC (len + 10 + 1, char); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
209 memcpy (locale_code_translit, locale_code, len); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
210 memcpy (locale_code_translit + len, "//TRANSLIT", 10 + 1); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
211 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
212 converted_translit = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
213 xstr_iconv (name_utf8, "UTF-8", locale_code_translit); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
214 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
215 free (locale_code_translit); |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
216 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
217 if (converted_translit != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
218 { |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
219 # if !_LIBICONV_VERSION |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
220 /* Don't use the transliteration if it added question marks. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
221 glibc's transliteration falls back to question marks; libiconv's |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
222 transliteration does not. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
223 mbschr is equivalent to strchr in this case. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
224 if (strchr (converted_translit, '?') != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
225 free (converted_translit); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
226 else |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
227 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
228 name_converted_translit = alloc_name_converted_translit = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
229 converted_translit; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
230 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
231 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
232 # endif |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
233 #endif |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
234 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
235 else |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
236 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
237 name_converted = name_utf8; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
238 name_converted_translit = name_utf8; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
239 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
240 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
241 /* The name in locale encoding. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
242 name = (name_converted != NULL ? name_converted : |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
243 name_converted_translit != NULL ? name_converted_translit : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
244 name_ascii); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
245 |
11537
0ec84326efef
Ignore no-op translations.
Jim Meyering <meyering@redhat.com>
parents:
10954
diff
changeset
|
246 /* See whether we have a translation. Some translators have not understood |
0ec84326efef
Ignore no-op translations.
Jim Meyering <meyering@redhat.com>
parents:
10954
diff
changeset
|
247 that they should use the UTF-8 form of the name, if possible. So if the |
0ec84326efef
Ignore no-op translations.
Jim Meyering <meyering@redhat.com>
parents:
10954
diff
changeset
|
248 translator provided a no-op translation, we ignore it. */ |
0ec84326efef
Ignore no-op translations.
Jim Meyering <meyering@redhat.com>
parents:
10954
diff
changeset
|
249 if (strcmp (translation, name_ascii) != 0) |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
250 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
251 /* See whether the translation contains the original name. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
252 if (mbsstr_trimmed_wordbounded (translation, name_ascii) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
253 || (name_converted != NULL |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
254 && mbsstr_trimmed_wordbounded (translation, name_converted)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
255 || (name_converted_translit != NULL |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
256 && mbsstr_trimmed_wordbounded (translation, name_converted_translit))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
257 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
258 if (alloc_name_converted != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
259 free (alloc_name_converted); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
260 if (alloc_name_converted_translit != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
261 free (alloc_name_converted_translit); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
262 return translation; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
263 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
264 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
265 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
266 /* Return "TRANSLATION (NAME)". */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
267 char *result = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
268 XNMALLOC (strlen (translation) + 2 + strlen (name) + 1 + 1, char); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
269 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
270 sprintf (result, "%s (%s)", translation, name); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
271 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
272 if (alloc_name_converted != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
273 free (alloc_name_converted); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
274 if (alloc_name_converted_translit != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
275 free (alloc_name_converted_translit); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
276 return result; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
277 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
278 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
279 else |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
280 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
281 if (alloc_name_converted != NULL && alloc_name_converted != name) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
282 free (alloc_name_converted); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
283 if (alloc_name_converted_translit != NULL |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
284 && alloc_name_converted_translit != name) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
285 free (alloc_name_converted_translit); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
286 return name; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
287 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
288 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
289 |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
290 #ifdef TEST1 |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
291 # include <locale.h> |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
292 int |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
293 main (int argc, char *argv[]) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
294 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
295 setlocale (LC_ALL, ""); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
296 if (mbsstr_trimmed_wordbounded (argv[1], argv[2])) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
297 printf("found\n"); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
298 return 0; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
299 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
300 #endif |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
301 |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
302 #ifdef TEST2 |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
303 # include <locale.h> |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
304 # include <stdio.h> |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
305 int |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
306 main (int argc, char *argv[]) |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
307 { |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
308 setlocale (LC_ALL, ""); |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
309 printf ("%s\n", proper_name_utf8 ("Franc,ois Pinard", "Fran\303\247ois Pinard")); |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
310 return 0; |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
311 } |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
312 #endif |