Mercurial > hg > octave-kai > gnulib-hg
annotate lib/propername.c @ 14610:b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sun, 24 Apr 2011 19:02:10 +0200 |
parents | 97fc9a21a8fb |
children | 6ef4f1f39105 |
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 |
14610
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
41 /* The attribute __const__ was added in gcc 2.95. */ |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
42 #undef _GL_ATTRIBUTE_CONST |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
43 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
44 # define _GL_ATTRIBUTE_CONST __attribute__ ((__const__)) |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
45 #else |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
46 # define _GL_ATTRIBUTE_CONST /* empty */ |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
47 #endif |
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
48 |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 /* 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
|
51 boundaries. |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 after it starts with a non-word. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 static bool |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 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
|
58 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 char *tsub = trim (sub); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 bool found = false; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 for (; *string != '\0';) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 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
|
65 if (tsub_in_string == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
66 break; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
68 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
69 if (MB_CUR_MAX > 1) |
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 mbui_iterator_t string_iter; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
72 bool word_boundary_before; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
73 bool word_boundary_after; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
75 mbui_init (string_iter, string); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
76 word_boundary_before = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
77 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
|
78 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
79 mbchar_t last_char_before_tsub; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
80 do |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
81 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
82 if (!mbui_avail (string_iter)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
83 abort (); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
84 last_char_before_tsub = mbui_cur (string_iter); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
85 mbui_advance (string_iter); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
86 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
87 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
|
88 if (mb_isalnum (last_char_before_tsub)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
89 word_boundary_before = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
90 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
92 mbui_init (string_iter, tsub_in_string); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
93 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
94 mbui_iterator_t tsub_iter; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
96 for (mbui_init (tsub_iter, tsub); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
97 mbui_avail (tsub_iter); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
98 mbui_advance (tsub_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 if (!mbui_avail (string_iter)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
101 abort (); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
102 mbui_advance (string_iter); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
103 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
104 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
105 word_boundary_after = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
106 if (mbui_avail (string_iter)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
107 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
108 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
|
109 if (mb_isalnum (first_char_after_tsub)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
110 word_boundary_after = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
111 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
113 if (word_boundary_before && word_boundary_after) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
114 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
115 found = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
116 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
117 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
119 mbui_init (string_iter, tsub_in_string); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
120 if (!mbui_avail (string_iter)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
121 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
122 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
|
123 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
124 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
125 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
126 bool word_boundary_before; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
127 const char *p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
128 bool word_boundary_after; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
130 word_boundary_before = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
131 if (string < tsub_in_string) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
132 if (isalnum ((unsigned char) tsub_in_string[-1])) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
133 word_boundary_before = false; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
135 p = tsub_in_string + strlen (tsub); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
136 word_boundary_after = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
137 if (*p != '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
138 if (isalnum ((unsigned char) *p)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
139 word_boundary_after = false; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
140 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
141 if (word_boundary_before && word_boundary_after) |
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 found = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
144 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
145 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
147 if (*tsub_in_string == '\0') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
148 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
149 string = tsub_in_string + 1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
150 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
151 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 free (tsub); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 return found; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 } |
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 /* 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
|
158 |
14610
b427a1938336
use _GL_ATTRIBUTE_CONST and _GL_ATTRIBUTE_PURE
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
159 const char * _GL_ATTRIBUTE_CONST |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 proper_name (const char *name) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 /* See whether there is a translation. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
163 const char *translation = gettext (name); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
164 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
165 if (translation != name) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 /* 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
|
168 if (mbsstr_trimmed_wordbounded (translation, name)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
169 return translation; |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
170 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
171 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
172 /* Return "TRANSLATION (NAME)". */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
173 char *result = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
174 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
|
175 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
176 sprintf (result, "%s (%s)", translation, name); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
177 return result; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
178 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
179 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 else |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
181 return name; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
182 } |
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 /* 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
|
185 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
|
186 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
|
187 characters. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 const char * |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
190 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
|
191 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
192 /* See whether there is a translation. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 const char *translation = gettext (name_ascii); |
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 /* 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
|
196 const char *locale_code = locale_charset (); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
197 char *alloc_name_converted = NULL; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
198 char *alloc_name_converted_translit = NULL; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
199 const char *name_converted = NULL; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
200 const char *name_converted_translit = NULL; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
201 const char *name; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
202 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
203 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
|
204 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
205 #if HAVE_ICONV |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
206 name_converted = alloc_name_converted = |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
207 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
|
208 |
13885 | 209 # if (((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2) \ |
210 && !defined __UCLIBC__) \ | |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
211 || _LIBICONV_VERSION >= 0x0105 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
212 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
213 char *converted_translit; |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
214 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
215 size_t len = strlen (locale_code); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
216 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
|
217 memcpy (locale_code_translit, locale_code, len); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
218 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
|
219 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
220 converted_translit = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
221 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
|
222 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
223 free (locale_code_translit); |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
224 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
225 if (converted_translit != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
226 { |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
227 # if !_LIBICONV_VERSION |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
228 /* 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
|
229 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
|
230 transliteration does not. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
231 mbschr is equivalent to strchr in this case. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
232 if (strchr (converted_translit, '?') != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
233 free (converted_translit); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
234 else |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
235 # endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
236 name_converted_translit = alloc_name_converted_translit = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
237 converted_translit; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
238 } |
10085
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 # endif |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
241 #endif |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
242 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
243 else |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
244 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
245 name_converted = name_utf8; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
246 name_converted_translit = name_utf8; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
247 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
248 |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
249 /* The name in locale encoding. */ |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
250 name = (name_converted != NULL ? name_converted : |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
251 name_converted_translit != NULL ? name_converted_translit : |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
252 name_ascii); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
253 |
11537
0ec84326efef
Ignore no-op translations.
Jim Meyering <meyering@redhat.com>
parents:
10954
diff
changeset
|
254 /* 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
|
255 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
|
256 translator provided a no-op translation, we ignore it. */ |
0ec84326efef
Ignore no-op translations.
Jim Meyering <meyering@redhat.com>
parents:
10954
diff
changeset
|
257 if (strcmp (translation, name_ascii) != 0) |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
258 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
259 /* 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
|
260 if (mbsstr_trimmed_wordbounded (translation, name_ascii) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
261 || (name_converted != NULL |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
262 && mbsstr_trimmed_wordbounded (translation, name_converted)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
263 || (name_converted_translit != NULL |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
264 && mbsstr_trimmed_wordbounded (translation, name_converted_translit))) |
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 if (alloc_name_converted != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
267 free (alloc_name_converted); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
268 if (alloc_name_converted_translit != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
269 free (alloc_name_converted_translit); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
270 return translation; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
271 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
272 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
273 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
274 /* Return "TRANSLATION (NAME)". */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
275 char *result = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
276 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
|
277 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
278 sprintf (result, "%s (%s)", translation, name); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
279 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
280 if (alloc_name_converted != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
281 free (alloc_name_converted); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
282 if (alloc_name_converted_translit != NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
283 free (alloc_name_converted_translit); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
284 return result; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
285 } |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
286 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
287 else |
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 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
|
290 free (alloc_name_converted); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
291 if (alloc_name_converted_translit != NULL |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
292 && alloc_name_converted_translit != name) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11537
diff
changeset
|
293 free (alloc_name_converted_translit); |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
294 return name; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
295 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
296 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
297 |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
298 #ifdef TEST1 |
10085
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
299 # include <locale.h> |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
300 int |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
301 main (int argc, char *argv[]) |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
302 { |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
303 setlocale (LC_ALL, ""); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
304 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
|
305 printf("found\n"); |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
306 return 0; |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
307 } |
6eeccac8ebca
New module 'propername', moved here from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
308 #endif |
10225
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
309 |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
310 #ifdef TEST2 |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
311 # include <locale.h> |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
312 # include <stdio.h> |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
313 int |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
314 main (int argc, char *argv[]) |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
315 { |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
316 setlocale (LC_ALL, ""); |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
317 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
|
318 return 0; |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
319 } |
263c02b12cef
Avoid question marks in proper_name_utf8 result.
Bruno Haible <bruno@clisp.org>
parents:
10085
diff
changeset
|
320 #endif |