Debian Codegraph @

lib/romaji.c

raw symbols SCIP
1 /*
2 Copyright (C) 2018-2022 Sutou Kouhei <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "grn_romaji.h"
20 #include "grn_str.h"
21
22 static inline bool
23 grn_romaji_hepburn_is_pbm(const unsigned char *utf8,
24 size_t length)
25 {
26 if (length != 3) {
27 return false;
28 }
29
30 switch (utf8[0]) {
31 case 0xe3 :
32 switch (utf8[1]) {
33 case 0x81 :
34 switch (utf8[2]) {
35 case 0xb0 : /* U+3070 HIRAGANA LETTER BA */
36 case 0xb1 : /* U+3071 HIRAGANA LETTER PA */
37 case 0xb3 : /* U+3073 HIRAGANA LETTER BI */
38 case 0xb4 : /* U+3074 HIRAGANA LETTER PI */
39 case 0xb6 : /* U+3076 HIRAGANA LETTER BU */
40 case 0xb7 : /* U+3077 HIRAGANA LETTER PU */
41 case 0xb9 : /* U+3079 HIRAGANA LETTER BE */
42 case 0xba : /* U+307A HIRAGANA LETTER PE */
43 return true;
44 default :
45 /* U+3079 HIRAGANA LETTER BO ..
46 * U+307F HIRAGANA LETTER MI */
47 return utf8[2] >= 0xbc;
48 }
49 case 0x82 :
50 /* U+3080 HIRAGANA LETTER MU ..
51 * U+3082 HIRAGANA LETTER MO */
52 return (0x80 <= utf8[2] && utf8[2] <= 0x82);
53 case 0x83 :
54 switch (utf8[2]) {
55 case 0x90 : /* U+30D0 KATAKANA LETTER BA */
56 case 0x91 : /* U+30D1 KATAKANA LETTER PA */
57 case 0x93 : /* U+30D3 KATAKANA LETTER BI */
58 case 0x94 : /* U+30D4 KATAKANA LETTER PI */
59 case 0x96 : /* U+30D6 KATAKANA LETTER BU */
60 case 0x97 : /* U+30D7 KATAKANA LETTER PU */
61 case 0x99 : /* U+30D9 KATAKANA LETTER BE */
62 case 0x9a : /* U+30DA KATAKANA LETTER PE */
63 return true;
64 default :
65 /* U+30DC KATAKANA LETTER BO ..
66 * U+30E2 KATAKANA LETTER MO */
67 return (0x9c <= utf8[2] && utf8[2] <= 0xa2);
68 }
69 default :
70 return false;
71 }
72 default :
73 return false;
74 }
75 }
76
77 static inline bool
78 grn_romaji_hepburn_is_aiueoy(const unsigned char *utf8,
79 size_t length)
80 {
81 if (length != 3) {
82 return false;
83 }
84
85 switch (utf8[0]) {
86 case 0xe3 :
87 switch (utf8[1]) {
88 case 0x81 :
89 switch (utf8[2]) {
90 case 0x82 : /* U+3042 HIRAGANA LETTER A */
91 case 0x84 : /* U+3044 HIRAGANA LETTER I */
92 case 0x86 : /* U+3046 HIRAGANA LETTER U */
93 case 0x88 : /* U+3048 HIRAGANA LETTER E */
94 case 0x8a : /* U+304A HIRAGANA LETTER O */
95 return true;
96 default :
97 return false;
98 }
99 case 0x82 :
100 switch (utf8[2]) {
101 case 0x84 : /* U+3084 HIRAGANA LETTER YA */
102 case 0x86 : /* U+3086 HIRAGANA LETTER YU */
103 case 0x88 : /* U+3088 HIRAGANA LETTER YO */
104 case 0xa2 : /* U+30A2 KATAKANA LETTER A */
105 case 0xa4 : /* U+30A4 KATAKANA LETTER I */
106 case 0xa6 : /* U+30A6 KATAKANA LETTER U */
107 case 0xa8 : /* U+30A8 KATAKANA LETTER E */
108 case 0xaa : /* U+30AA KATAKANA LETTER O */
109 return true;
110 default :
111 return false;
112 }
113 case 0x83 :
114 switch (utf8[2]) {
115 case 0xa4 : /* U+30E4 KATAKANA LETTER YA */
116 case 0xa6 : /* U+30E6 KATAKANA LETTER YU */
117 case 0xa8 : /* U+30E8 KATAKANA LETTER YO */
118 return true;
119 default :
120 return false;
121 }
122 default :
123 return false;
124 }
125 default :
126 return false;
127 }
128 }
129
130 static inline unsigned char
131 grn_romaji_hepburn_consonant(grn_ctx *ctx,
132 const unsigned char *current,
133 size_t char_length,
134 const unsigned char *end)
135 {
136 if (char_length != 3) {
137 return '\0';
138 }
139
140 switch (current[0]) {
141 case 0xe3 :
142 switch (current[1]) {
143 case 0x81 :
144 if (0x81 <= current[2] && current[2] <= 0x8a) {
145 /* U+3042 HIRAGANA LETTER SMALL A ..
146 * U+304A HIRAGANA LETTER O */
147 if ((current[2] % 2) == 1) { /* SMALL */
148 return 'x';
149 }
150 } else if (0x8b <= current[2] && current[2] <= 0x94) {
151 /* U+304B HIRAGANA LETTER KA ..
152 * U+3054 HIRAGANA LETTER GO */
153 const char *gk = "gk";
154 return (unsigned char)(gk[current[2] % 2]);
155 } else if (0x95 <= current[2] && current[2] <= 0x9e) {
156 /* U+3055 HIRAGANA LETTER SA ..
157 * U+305E HIRAGANA LETTER ZO */
158 if (current[2] == 0x97) {
159 /* U+3057 HIRAGANA LETTER SI */
160 return 's';
161 } else if (current[2] == 0x98) {
162 /* U+3058 HIRAGANA LETTER ZI */
163 return 'j';
164 } else {
165 const char *zs = "zs";
166 return (unsigned char)(zs[current[2] % 2]);
167 }
168 } else if (0x9f <= current[2] && current[2] <= 0xa9) {
169 /* U+305F HIRAGANA LETTER TA ..
170 * U+3069 HIRAGANA LETTER DO */
171 const char *tdtjxtztdtd = "tdtjxtztdtd";
172 return (unsigned char)(tdtjxtztdtd[current[2] - 0x9f]);
173 } else if (0xaa <= current[2] && current[2] <= 0xae) {
174 /* U+306A HIRAGANA LETTER NA ..
175 * U+306E HIRAGANA LETTER NO */
176 return 'n';
177 } else if (0xaf <= current[2] && current[2] <= 0xbd) {
178 /* U+306F HIRAGANA LETTER HA ..
179 * U+307D HIRAGANA LETTER PO */
180 const char *phb = "phb";
181 return (unsigned char)(phb[current[2] % 3]);
182 } else if (0xbe <= current[2] && current[2] <= 0xbf) {
183 /* U+307E HIRAGANA LETTER MA ..
184 * U+307F HIRAGANA LETTER MI */
185 return 'm';
186 }
187 break;
188 case 0x82 :
189 if (0x80 <= current[2] && current[2] <= 0x82) {
190 /* U+3080 HIRAGANA LETTER MU ..
191 * U+3082 HIRAGANA LETTER MO */
192 return 'm';
193 } else if (0x83 <= current[2] && current[2] <= 0x88) {
194 /* U+3083 HIRAGANA LETTER SMALL YA ..
195 * U+3088 HIRAGANA LETTER YO */
196 if ((current[2] % 2) == 1) { /* SMALL */
197 return 'x';
198 } else {
199 return 'y';
200 }
201 } else if (0x89 <= current[2] && current[2] <= 0x8d) {
202 /* U+3089 HIRAGANA LETTER RA ..
203 * U+308D HIRAGANA LETTER RO */
204 return 'r';
205 } else if (0x8e <= current[2] && current[2] <= 0x92) {
206 /* U+308E HIRAGANA LETTER SMALL WA ..
207 * U+3092 HIRAGANA LETTER WO */
208 if (current[2] == 0x8e) { /* SMALL */
209 return 'x';
210 } else {
211 return 'w';
212 }
213 } else if (current[2] == 0x93) {
214 /* U+3093 HIRAGANA LETTER N */
215 const unsigned char *next = current + char_length;
216 size_t next_char_length =
217 (size_t)grn_charlen_(ctx, next, end, GRN_ENC_UTF8);
218 if (grn_romaji_hepburn_is_pbm(next, next_char_length)) {
219 return 'm';
220 } else {
221 return 'n';
222 }
223 } else if (current[2] == 0x94) {
224 /* U+3094 HIRAGANA LETTER VU */
225 return 'v';
226 } else if (current[2] == 0x95) {
227 /* U+3095 HIRAGANA LETTER SMALL KA */
228 return 'x';
229 } else if (current[2] == 0x96) {
230 /* U+3096 HIRAGANA LETTER SMALL KE */
231 return 'x';
232 } else if (0xa1 <= current[2] && current[2] <= 0xaa) {
233 /* U+30A1 KATAKANA LETTER SMALL A ..
234 * U+30AA KATAKANA LETTER O */
235 if ((current[2] % 2) == 1) { /* SMALL */
236 return 'x';
237 }
238 } else if (0xab <= current[2] && current[2] <= 0xb4) {
239 /* U+30AB KATAKANA LETTER KA ..
240 * U+30B4 KATAKANA LETTER GO */
241 const char *gk = "gk";
242 return (unsigned char)(gk[current[2] % 2]);
243 } else if (0xb5 <= current[2] && current[2] <= 0xbe) {
244 /* U+30B5 KATAKANA LETTER SA ..
245 * U+30BE KATAKANA LETTER ZO */
246 if (current[2] == 0xb7) {
247 /* U+30B7 KATAKANA LETTER SI */
248 return 's';
249 } else if (current[2] == 0x98) {
250 /* U+30B8 KATAKANA LETTER ZI */
251 return 'j';
252 } else {
253 const char *zs = "zs";
254 return (unsigned char)(zs[current[2] % 2]);
255 }
256 } else if (current[2] == 0xbf) {
257 /* U+30BF KATAKANA LETTER TA */
258 return 't';
259 }
260 break;
261 case 0x83 :
262 if (0x80 <= current[2] && current[2] <= 0x89) {
263 /* U+30C0 KATAKANA LETTER DA ..
264 * U+30C9 KATAKANA LETTER DO */
265 const char *dtjxtztdtd = "dtjxtztdtd";
266 return (unsigned char)(dtjxtztdtd[current[2] - 0x80]);
267 } else if (0x8a <= current[2] && current[2] <= 0x8e) {
268 /* U+30CA KATAKANA LETTER NA ..
269 * U+30CE KATAKANA LETTER NO */
270 return 'n';
271 } else if (0x8f <= current[2] && current[2] <= 0x9d) {
272 /* U+30CF KATAKANA LETTER HA ..
273 * U+30DD KATAKANA LETTER PO */
274 const char *bph = "bph";
275 return (unsigned char)(bph[current[2] % 3]);
276 } else if (0x9e <= current[2] && current[2] <= 0xa2) {
277 /* U+30DE KATAKANA LETTER MA ..
278 * U+30E2 KATAKANA LETTER MO */
279 return 'm';
280 } else if (0xa3 <= current[2] && current[2] <= 0xa8) {
281 /* U+30E3 KATAKANA LETTER SMALL YA ..
282 * U+30E8 KATAKANA LETTER YO */
283 if ((current[2] % 2) == 1) { /* SMALL */
284 return 'x';
285 } else {
286 return 'y';
287 }
288 } else if (0xa9 <= current[2] && current[2] <= 0xad) {
289 /* U+30E9 KATAKANA LETTER RA ..
290 * U+30ED KATAKANA LETTER RO */
291 return 'r';
292 } else if (0xae <= current[2] && current[2] <= 0xb2) {
293 /* U+30EE KATAKANA LETTER SMALL WA ..
294 * U+30F2 KATAKANA LETTER WO */
295 if (current[2] == 0xae) { /* SMALL */
296 return 'x';
297 } else {
298 return 'w';
299 }
300 } else if (current[2] == 0xb3) {
301 /* U+30F3 KATAKANA LETTER N */
302 const unsigned char *next = current + char_length;
303 size_t next_char_length =
304 (size_t)grn_charlen_(ctx, next, end, GRN_ENC_UTF8);
305 if (grn_romaji_hepburn_is_pbm(next, next_char_length)) {
306 return 'm';
307 } else {
308 return 'n';
309 }
310 } else if (current[2] == 0xb4) {
311 /* U+30F4 KATAKANA LETTER VU */
312 return 'v';
313 } else if (current[2] == 0xb5) {
314 /* U+30F5 KATAKANA LETTER SMALL KA */
315 return 'x';
316 } else if (current[2] == 0xb6) {
317 /* U+30F6 KATAKANA LETTER SMALL KE */
318 return 'x';
319 } else if (0xb7 <= current[2] && current[2] <= 0xba) {
320 /* U+30F7 KATAKANA LETTER VA ..
321 * U+30FA KATAKANA LETTER VO */
322 return 'v';
323 }
324 break;
325 default :
326 break;
327 }
328 }
329
330 return '\0';
331 }
332
333 const unsigned char *
334 grn_romaji_hepburn_convert(grn_ctx *ctx,
335 const unsigned char *current,
336 const unsigned char *end,
337 size_t *n_used_bytes,
338 size_t *n_used_characters,
339 unsigned char *buffer,
340 size_t *n_bytes,
341 size_t *n_characters)
342 {
343 size_t char_length;
344 const unsigned char *next = NULL;
345 size_t next_char_length = 0;
346 bool next_small_y = false;
347 unsigned char next_small_yayuyo = '\0';
348 const char aiueo[] = "aiueo";
349 const char auo[] = "auo";
350 const char aaieo[] = "aaieo";
351
352 char_length = (size_t)grn_charlen_(ctx, current, end, GRN_ENC_UTF8);
353 *n_used_bytes = char_length;
354 *n_used_characters = 1;
355
356 if (char_length == 3) {
357 next = current + char_length;
358 next_char_length = (size_t)grn_charlen_(ctx, next, end, GRN_ENC_UTF8);
359 if (next_char_length == 3) {
360 switch (next[0]) {
361 case 0xe3 :
362 switch (next[1]) {
363 case 0x82 :
364 switch (next[2]) {
365 case 0x83 : /* U+3083 HIRAGANA LETTER SMALL YA */
366 case 0x85 : /* U+3085 HIRAGANA LETTER SMALL YU */
367 case 0x87 : /* U+3087 HIRAGANA LETTER SMALL YO */
368 next_small_y = true;
369 next_small_yayuyo = (unsigned char)(aiueo[(next[2] - 1) % 5]);
370 break;
371 default :
372 break;
373 }
374 break;
375 case 0x83 :
376 switch (next[2]) {
377 case 0xa3 : /* U+30E3 KATAKANA LETTER SMALL YA */
378 case 0xa5 : /* U+30E5 KATAKANA LETTER SMALL YU */
379 case 0xa7 : /* U+30E7 KATAKANA LETTER SMALL YO */
380 next_small_y = true;
381 next_small_yayuyo = (unsigned char)(aiueo[(next[2] - 3) % 5]);
382 break;
383 default :
384 break;
385 }
386 break;
387 default :
388 break;
389 }
390 break;
391 default :
392 break;
393 }
394 }
395 }
396
397 switch (current[0]) {
398 case 0xe3 :
399 switch (current[1]) {
400 case 0x81 :
401 if (0x81 <= current[2] && current[2] <= 0x8a) {
402 /* U+3042 HIRAGANA LETTER SMALL A ..
403 * U+304A HIRAGANA LETTER O */
404 if ((current[2] % 2) == 1) { /* SMALL */
405 buffer[(*n_bytes)++] = 'x';
406 }
407 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0x81) / 2]);
408 } else if (0x8b <= current[2] && current[2] <= 0x94) {
409 /* U+304B HIRAGANA LETTER KA ..
410 * U+3054 HIRAGANA LETTER GO */
411 const char *gk = "gk";
412 buffer[(*n_bytes)++] = (unsigned char)(gk[current[2] % 2]);
413 if (next_small_y &&
414 (current[2] == 0x8d || /* U+304D HIRAGANA LETTER KI */
415 current[2] == 0x8e)) { /* U+304E HIRAGANA LETTER GI */
416 buffer[(*n_bytes)++] = 'y';
417 buffer[(*n_bytes)++] = next_small_yayuyo;
418 (*n_used_bytes) += next_char_length;
419 (*n_used_characters)++;
420 } else {
421 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0x8b) / 2]);
422 }
423 } else if (0x95 <= current[2] && current[2] <= 0x9e) {
424 /* U+3055 HIRAGANA LETTER SA ..
425 * U+305E HIRAGANA LETTER ZO */
426 if (next_small_y && current[2] == 0x97) {
427 /* U+3057 HIRAGANA LETTER SI */
428 buffer[(*n_bytes)++] = 's';
429 buffer[(*n_bytes)++] = 'h';
430 buffer[(*n_bytes)++] = next_small_yayuyo;
431 (*n_used_bytes) += next_char_length;
432 (*n_used_characters)++;
433 } else if (next_small_y && current[2] == 0x98) {
434 /* U+3058 HIRAGANA LETTER ZI */
435 buffer[(*n_bytes)++] = 'j';
436 buffer[(*n_bytes)++] = next_small_yayuyo;
437 (*n_used_bytes) += next_char_length;
438 (*n_used_characters)++;
439 } else {
440 if (current[2] == 0x97) {
441 /* U+3057 HIRAGANA LETTER SI */
442 buffer[(*n_bytes)++] = 's';
443 buffer[(*n_bytes)++] = 'h';
444 } else if (current[2] == 0x98) {
445 /* U+3058 HIRAGANA LETTER ZI */
446 buffer[(*n_bytes)++] = 'j';
447 } else {
448 const char *zs = "zs";
449 buffer[(*n_bytes)++] = (unsigned char)(zs[current[2] % 2]);
450 }
451 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0x95) / 2]);
452 }
453 } else if (0x9f <= current[2] && current[2] <= 0xa9) {
454 /* U+305F HIRAGANA LETTER TA ..
455 * U+3069 HIRAGANA LETTER DO */
456 if (next_small_y && current[2] == 0xa1) {
457 /* U+3061 HIRAGANA LETTER TI */
458 buffer[(*n_bytes)++] = 'c';
459 buffer[(*n_bytes)++] = 'h';
460 buffer[(*n_bytes)++] = next_small_yayuyo;
461 (*n_used_bytes) += next_char_length;
462 (*n_used_characters)++;
463 } else if (next_small_y && current[2] == 0xa2) {
464 /* U+3062 HIRAGANA LETTER DI */
465 buffer[(*n_bytes)++] = 'j';
466 buffer[(*n_bytes)++] = next_small_yayuyo;
467 (*n_used_bytes) += next_char_length;
468 (*n_used_characters)++;
469 } else if (current[2] == 0xa3) {
470 /* U+3063 HIRAGANA LETTER SMALL TU */
471 const unsigned char next_consonant =
472 grn_romaji_hepburn_consonant(ctx, next, next_char_length, end);
473 if (next_consonant == '\0') {
474 buffer[(*n_bytes)++] = 'x';
475 buffer[(*n_bytes)++] = 't';
476 buffer[(*n_bytes)++] = 's';
477 } else {
478 buffer[(*n_bytes)++] = next_consonant;
479 }
480 } else {
481 const char *aaiiuuueeoo = "aaiiuuueeoo";
482 if (current[2] == 0xa1) {
483 /* U+3061 HIRAGANA LETTER TI */
484 buffer[(*n_bytes)++] = 'c';
485 buffer[(*n_bytes)++] = 'h';
486 } else if (current[2] == 0xa2) {
487 /* U+3062 HIRAGANA LETTER DI */
488 buffer[(*n_bytes)++] = 'j';
489 } else if (current[2] == 0xa4) {
490 /* U+3064 HIRAGANA LETTER TU */
491 buffer[(*n_bytes)++] = 't';
492 buffer[(*n_bytes)++] = 's';
493 } else {
494 const char *td____ztdtd = "td____ztdtd";
495 buffer[(*n_bytes)++] =
496 (unsigned char)(td____ztdtd[current[2] - 0x9f]);
497 }
498 buffer[(*n_bytes)++] =
499 (unsigned char)(aaiiuuueeoo[current[2] - 0x9f]);
500 }
501 } else if (0xaa <= current[2] && current[2] <= 0xae) {
502 /* U+306A HIRAGANA LETTER NA ..
503 * U+306E HIRAGANA LETTER NO */
504 buffer[(*n_bytes)++] = 'n';
505 if (next_small_y && current[2] == 0xab) {
506 /* U+306B HIRAGANA LETTER NI */
507 buffer[(*n_bytes)++] = 'y';
508 buffer[(*n_bytes)++] = next_small_yayuyo;
509 (*n_used_bytes) += next_char_length;
510 (*n_used_characters)++;
511 } else {
512 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0xaa)]);
513 }
514 } else if (0xaf <= current[2] && current[2] <= 0xbd) {
515 /* U+306F HIRAGANA LETTER HA ..
516 * U+307D HIRAGANA LETTER PO */
517 const char *phb = "phb";
518 buffer[(*n_bytes)++] = (unsigned char)(phb[current[2] % 3]);
519 if (next_small_y &&
520 (0xb2 <= current[2] && /* U+3072 HIRAGANA LETTER HI .. */
521 current[2] <= 0xb4)) { /* U+3074 HIRAGANA LETTER PI */
522 buffer[(*n_bytes)++] = 'y';
523 buffer[(*n_bytes)++] = next_small_yayuyo;
524 (*n_used_bytes) += next_char_length;
525 (*n_used_characters)++;
526 } else {
527 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0xaf) / 3]);
528 }
529 } else if (0xbe <= current[2] && current[2] <= 0xbf) {
530 /* U+307E HIRAGANA LETTER MA ..
531 * U+307F HIRAGANA LETTER MI */
532 buffer[(*n_bytes)++] = 'm';
533 if (next_small_y && current[2] == 0xbf) {
534 /* U+307F HIRAGANA LETTER MI */
535 buffer[(*n_bytes)++] = 'y';
536 buffer[(*n_bytes)++] = next_small_yayuyo;
537 (*n_used_bytes) += next_char_length;
538 (*n_used_characters)++;
539 } else {
540 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0xbe)]);
541 }
542 }
543 break;
544 case 0x82 :
545 if (0x80 <= current[2] && current[2] <= 0x82) {
546 /* U+3080 HIRAGANA LETTER MU ..
547 * U+3082 HIRAGANA LETTER MO */
548 buffer[(*n_bytes)++] = 'm';
549 if (next_small_y && current[2] == 0xbf) {
550 /* U+307F HIRAGANA LETTER MI */
551 buffer[(*n_bytes)++] = 'y';
552 buffer[(*n_bytes)++] = next_small_yayuyo;
553 (*n_used_bytes) += next_char_length;
554 (*n_used_characters)++;
555 } else {
556 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0x80) + 2]);
557 }
558 } else if (0x83 <= current[2] && current[2] <= 0x88) {
559 /* U+3083 HIRAGANA LETTER SMALL YA ..
560 * U+3088 HIRAGANA LETTER YO */
561 if ((current[2] % 2) == 1) { /* SMALL */
562 buffer[(*n_bytes)++] = 'x';
563 }
564 buffer[(*n_bytes)++] = 'y';
565 buffer[(*n_bytes)++] = (unsigned char)(auo[(current[2] - 0x83) / 2]);
566 } else if (0x89 <= current[2] && current[2] <= 0x8d) {
567 /* U+3089 HIRAGANA LETTER RA ..
568 * U+308D HIRAGANA LETTER RO */
569 buffer[(*n_bytes)++] = 'r';
570 if (next_small_y && current[2] == 0x8a) {
571 /* U+308A HIRAGANA LETTER RI */
572 buffer[(*n_bytes)++] = 'y';
573 buffer[(*n_bytes)++] = next_small_yayuyo;
574 (*n_used_bytes) += next_char_length;
575 (*n_used_characters)++;
576 } else {
577 buffer[(*n_bytes)++] = (unsigned char)(aiueo[current[2] - 0x89]);
578 }
579 } else if (0x8e <= current[2] && current[2] <= 0x92) {
580 /* U+308E HIRAGANA LETTER SMALL WA ..
581 * U+3092 HIRAGANA LETTER WO */
582 if (current[2] == 0x8e) { /* SMALL */
583 buffer[(*n_bytes)++] = 'x';
584 }
585 buffer[(*n_bytes)++] = 'w';
586 buffer[(*n_bytes)++] = (unsigned char)(aaieo[current[2] - 0x8e]);
587 } else if (current[2] == 0x93) {
588 /* U+3093 HIRAGANA LETTER N */
589 if (grn_romaji_hepburn_is_pbm(next, next_char_length)) {
590 buffer[(*n_bytes)++] = 'm';
591 } else {
592 buffer[(*n_bytes)++] = 'n';
593 }
594 if (grn_romaji_hepburn_is_aiueoy(next, next_char_length)) {
595 buffer[(*n_bytes)++] = '-';
596 }
597 } else if (current[2] == 0x94) {
598 /* U+3094 HIRAGANA LETTER VU */
599 buffer[(*n_bytes)++] = 'v';
600 buffer[(*n_bytes)++] = 'u';
601 } else if (current[2] == 0x95) {
602 /* U+3095 HIRAGANA LETTER SMALL KA */
603 buffer[(*n_bytes)++] = 'x';
604 buffer[(*n_bytes)++] = 'k';
605 buffer[(*n_bytes)++] = 'a';
606 } else if (current[2] == 0x96) {
607 /* U+3096 HIRAGANA LETTER SMALL KE */
608 buffer[(*n_bytes)++] = 'x';
609 buffer[(*n_bytes)++] = 'k';
610 buffer[(*n_bytes)++] = 'e';
611 } else if (0xa1 <= current[2] && current[2] <= 0xaa) {
612 /* U+30A1 KATAKANA LETTER SMALL A ..
613 * U+30AA KATAKANA LETTER O */
614 if ((current[2] % 2) == 1) { /* SMALL */
615 buffer[(*n_bytes)++] = 'x';
616 }
617 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0xa1) / 2]);
618 } else if (0xab <= current[2] && current[2] <= 0xb4) {
619 /* U+30AB KATAKANA LETTER KA ..
620 * U+30B4 KATAKANA LETTER GO */
621 const char *gk = "gk";
622 buffer[(*n_bytes)++] = (unsigned char)(gk[current[2] % 2]);
623 if (next_small_y &&
624 (current[2] == 0xad || /* U+30AD KATAKANA LETTER KI */
625 current[2] == 0xae)) { /* U+U+30AE KATAKANA LETTER GI */
626 buffer[(*n_bytes)++] = 'y';
627 buffer[(*n_bytes)++] = next_small_yayuyo;
628 (*n_used_bytes) += next_char_length;
629 (*n_used_characters)++;
630 } else {
631 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0xab) / 2]);
632 }
633 } else if (0xb5 <= current[2] && current[2] <= 0xbe) {
634 /* U+30B5 KATAKANA LETTER SA ..
635 * U+30BE KATAKANA LETTER ZO */
636 if (next_small_y && current[2] == 0xb7) {
637 /* U+30B7 KATAKANA LETTER SI */
638 buffer[(*n_bytes)++] = 's';
639 buffer[(*n_bytes)++] = 'h';
640 buffer[(*n_bytes)++] = next_small_yayuyo;
641 (*n_used_bytes) += next_char_length;
642 (*n_used_characters)++;
643 } else if (next_small_y && current[2] == 0xb8) {
644 /* U+30B8 KATAKANA LETTER ZI */
645 buffer[(*n_bytes)++] = 'j';
646 buffer[(*n_bytes)++] = next_small_yayuyo;
647 (*n_used_bytes) += next_char_length;
648 (*n_used_characters)++;
649 } else {
650 if (current[2] == 0xb7) {
651 /* U+30B7 KATAKANA LETTER SI */
652 buffer[(*n_bytes)++] = 's';
653 buffer[(*n_bytes)++] = 'h';
654 } else if (current[2] == 0xb8) {
655 /* U+30B8 KATAKANA LETTER ZI */
656 buffer[(*n_bytes)++] = 'j';
657 } else {
658 const char *zs = "zs";
659 buffer[(*n_bytes)++] = (unsigned char)(zs[current[2] % 2]);
660 }
661 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0xb5) / 2]);
662 }
663 } else if (current[2] == 0xbf) {
664 /* U+30BF KATAKANA LETTER TA */
665 buffer[(*n_bytes)++] = 't';
666 buffer[(*n_bytes)++] = 'a';
667 }
668 break;
669 case 0x83 :
670 if (0x80 <= current[2] && current[2] <= 0x89) {
671 /* U+30C0 KATAKANA LETTER DA ..
672 * U+30C9 KATAKANA LETTER DO */
673 if (next_small_y && current[2] == 0x81) {
674 /* U+30C1 KATAKANA LETTER TI */
675 buffer[(*n_bytes)++] = 'c';
676 buffer[(*n_bytes)++] = 'h';
677 buffer[(*n_bytes)++] = next_small_yayuyo;
678 (*n_used_bytes) += next_char_length;
679 (*n_used_characters)++;
680 } else if (next_small_y && current[2] == 0x82) {
681 /* U+30C2 KATAKANA LETTER DI */
682 buffer[(*n_bytes)++] = 'j';
683 buffer[(*n_bytes)++] = next_small_yayuyo;
684 (*n_used_bytes) += next_char_length;
685 (*n_used_characters)++;
686 } else if (current[2] == 0x83) {
687 /* U+30C3 KATAKANA LETTER SMALL TU */
688 const unsigned char next_consonant =
689 grn_romaji_hepburn_consonant(ctx, next, next_char_length, end);
690 if (next_consonant == '\0') {
691 buffer[(*n_bytes)++] = 'x';
692 buffer[(*n_bytes)++] = 't';
693 buffer[(*n_bytes)++] = 's';
694 } else {
695 buffer[(*n_bytes)++] = next_consonant;
696 }
697 } else {
698 const char *aiiuuueeoo = "aiiuuueeoo";
699 if (current[2] == 0x81) {
700 /* U+30C1 KATAKANA LETTER TI */
701 buffer[(*n_bytes)++] = 'c';
702 buffer[(*n_bytes)++] = 'h';
703 } else if (current[2] == 0x82) {
704 /* U+30C2 KATAKANA LETTER DI */
705 buffer[(*n_bytes)++] = 'j';
706 } else if (current[2] == 0x83) {
707 /* U+30C3 KATAKANA LETTER SMALL TU */
708 buffer[(*n_bytes)++] = 'x';
709 buffer[(*n_bytes)++] = 't';
710 buffer[(*n_bytes)++] = 's';
711 } else if (current[2] == 0x84) {
712 /* U+30C4 KATAKANA LETTER TU */
713 buffer[(*n_bytes)++] = 't';
714 buffer[(*n_bytes)++] = 's';
715 } else {
716 const char *d____ztdtd = "d____ztdtd";
717 buffer[(*n_bytes)++] =
718 (unsigned char)(d____ztdtd[current[2] - 0x80]);
719 }
720 buffer[(*n_bytes)++] =
721 (unsigned char)(aiiuuueeoo[current[2] - 0x80]);
722 }
723 } else if (0x8a <= current[2] && current[2] <= 0x8e) {
724 /* U+30CA KATAKANA LETTER NA ..
725 * U+30CE KATAKANA LETTER NO */
726 buffer[(*n_bytes)++] = 'n';
727 if (next_small_y && current[2] == 0x8b) {
728 /* U+30CB KATAKANA LETTER NI */
729 buffer[(*n_bytes)++] = 'y';
730 buffer[(*n_bytes)++] = next_small_yayuyo;
731 (*n_used_bytes) += next_char_length;
732 (*n_used_characters)++;
733 } else {
734 buffer[(*n_bytes)++] =
735 (unsigned char)(aiueo[current[2] - 0x8a]);
736 }
737 } else if (0x8f <= current[2] && current[2] <= 0x9d) {
738 /* U+30CF KATAKANA LETTER HA ..
739 * U+30DD KATAKANA LETTER PO */
740 const char *bph = "bph";
741 buffer[(*n_bytes)++] = (unsigned char)(bph[current[2] % 3]);
742 if (next_small_y &&
743 (0x92 <= current[2] && /* U+30D2 KATAKANA LETTER HI .. */
744 current[2] <= 0x94)) { /* U+30D4 KATAKANA LETTER PI */
745 buffer[(*n_bytes)++] = 'y';
746 buffer[(*n_bytes)++] = next_small_yayuyo;
747 (*n_used_bytes) += next_char_length;
748 (*n_used_characters)++;
749 } else {
750 buffer[(*n_bytes)++] = (unsigned char)(aiueo[(current[2] - 0x8f) / 3]);
751 }
752 } else if (0x9e <= current[2] && current[2] <= 0xa2) {
753 /* U+30DE KATAKANA LETTER MA ..
754 * U+30E2 KATAKANA LETTER MO */
755 buffer[(*n_bytes)++] = 'm';
756 if (next_small_y && current[2] == 0x9f) {
757 /* U+30DF KATAKANA LETTER MI */
758 buffer[(*n_bytes)++] = 'y';
759 buffer[(*n_bytes)++] = next_small_yayuyo;
760 (*n_used_bytes) += next_char_length;
761 (*n_used_characters)++;
762 } else {
763 buffer[(*n_bytes)++] = (unsigned char)(aiueo[current[2] - 0x9e]);
764 }
765 } else if (0xa3 <= current[2] && current[2] <= 0xa8) {
766 /* U+30E3 KATAKANA LETTER SMALL YA ..
767 * U+30E8 KATAKANA LETTER YO */
768 if ((current[2] % 2) == 1) { /* SMALL */
769 buffer[(*n_bytes)++] = 'x';
770 }
771 buffer[(*n_bytes)++] = 'y';
772 buffer[(*n_bytes)++] = (unsigned char)(auo[(current[2] - 0xa3) / 2]);
773 } else if (0xa9 <= current[2] && current[2] <= 0xad) {
774 /* U+30E9 KATAKANA LETTER RA ..
775 * U+30ED KATAKANA LETTER RO */
776 buffer[(*n_bytes)++] = 'r';
777 if (next_small_y && current[2] == 0xaa) {
778 /* U+30EA KATAKANA LETTER RI */
779 buffer[(*n_bytes)++] = 'y';
780 buffer[(*n_bytes)++] = next_small_yayuyo;
781 (*n_used_bytes) += next_char_length;
782 (*n_used_characters)++;
783 } else {
784 buffer[(*n_bytes)++] = (unsigned char)(aiueo[current[2] - 0xa9]);
785 }
786 } else if (0xae <= current[2] && current[2] <= 0xb2) {
787 /* U+30EE KATAKANA LETTER SMALL WA ..
788 * U+30F2 KATAKANA LETTER WO */
789 if (current[2] == 0xae) { /* SMALL */
790 buffer[(*n_bytes)++] = 'x';
791 }
792 buffer[(*n_bytes)++] = 'w';
793 buffer[(*n_bytes)++] = (unsigned char)(aaieo[current[2] - 0xae]);
794 } else if (current[2] == 0xb3) {
795 /* U+30F3 KATAKANA LETTER N */
796 if (grn_romaji_hepburn_is_pbm(next, next_char_length)) {
797 buffer[(*n_bytes)++] = 'm';
798 } else {
799 buffer[(*n_bytes)++] = 'n';
800 }
801 if (grn_romaji_hepburn_is_aiueoy(next, next_char_length)) {
802 buffer[(*n_bytes)++] = '-';
803 }
804 } else if (current[2] == 0xb4) {
805 /* U+30F4 KATAKANA LETTER VU */
806 buffer[(*n_bytes)++] = 'v';
807 buffer[(*n_bytes)++] = 'u';
808 } else if (current[2] == 0xb5) {
809 /* U+30F5 KATAKANA LETTER SMALL KA */
810 buffer[(*n_bytes)++] = 'x';
811 buffer[(*n_bytes)++] = 'k';
812 buffer[(*n_bytes)++] = 'a';
813 } else if (current[2] == 0xb6) {
814 /* U+30F6 KATAKANA LETTER SMALL KE */
815 buffer[(*n_bytes)++] = 'x';
816 buffer[(*n_bytes)++] = 'k';
817 buffer[(*n_bytes)++] = 'e';
818 } else if (0xb7 <= current[2] && current[2] <= 0xba) {
819 /* U+30F7 KATAKANA LETTER VA ..
820 * U+30FA KATAKANA LETTER VO */
821 static char aieo[] = "aieo";
822 buffer[(*n_bytes)++] = 'v';
823 buffer[(*n_bytes)++] = (unsigned char)(aieo[current[2] - 0xb7]);
824 }
825 break;
826 default :
827 break;
828 }
829 break;
830 default :
831 break;
832 }
833
834 if (*n_bytes > 0) {
835 *n_characters = *n_bytes;
836 return buffer;
837 } else {
838 *n_bytes = *n_used_bytes;
839 *n_characters = *n_used_characters;
840 return current;
841 }
842 }