Coverage Report

Created: 2026-07-25 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/glib/glib/guniprop.c
Line
Count
Source
1
/* guniprop.c - Unicode character properties.
2
 *
3
 * Copyright (C) 1999 Tom Tromey
4
 * Copyright (C) 2000 Red Hat, Inc.
5
 *
6
 * SPDX-License-Identifier: LGPL-2.1-or-later
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "config.h"
23
24
#include <stdlib.h>
25
#include <stddef.h>
26
#include <string.h>
27
#include <locale.h>
28
29
#include "gmem.h"
30
#include "gstring.h"
31
#include "gtestutils.h"
32
#include "gtypes.h"
33
#include "gunicode.h"
34
#include "gunichartables.h"
35
#include "gmirroringtable.h"
36
#include "gscripttable.h"
37
#include "gunicodeprivate.h"
38
#ifdef G_OS_WIN32
39
#include "gwin32.h"
40
#endif
41
42
0
#define G_UNICHAR_FULLWIDTH_A 0xff21
43
0
#define G_UNICHAR_FULLWIDTH_I 0xff29
44
0
#define G_UNICHAR_FULLWIDTH_J 0xff2a
45
0
#define G_UNICHAR_FULLWIDTH_F 0xff26
46
0
#define G_UNICHAR_FULLWIDTH_a 0xff41
47
0
#define G_UNICHAR_FULLWIDTH_f 0xff46
48
49
0
#define ATTR_TABLE(Page) (((Page) <= G_UNICODE_LAST_PAGE_PART1) \
50
0
                          ? attr_table_part1[Page] \
51
0
                          : attr_table_part2[(Page) - 0xe00])
52
53
#define ATTTABLE(Page, Char) \
54
0
  ((ATTR_TABLE(Page) == G_UNICODE_MAX_TABLE_INDEX) ? 0 : (attr_data[ATTR_TABLE(Page)][Char]))
55
56
#define TTYPE_PART1(Page, Char) \
57
0
  ((type_table_part1[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
58
0
   ? (type_table_part1[Page] - G_UNICODE_MAX_TABLE_INDEX) \
59
0
   : (type_data[type_table_part1[Page]][Char]))
60
61
#define TTYPE_PART2(Page, Char) \
62
0
  ((type_table_part2[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
63
0
   ? (type_table_part2[Page] - G_UNICODE_MAX_TABLE_INDEX) \
64
0
   : (type_data[type_table_part2[Page]][Char]))
65
66
#define TYPE(Char) \
67
0
  (((Char) <= G_UNICODE_LAST_CHAR_PART1) \
68
0
   ? TTYPE_PART1 ((Char) >> 8, (Char) & 0xff) \
69
0
   : (((Char) >= 0xe0000 && (Char) <= G_UNICODE_LAST_CHAR) \
70
0
      ? TTYPE_PART2 (((Char) - 0xe0000) >> 8, (Char) & 0xff) \
71
0
      : G_UNICODE_UNASSIGNED))
72
73
74
0
#define IS(Type, Class) (((guint)1 << (Type)) & (Class))
75
#define OR(Type, Rest)  (((guint)1 << (Type)) | (Rest))
76
77
78
79
0
#define ISALPHA(Type) IS ((Type),       \
80
0
          OR (G_UNICODE_LOWERCASE_LETTER, \
81
0
          OR (G_UNICODE_UPPERCASE_LETTER, \
82
0
          OR (G_UNICODE_TITLECASE_LETTER, \
83
0
          OR (G_UNICODE_MODIFIER_LETTER,  \
84
0
          OR (G_UNICODE_OTHER_LETTER,   0))))))
85
86
0
#define ISALDIGIT(Type) IS ((Type),       \
87
0
          OR (G_UNICODE_DECIMAL_NUMBER, \
88
0
          OR (G_UNICODE_LETTER_NUMBER,  \
89
0
          OR (G_UNICODE_OTHER_NUMBER,   \
90
0
          OR (G_UNICODE_LOWERCASE_LETTER, \
91
0
          OR (G_UNICODE_UPPERCASE_LETTER, \
92
0
          OR (G_UNICODE_TITLECASE_LETTER, \
93
0
          OR (G_UNICODE_MODIFIER_LETTER,  \
94
0
          OR (G_UNICODE_OTHER_LETTER,   0)))))))))
95
96
0
#define ISMARK(Type)  IS ((Type),       \
97
0
          OR (G_UNICODE_NON_SPACING_MARK, \
98
0
          OR (G_UNICODE_SPACING_MARK, \
99
0
          OR (G_UNICODE_ENCLOSING_MARK, 0))))
100
101
#define ISZEROWIDTHTYPE(Type) IS ((Type),     \
102
          OR (G_UNICODE_NON_SPACING_MARK, \
103
          OR (G_UNICODE_ENCLOSING_MARK, \
104
          OR (G_UNICODE_FORMAT,   0))))
105
106
/**
107
 * g_unichar_isalnum:
108
 * @c: a Unicode character
109
 * 
110
 * Determines whether a character is alphanumeric.
111
 * Given some UTF-8 text, obtain a character value
112
 * with g_utf8_get_char().
113
 * 
114
 * Returns: %TRUE if @c is an alphanumeric character
115
 **/
116
gboolean
117
g_unichar_isalnum (gunichar c)
118
0
{
119
0
  return ISALDIGIT (TYPE (c)) ? TRUE : FALSE;
120
0
}
121
122
/**
123
 * g_unichar_isalpha:
124
 * @c: a Unicode character
125
 * 
126
 * Determines whether a character is alphabetic (i.e. a letter).
127
 * Given some UTF-8 text, obtain a character value with
128
 * g_utf8_get_char().
129
 * 
130
 * Returns: %TRUE if @c is an alphabetic character
131
 **/
132
gboolean
133
g_unichar_isalpha (gunichar c)
134
0
{
135
0
  return ISALPHA (TYPE (c)) ? TRUE : FALSE;
136
0
}
137
138
139
/**
140
 * g_unichar_iscntrl:
141
 * @c: a Unicode character
142
 * 
143
 * Determines whether a character is a control character.
144
 * Given some UTF-8 text, obtain a character value with
145
 * g_utf8_get_char().
146
 * 
147
 * Returns: %TRUE if @c is a control character
148
 **/
149
gboolean
150
g_unichar_iscntrl (gunichar c)
151
0
{
152
0
  return TYPE (c) == G_UNICODE_CONTROL;
153
0
}
154
155
/**
156
 * g_unichar_isdigit:
157
 * @c: a Unicode character
158
 * 
159
 * Determines whether a character is numeric (i.e. a digit).  This
160
 * covers ASCII 0-9 and also digits in other languages/scripts.  Given
161
 * some UTF-8 text, obtain a character value with g_utf8_get_char().
162
 * 
163
 * Returns: %TRUE if @c is a digit
164
 **/
165
gboolean
166
g_unichar_isdigit (gunichar c)
167
0
{
168
0
  return TYPE (c) == G_UNICODE_DECIMAL_NUMBER;
169
0
}
170
171
172
/**
173
 * g_unichar_isgraph:
174
 * @c: a Unicode character
175
 * 
176
 * Determines whether a character is printable and not a space
177
 * (returns %FALSE for control characters, format characters, and
178
 * spaces). g_unichar_isprint() is similar, but returns %TRUE for
179
 * spaces. Given some UTF-8 text, obtain a character value with
180
 * g_utf8_get_char().
181
 * 
182
 * Returns: %TRUE if @c is printable unless it's a space
183
 **/
184
gboolean
185
g_unichar_isgraph (gunichar c)
186
0
{
187
0
  return !IS (TYPE(c),
188
0
        OR (G_UNICODE_CONTROL,
189
0
        OR (G_UNICODE_FORMAT,
190
0
        OR (G_UNICODE_UNASSIGNED,
191
0
        OR (G_UNICODE_SURROGATE,
192
0
        OR (G_UNICODE_SPACE_SEPARATOR,
193
0
       0))))));
194
0
}
195
196
/**
197
 * g_unichar_islower:
198
 * @c: a Unicode character
199
 * 
200
 * Determines whether a character is a lowercase letter.
201
 * Given some UTF-8 text, obtain a character value with
202
 * g_utf8_get_char().
203
 * 
204
 * Returns: %TRUE if @c is a lowercase letter
205
 **/
206
gboolean
207
g_unichar_islower (gunichar c)
208
0
{
209
0
  return TYPE (c) == G_UNICODE_LOWERCASE_LETTER;
210
0
}
211
212
213
/**
214
 * g_unichar_isprint:
215
 * @c: a Unicode character
216
 * 
217
 * Determines whether a character is printable.
218
 * Unlike g_unichar_isgraph(), returns %TRUE for spaces.
219
 * Given some UTF-8 text, obtain a character value with
220
 * g_utf8_get_char().
221
 * 
222
 * Returns: %TRUE if @c is printable
223
 **/
224
gboolean
225
g_unichar_isprint (gunichar c)
226
0
{
227
0
  return !IS (TYPE(c),
228
0
        OR (G_UNICODE_CONTROL,
229
0
        OR (G_UNICODE_FORMAT,
230
0
        OR (G_UNICODE_UNASSIGNED,
231
0
        OR (G_UNICODE_SURROGATE,
232
0
       0)))));
233
0
}
234
235
/**
236
 * g_unichar_ispunct:
237
 * @c: a Unicode character
238
 * 
239
 * Determines whether a character is punctuation or a symbol.
240
 * Given some UTF-8 text, obtain a character value with
241
 * g_utf8_get_char().
242
 * 
243
 * Returns: %TRUE if @c is a punctuation or symbol character
244
 **/
245
gboolean
246
g_unichar_ispunct (gunichar c)
247
0
{
248
0
  return IS (TYPE(c),
249
0
       OR (G_UNICODE_CONNECT_PUNCTUATION,
250
0
       OR (G_UNICODE_DASH_PUNCTUATION,
251
0
       OR (G_UNICODE_CLOSE_PUNCTUATION,
252
0
       OR (G_UNICODE_FINAL_PUNCTUATION,
253
0
       OR (G_UNICODE_INITIAL_PUNCTUATION,
254
0
       OR (G_UNICODE_OTHER_PUNCTUATION,
255
0
       OR (G_UNICODE_OPEN_PUNCTUATION,
256
0
       OR (G_UNICODE_CURRENCY_SYMBOL,
257
0
       OR (G_UNICODE_MODIFIER_SYMBOL,
258
0
       OR (G_UNICODE_MATH_SYMBOL,
259
0
       OR (G_UNICODE_OTHER_SYMBOL,
260
0
      0)))))))))))) ? TRUE : FALSE;
261
0
}
262
263
/**
264
 * g_unichar_isspace:
265
 * @c: a Unicode character
266
 * 
267
 * Determines whether a character is a space, tab, or line separator
268
 * (newline, carriage return, etc.).  Given some UTF-8 text, obtain a
269
 * character value with g_utf8_get_char().
270
 *
271
 * (Note: don't use this to do word breaking; you have to use
272
 * Pango or equivalent to get word breaking right, the algorithm
273
 * is fairly complex.)
274
 *  
275
 * Returns: %TRUE if @c is a space character
276
 **/
277
gboolean
278
g_unichar_isspace (gunichar c)
279
0
{
280
0
  switch (c)
281
0
    {
282
      /* special-case these since Unicode thinks they are not spaces */
283
0
    case '\t':
284
0
    case '\n':
285
0
    case '\r':
286
0
    case '\f':
287
0
      return TRUE;
288
0
      break;
289
      
290
0
    default:
291
0
      {
292
0
  return IS (TYPE(c),
293
0
             OR (G_UNICODE_SPACE_SEPARATOR,
294
0
             OR (G_UNICODE_LINE_SEPARATOR,
295
0
                   OR (G_UNICODE_PARAGRAPH_SEPARATOR,
296
0
      0)))) ? TRUE : FALSE;
297
0
      }
298
0
      break;
299
0
    }
300
0
}
301
302
/**
303
 * g_unichar_ismark:
304
 * @c: a Unicode character
305
 *
306
 * Determines whether a character is a mark (non-spacing mark,
307
 * combining mark, or enclosing mark in Unicode speak).
308
 * Given some UTF-8 text, obtain a character value
309
 * with g_utf8_get_char().
310
 *
311
 * Note: in most cases where isalpha characters are allowed,
312
 * ismark characters should be allowed to as they are essential
313
 * for writing most European languages as well as many non-Latin
314
 * scripts.
315
 *
316
 * Returns: %TRUE if @c is a mark character
317
 *
318
 * Since: 2.14
319
 **/
320
gboolean
321
g_unichar_ismark (gunichar c)
322
0
{
323
0
  return ISMARK (TYPE (c));
324
0
}
325
326
/**
327
 * g_unichar_isupper:
328
 * @c: a Unicode character
329
 * 
330
 * Determines if a character is uppercase.
331
 * 
332
 * Returns: %TRUE if @c is an uppercase character
333
 **/
334
gboolean
335
g_unichar_isupper (gunichar c)
336
0
{
337
0
  return TYPE (c) == G_UNICODE_UPPERCASE_LETTER;
338
0
}
339
340
/**
341
 * g_unichar_istitle:
342
 * @c: a Unicode character
343
 * 
344
 * Determines if a character is titlecase. Some characters in
345
 * Unicode which are composites, such as the DZ digraph
346
 * have three case variants instead of just two. The titlecase
347
 * form is used at the beginning of a word where only the
348
 * first letter is capitalized. The titlecase form of the DZ
349
 * digraph is U+01F2 LATIN CAPITAL LETTTER D WITH SMALL LETTER Z.
350
 * 
351
 * Returns: %TRUE if the character is titlecase
352
 **/
353
gboolean
354
g_unichar_istitle (gunichar c)
355
0
{
356
0
  unsigned int i;
357
0
  for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
358
0
    if (title_table[i][0] == c)
359
0
      return TRUE;
360
0
  return FALSE;
361
0
}
362
363
/**
364
 * g_unichar_isxdigit:
365
 * @c: a Unicode character.
366
 * 
367
 * Determines if a character is a hexadecimal digit.
368
 * 
369
 * Returns: %TRUE if the character is a hexadecimal digit
370
 **/
371
gboolean
372
g_unichar_isxdigit (gunichar c)
373
0
{
374
0
  return ((c >= 'a' && c <= 'f') ||
375
0
          (c >= 'A' && c <= 'F') ||
376
0
          (c >= G_UNICHAR_FULLWIDTH_a && c <= G_UNICHAR_FULLWIDTH_f) ||
377
0
          (c >= G_UNICHAR_FULLWIDTH_A && c <= G_UNICHAR_FULLWIDTH_F) ||
378
0
          (TYPE (c) == G_UNICODE_DECIMAL_NUMBER));
379
0
}
380
381
/**
382
 * g_unichar_isdefined:
383
 * @c: a Unicode character
384
 * 
385
 * Determines if a given character is assigned in the Unicode
386
 * standard.
387
 *
388
 * Returns: %TRUE if the character has an assigned value
389
 **/
390
gboolean
391
g_unichar_isdefined (gunichar c)
392
0
{
393
0
  return !IS (TYPE(c),
394
0
        OR (G_UNICODE_UNASSIGNED,
395
0
        OR (G_UNICODE_SURROGATE,
396
0
       0)));
397
0
}
398
399
/**
400
 * g_unichar_iszerowidth:
401
 * @c: a Unicode character
402
 * 
403
 * Determines if a given character typically takes zero width when rendered.
404
 * The return value is %TRUE for all non-spacing and enclosing marks
405
 * (e.g., combining accents), format characters, zero-width
406
 * space, but not U+00AD SOFT HYPHEN.
407
 *
408
 * A typical use of this function is with one of g_unichar_iswide() or
409
 * g_unichar_iswide_cjk() to determine the number of cells a string occupies
410
 * when displayed on a grid display (terminals).  However, note that not all
411
 * terminals support zero-width rendering of zero-width marks.
412
 *
413
 * Returns: %TRUE if the character has zero width
414
 *
415
 * Since: 2.14
416
 **/
417
gboolean
418
g_unichar_iszerowidth (gunichar c)
419
0
{
420
0
  if (G_UNLIKELY (c == 0x00AD))
421
0
    return FALSE;
422
423
0
  if (G_UNLIKELY (ISZEROWIDTHTYPE (TYPE (c))))
424
0
    return TRUE;
425
426
  /* A few additional codepoints are zero-width:
427
   *  - Part of the Hangul Jamo block covering medial/vowels/jungseong and
428
   *    final/trailing_consonants/jongseong Jamo
429
   *  - Jungseong and jongseong for Old Korean
430
   *  - Zero-width space (U+200B)
431
   */
432
0
  if (G_UNLIKELY ((c >= 0x1160 && c < 0x1200) ||
433
0
                  (c >= 0xD7B0 && c < 0xD800) ||
434
0
                  c == 0x200B))
435
0
    return TRUE;
436
437
0
  return FALSE;
438
0
}
439
440
static int
441
interval_compare (const void *key, const void *elt)
442
0
{
443
0
  gunichar c = GPOINTER_TO_UINT (key);
444
0
  struct Interval *interval = (struct Interval *)elt;
445
446
0
  if (c < interval->start)
447
0
    return -1;
448
0
  if (c > interval->end)
449
0
    return +1;
450
451
0
  return 0;
452
0
}
453
454
0
#define G_WIDTH_TABLE_MIDPOINT (G_N_ELEMENTS (g_unicode_width_table_wide) / 2)
455
456
static inline gboolean
457
g_unichar_iswide_bsearch (gunichar ch)
458
0
{
459
0
  int lower = 0;
460
0
  int upper = G_N_ELEMENTS (g_unicode_width_table_wide) - 1;
461
0
  static int saved_mid = G_WIDTH_TABLE_MIDPOINT;
462
0
  int mid = saved_mid;
463
464
0
  do
465
0
    {
466
0
      if (ch < g_unicode_width_table_wide[mid].start)
467
0
  upper = mid - 1;
468
0
      else if (ch > g_unicode_width_table_wide[mid].end)
469
0
  lower = mid + 1;
470
0
      else
471
0
  return TRUE;
472
473
0
      mid = (lower + upper) / 2;
474
0
    }
475
0
  while (lower <= upper);
476
477
0
  return FALSE;
478
0
}
479
480
static const struct Interval default_wide_blocks[] = {
481
  { 0x3400, 0x4dbf },
482
  { 0x4e00, 0x9fff },
483
  { 0xf900, 0xfaff },
484
  { 0x20000, 0x2fffd },
485
  { 0x30000, 0x3fffd }
486
};
487
488
/**
489
 * g_unichar_iswide:
490
 * @c: a Unicode character
491
 * 
492
 * Determines if a character is typically rendered in a double-width
493
 * cell.
494
 * 
495
 * Returns: %TRUE if the character is wide
496
 **/
497
gboolean
498
g_unichar_iswide (gunichar c)
499
0
{
500
0
  if (c < g_unicode_width_table_wide[0].start)
501
0
    return FALSE;
502
0
  else if (g_unichar_iswide_bsearch (c))
503
0
    return TRUE;
504
0
  else if (g_unichar_type (c) == G_UNICODE_UNASSIGNED &&
505
0
           bsearch (GUINT_TO_POINTER (c),
506
0
                    default_wide_blocks,
507
0
                    G_N_ELEMENTS (default_wide_blocks),
508
0
                    sizeof default_wide_blocks[0],
509
0
                    interval_compare))
510
0
    return TRUE;
511
512
0
  return FALSE;
513
0
}
514
515
516
/**
517
 * g_unichar_iswide_cjk:
518
 * @c: a Unicode character
519
 * 
520
 * Determines if a character is typically rendered in a double-width
521
 * cell under legacy East Asian locales.  If a character is wide according to
522
 * g_unichar_iswide(), then it is also reported wide with this function, but
523
 * the converse is not necessarily true. See the
524
 * [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
525
 * for details.
526
 *
527
 * If a character passes the g_unichar_iswide() test then it will also pass
528
 * this test, but not the other way around.  Note that some characters may
529
 * pass both this test and g_unichar_iszerowidth().
530
 * 
531
 * Returns: %TRUE if the character is wide in legacy East Asian locales
532
 *
533
 * Since: 2.12
534
 */
535
gboolean
536
g_unichar_iswide_cjk (gunichar c)
537
0
{
538
0
  if (g_unichar_iswide (c))
539
0
    return TRUE;
540
541
  /* bsearch() is declared attribute(nonnull(1)) so we can't validly search
542
   * for a NULL key */
543
0
  if (c == 0)
544
0
    return FALSE;
545
546
0
  if (bsearch (GUINT_TO_POINTER (c), 
547
0
               g_unicode_width_table_ambiguous,
548
0
               G_N_ELEMENTS (g_unicode_width_table_ambiguous),
549
0
               sizeof g_unicode_width_table_ambiguous[0],
550
0
         interval_compare))
551
0
    return TRUE;
552
553
0
  return FALSE;
554
0
}
555
556
557
/**
558
 * g_unichar_toupper:
559
 * @c: a Unicode character
560
 * 
561
 * Converts a character to uppercase.
562
 * 
563
 * Returns: the result of converting @c to uppercase.
564
 *               If @c is not a lowercase or titlecase character,
565
 *               or has no upper case equivalent @c is returned unchanged.
566
 **/
567
gunichar
568
g_unichar_toupper (gunichar c)
569
0
{
570
0
  int t = TYPE (c);
571
0
  if (t == G_UNICODE_LOWERCASE_LETTER)
572
0
    {
573
0
      gunichar val = ATTTABLE (c >> 8, c & 0xff);
574
0
      if (val >= 0x1000000)
575
0
  {
576
0
          const gchar *p = special_case_table + (val - 0x1000000);
577
0
          val = g_utf8_get_char (p);
578
0
  }
579
      /* Some lowercase letters, e.g., U+000AA, FEMININE ORDINAL INDICATOR,
580
       * do not have an uppercase equivalent, in which case val will be
581
       * zero. 
582
       */
583
0
      return val ? val : c;
584
0
    }
585
0
  else if (t == G_UNICODE_TITLECASE_LETTER)
586
0
    {
587
0
      unsigned int i;
588
0
      for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
589
0
  {
590
0
    if (title_table[i][0] == c)
591
0
      return title_table[i][1] ? title_table[i][1] : c;
592
0
  }
593
0
    }
594
0
  return c;
595
0
}
596
597
/**
598
 * g_unichar_tolower:
599
 * @c: a Unicode character.
600
 * 
601
 * Converts a character to lower case.
602
 * 
603
 * Returns: the result of converting @c to lower case.
604
 *               If @c is not an upperlower or titlecase character,
605
 *               or has no lowercase equivalent @c is returned unchanged.
606
 **/
607
gunichar
608
g_unichar_tolower (gunichar c)
609
0
{
610
0
  int t = TYPE (c);
611
0
  if (t == G_UNICODE_UPPERCASE_LETTER)
612
0
    {
613
0
      gunichar val = ATTTABLE (c >> 8, c & 0xff);
614
0
      if (val >= 0x1000000)
615
0
  {
616
0
          const gchar *p = special_case_table + (val - 0x1000000);
617
0
          return g_utf8_get_char (p);
618
0
  }
619
0
      else
620
0
  {
621
    /* Not all uppercase letters are guaranteed to have a lowercase
622
     * equivalent.  If this is the case, val will be zero. */
623
0
    return val ? val : c;
624
0
  }
625
0
    }
626
0
  else if (t == G_UNICODE_TITLECASE_LETTER)
627
0
    {
628
0
      unsigned int i;
629
0
      for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
630
0
  {
631
0
    if (title_table[i][0] == c)
632
0
      return title_table[i][2];
633
0
  }
634
0
    }
635
0
  return c;
636
0
}
637
638
/**
639
 * g_unichar_totitle:
640
 * @c: a Unicode character
641
 * 
642
 * Converts a character to the titlecase.
643
 * 
644
 * Returns: the result of converting @c to titlecase.
645
 *               If @c is not an uppercase or lowercase character,
646
 *               @c is returned unchanged.
647
 **/
648
gunichar
649
g_unichar_totitle (gunichar c)
650
0
{
651
0
  unsigned int i;
652
653
  /* We handle U+0000 explicitly because some elements in
654
   * title_table[i][1] may be null. */
655
0
  if (c == 0)
656
0
    return c;
657
658
0
  for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
659
0
    {
660
0
      if (title_table[i][0] == c || title_table[i][1] == c
661
0
    || title_table[i][2] == c)
662
0
  return title_table[i][0];
663
0
    }
664
665
0
  if (TYPE (c) == G_UNICODE_LOWERCASE_LETTER)
666
0
    return g_unichar_toupper (c);
667
668
0
  return c;
669
0
}
670
671
/**
672
 * g_unichar_digit_value:
673
 * @c: a Unicode character
674
 *
675
 * Determines the numeric value of a character as a decimal
676
 * digit.
677
 *
678
 * Returns: If @c is a decimal digit (according to
679
 * g_unichar_isdigit()), its numeric value. Otherwise, -1.
680
 **/
681
int
682
g_unichar_digit_value (gunichar c)
683
0
{
684
0
  if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
685
0
    return ATTTABLE (c >> 8, c & 0xff);
686
0
  return -1;
687
0
}
688
689
/**
690
 * g_unichar_xdigit_value:
691
 * @c: a Unicode character
692
 *
693
 * Determines the numeric value of a character as a hexadecimal
694
 * digit.
695
 *
696
 * Returns: If @c is a hex digit (according to
697
 * g_unichar_isxdigit()), its numeric value. Otherwise, -1.
698
 **/
699
int
700
g_unichar_xdigit_value (gunichar c)
701
0
{
702
0
  if (c >= 'A' && c <= 'F')
703
0
    return c - 'A' + 10;
704
0
  if (c >= 'a' && c <= 'f')
705
0
    return c - 'a' + 10;
706
0
  if (c >= G_UNICHAR_FULLWIDTH_A && c <= G_UNICHAR_FULLWIDTH_F)
707
0
    return c - G_UNICHAR_FULLWIDTH_A + 10;
708
0
  if (c >= G_UNICHAR_FULLWIDTH_a && c <= G_UNICHAR_FULLWIDTH_f)
709
0
    return c - G_UNICHAR_FULLWIDTH_a + 10;
710
0
  if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
711
0
    return ATTTABLE (c >> 8, c & 0xff);
712
0
  return -1;
713
0
}
714
715
/**
716
 * g_unichar_type:
717
 * @c: a Unicode character
718
 * 
719
 * Classifies a Unicode character by type.
720
 * 
721
 * Returns: the type of the character.
722
 **/
723
GUnicodeType
724
g_unichar_type (gunichar c)
725
0
{
726
0
  return TYPE (c);
727
0
}
728
729
/*
730
 * Case mapping functions
731
 */
732
733
typedef enum {
734
  LOCALE_NORMAL,
735
  LOCALE_TURKIC,
736
  LOCALE_LITHUANIAN
737
} LocaleType;
738
739
static LocaleType
740
get_locale_type (void)
741
0
{
742
#ifdef G_OS_WIN32
743
  char *tem = g_win32_getlocale ();
744
  char locale[2];
745
746
  locale[0] = tem[0];
747
  locale[1] = tem[1];
748
  g_free (tem);
749
#else
750
0
  const char *locale = setlocale (LC_CTYPE, NULL);
751
752
0
  if (locale == NULL)
753
0
    return LOCALE_NORMAL;
754
0
#endif
755
756
0
  switch (locale[0])
757
0
    {
758
0
   case 'a':
759
0
      if (locale[1] == 'z')
760
0
  return LOCALE_TURKIC;
761
0
      break;
762
0
    case 'l':
763
0
      if (locale[1] == 't')
764
0
  return LOCALE_LITHUANIAN;
765
0
      break;
766
0
    case 't':
767
0
      if (locale[1] == 'r')
768
0
  return LOCALE_TURKIC;
769
0
      break;
770
0
    }
771
772
0
  return LOCALE_NORMAL;
773
0
}
774
775
G_ALWAYS_INLINE static inline void
776
increase_size (size_t *sizeptr, size_t add)
777
0
{
778
0
  g_assert (G_MAXSIZE - *(sizeptr) >= add);
779
0
  *(sizeptr) += add;
780
0
}
781
782
G_ALWAYS_INLINE static inline void
783
append_utf8_char_to_buffer (gunichar  c,
784
                            char     *out_buffer,
785
                            size_t   *in_out_len)
786
0
{
787
0
  gint utf8_len;
788
0
  char *buffer;
789
790
0
  buffer = out_buffer ? out_buffer + *(in_out_len) : NULL;
791
0
  utf8_len = g_unichar_to_utf8 (c, buffer);
792
793
0
  g_assert (utf8_len >= 0);
794
0
  increase_size (in_out_len, utf8_len);
795
0
}
796
797
static void
798
append_mark (const char **p_inout,
799
             char        *out_buffer,
800
             size_t      *in_out_len,
801
             gboolean     remove_dot)
802
0
{
803
0
  const char *p = *p_inout;
804
805
0
  while (*p)
806
0
    {
807
0
      gunichar c = g_utf8_get_char (p);
808
      
809
0
      if (ISMARK (TYPE (c)))
810
0
  {
811
0
    if (!remove_dot || c != 0x307 /* COMBINING DOT ABOVE */)
812
0
            append_utf8_char_to_buffer (c, out_buffer, in_out_len);
813
0
    p = g_utf8_next_char (p);
814
0
  }
815
0
      else
816
0
  break;
817
0
    }
818
819
0
  *p_inout = p;
820
0
}
821
822
static void
823
append_special_case (char   *out_buffer,
824
                     size_t *in_out_len,
825
                     int     offset,
826
                     int     type,
827
                     int     which)
828
0
{
829
0
  const gchar *p = special_case_table + offset;
830
0
  size_t len;
831
832
0
  if (type != G_UNICODE_TITLECASE_LETTER)
833
0
    p = g_utf8_next_char (p);
834
835
0
  if (which == 1)
836
0
    p += strlen (p) + 1;
837
838
0
  len = strlen (p);
839
0
  g_assert (len < G_MAXSIZE - *in_out_len);
840
841
0
  if (out_buffer)
842
0
    memcpy (out_buffer + *in_out_len, p, len);
843
844
0
  increase_size (in_out_len, len);
845
0
}
846
847
static gsize
848
real_toupper (const gchar *str,
849
        gssize       max_len,
850
        gchar       *out_buffer,
851
        LocaleType   locale_type)
852
0
{
853
0
  const gchar *p = str;
854
0
  const char *last = NULL;
855
0
  gsize len = 0;
856
0
  gboolean last_was_i = FALSE;
857
858
0
  while ((max_len < 0 || p < str + max_len) && *p)
859
0
    {
860
0
      gunichar c = g_utf8_get_char (p);
861
0
      int t = TYPE (c);
862
0
      gunichar val;
863
864
0
      last = p;
865
0
      p = g_utf8_next_char (p);
866
867
0
      if (locale_type == LOCALE_LITHUANIAN)
868
0
  {
869
0
    if (c == 'i')
870
0
      last_was_i = TRUE;
871
0
    else 
872
0
      {
873
0
        if (last_was_i)
874
0
    {
875
      /* Nasty, need to remove any dot above. Though
876
       * I think only E WITH DOT ABOVE occurs in practice
877
       * which could simplify this considerably.
878
       */
879
0
      gsize decomp_len, i;
880
0
      gunichar decomp[G_UNICHAR_MAX_DECOMPOSITION_LENGTH];
881
882
0
      decomp_len = g_unichar_fully_decompose (c, FALSE, decomp, G_N_ELEMENTS (decomp));
883
0
      for (i=0; i < decomp_len; i++)
884
0
        {
885
886
0
          if (decomp[i] != 0x307 /* COMBINING DOT ABOVE */)
887
0
                        append_utf8_char_to_buffer (g_unichar_toupper (decomp[i]),
888
0
                                                    out_buffer, &len);
889
0
        }
890
891
0
                  append_mark (&p, out_buffer, &len, TRUE);
892
893
0
      continue;
894
0
    }
895
896
0
        if (!ISMARK (t))
897
0
    last_was_i = FALSE;
898
0
      }
899
0
  }
900
901
0
      if (locale_type == LOCALE_TURKIC && c == 'i')
902
0
  {
903
    /* i => LATIN CAPITAL LETTER I WITH DOT ABOVE */
904
0
          append_utf8_char_to_buffer (0x130, out_buffer, &len);
905
0
  }
906
0
      else if (c == 0x0345) /* COMBINING GREEK YPOGEGRAMMENI */
907
0
  {
908
    /* Nasty, need to move it after other combining marks .. this would go away if
909
     * we normalized first.
910
     */
911
0
          append_mark (&p, out_buffer, &len, TRUE);
912
913
    /* And output as GREEK CAPITAL LETTER IOTA */
914
0
          append_utf8_char_to_buffer (0x399, out_buffer, &len);
915
0
  }
916
0
      else if (IS (t,
917
0
       OR (G_UNICODE_LOWERCASE_LETTER,
918
0
       OR (G_UNICODE_TITLECASE_LETTER,
919
0
      0))))
920
0
  {
921
0
    val = ATTTABLE (c >> 8, c & 0xff);
922
923
0
    if (val >= 0x1000000)
924
0
      {
925
0
              append_special_case (out_buffer, &len, val - 0x1000000, t,
926
0
                                   t == G_UNICODE_LOWERCASE_LETTER ? 0 : 1);
927
0
      }
928
0
    else
929
0
      {
930
0
        if (t == G_UNICODE_TITLECASE_LETTER)
931
0
    {
932
0
      unsigned int i;
933
0
      for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
934
0
        {
935
0
          if (title_table[i][0] == c)
936
0
      {
937
0
        val = title_table[i][1];
938
0
        break;
939
0
      }
940
0
        }
941
0
    }
942
943
        /* Some lowercase letters, e.g., U+000AA, FEMININE ORDINAL INDICATOR,
944
         * do not have an uppercase equivalent, in which case val will be
945
         * zero. */
946
0
              append_utf8_char_to_buffer (val ? val : c, out_buffer, &len);
947
0
      }
948
0
  }
949
0
      else
950
0
  {
951
0
    gsize char_len = g_utf8_skip[*(guchar *)last];
952
953
0
    if (out_buffer)
954
0
      memcpy (out_buffer + len, last, char_len);
955
956
0
          increase_size (&len, char_len);
957
0
  }
958
959
0
    }
960
961
0
  return len;
962
0
}
963
964
/**
965
 * g_utf8_strup:
966
 * @str: a UTF-8 encoded string
967
 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
968
 * 
969
 * Converts all Unicode characters in the string that have a case
970
 * to uppercase. The exact manner that this is done depends
971
 * on the current locale, and may result in the number of
972
 * characters in the string increasing. (For instance, the
973
 * German ess-zet will be changed to SS.)
974
 * 
975
 * Returns: a newly allocated string, with all characters
976
 *    converted to uppercase.  
977
 **/
978
gchar *
979
g_utf8_strup (const gchar *str,
980
        gssize       len)
981
0
{
982
0
  gsize result_len;
983
0
  LocaleType locale_type;
984
0
  gchar *result;
985
986
0
  g_return_val_if_fail (str != NULL, NULL);
987
988
0
  locale_type = get_locale_type ();
989
  
990
  /*
991
   * We use a two pass approach to keep memory management simple
992
   */
993
0
  result_len = real_toupper (str, len, NULL, locale_type);
994
0
  g_assert (result_len < G_MAXSIZE);
995
996
0
  result = g_malloc (result_len + 1);
997
0
  real_toupper (str, len, result, locale_type);
998
0
  result[result_len] = '\0';
999
1000
0
  return result;
1001
0
}
1002
1003
/* traverses the string checking for characters with combining class == 230
1004
 * until a base character is found */
1005
static gboolean
1006
has_more_above (const gchar *str)
1007
0
{
1008
0
  const gchar *p = str;
1009
0
  gint combining_class;
1010
1011
0
  while (*p)
1012
0
    {
1013
0
      combining_class = g_unichar_combining_class (g_utf8_get_char (p));
1014
0
      if (combining_class == 230)
1015
0
        return TRUE;
1016
0
      else if (combining_class == 0)
1017
0
        break;
1018
1019
0
      p = g_utf8_next_char (p);
1020
0
    }
1021
1022
0
  return FALSE;
1023
0
}
1024
1025
static gsize
1026
real_tolower (const gchar *str,
1027
        gssize       max_len,
1028
        gchar       *out_buffer,
1029
        LocaleType   locale_type)
1030
0
{
1031
0
  const gchar *p = str;
1032
0
  const char *last = NULL;
1033
0
  gsize len = 0;
1034
1035
0
  while ((max_len < 0 || p < str + max_len) && *p)
1036
0
    {
1037
0
      gunichar c = g_utf8_get_char (p);
1038
0
      int t = TYPE (c);
1039
0
      gunichar val;
1040
1041
0
      last = p;
1042
0
      p = g_utf8_next_char (p);
1043
1044
0
      if (locale_type == LOCALE_TURKIC && (c == 'I' || c == 0x130 ||
1045
0
                                           c == G_UNICHAR_FULLWIDTH_I))
1046
0
        {
1047
0
          gboolean combining_dot = (c == 'I' || c == G_UNICHAR_FULLWIDTH_I) &&
1048
0
                                   g_utf8_get_char (p) == 0x0307;
1049
0
          if (combining_dot || c == 0x130)
1050
0
            {
1051
              /* I + COMBINING DOT ABOVE => i (U+0069)
1052
               * LATIN CAPITAL LETTER I WITH DOT ABOVE => i (U+0069) */
1053
0
              append_utf8_char_to_buffer (0x0069, out_buffer, &len);
1054
1055
0
              if (combining_dot)
1056
0
                p = g_utf8_next_char (p);
1057
0
            }
1058
0
          else
1059
0
            {
1060
              /* I => LATIN SMALL LETTER DOTLESS I */
1061
0
              append_utf8_char_to_buffer (0x131, out_buffer, &len);
1062
0
            }
1063
0
        }
1064
      /* Introduce an explicit dot above when lowercasing capital I's and J's
1065
       * whenever there are more accents above. [SpecialCasing.txt] */
1066
0
      else if (locale_type == LOCALE_LITHUANIAN && 
1067
0
               (c == 0x00cc || c == 0x00cd || c == 0x0128))
1068
0
        {
1069
0
          append_utf8_char_to_buffer (0x0069, out_buffer, &len);
1070
0
          append_utf8_char_to_buffer (0x0307, out_buffer, &len);
1071
1072
0
          switch (c)
1073
0
            {
1074
0
            case 0x00cc: 
1075
0
              append_utf8_char_to_buffer (0x0300, out_buffer, &len);
1076
0
              break;
1077
0
            case 0x00cd: 
1078
0
              append_utf8_char_to_buffer (0x0301, out_buffer, &len);
1079
0
              break;
1080
0
            case 0x0128: 
1081
0
              append_utf8_char_to_buffer (0x0303, out_buffer, &len);
1082
0
              break;
1083
0
            }
1084
0
        }
1085
0
      else if (locale_type == LOCALE_LITHUANIAN && 
1086
0
               (c == 'I' || c == G_UNICHAR_FULLWIDTH_I ||
1087
0
                c == 'J' || c == G_UNICHAR_FULLWIDTH_J || c == 0x012e) &&
1088
0
               has_more_above (p))
1089
0
        {
1090
0
          append_utf8_char_to_buffer (g_unichar_tolower (c), out_buffer, &len);
1091
0
          append_utf8_char_to_buffer (0x0307, out_buffer, &len);
1092
0
        }
1093
0
      else if (c == 0x03A3) /* GREEK CAPITAL LETTER SIGMA */
1094
0
  {
1095
0
    if ((max_len < 0 || p < str + max_len) && *p)
1096
0
      {
1097
0
        gunichar next_c = g_utf8_get_char (p);
1098
0
        int next_type = TYPE(next_c);
1099
1100
        /* SIGMA mapps differently depending on whether it is
1101
         * final or not. The following simplified test would
1102
         * fail in the case of combining marks following the
1103
         * sigma, but I don't think that occurs in real text.
1104
         * The test here matches that in ICU.
1105
         */
1106
0
        if (ISALPHA (next_type)) /* Lu,Ll,Lt,Lm,Lo */
1107
0
    val = 0x3c3; /* GREEK SMALL SIGMA */
1108
0
        else
1109
0
    val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
1110
0
      }
1111
0
    else
1112
0
      val = 0x3c2; /* GREEK SMALL FINAL SIGMA */
1113
1114
0
          append_utf8_char_to_buffer (val, out_buffer, &len);
1115
0
  }
1116
0
      else if (IS (t,
1117
0
       OR (G_UNICODE_UPPERCASE_LETTER,
1118
0
       OR (G_UNICODE_TITLECASE_LETTER,
1119
0
      0))))
1120
0
  {
1121
0
    val = ATTTABLE (c >> 8, c & 0xff);
1122
1123
0
    if (val >= 0x1000000)
1124
0
      {
1125
0
              append_special_case (out_buffer, &len, val - 0x1000000, t, 0);
1126
0
      }
1127
0
    else
1128
0
      {
1129
0
        if (t == G_UNICODE_TITLECASE_LETTER)
1130
0
    {
1131
0
      unsigned int i;
1132
0
      for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
1133
0
        {
1134
0
          if (title_table[i][0] == c)
1135
0
      {
1136
0
        val = title_table[i][2];
1137
0
        break;
1138
0
      }
1139
0
        }
1140
0
    }
1141
1142
        /* Not all uppercase letters are guaranteed to have a lowercase
1143
         * equivalent.  If this is the case, val will be zero. */
1144
0
              append_utf8_char_to_buffer (val ? val : c, out_buffer, &len);
1145
0
      }
1146
0
  }
1147
0
      else
1148
0
  {
1149
0
    gsize char_len = g_utf8_skip[*(guchar *)last];
1150
1151
0
    if (out_buffer)
1152
0
      memcpy (out_buffer + len, last, char_len);
1153
1154
0
          increase_size (&len, char_len);
1155
0
  }
1156
1157
0
    }
1158
1159
0
  return len;
1160
0
}
1161
1162
/**
1163
 * g_utf8_strdown:
1164
 * @str: a UTF-8 encoded string
1165
 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
1166
 * 
1167
 * Converts all Unicode characters in the string that have a case
1168
 * to lowercase. The exact manner that this is done depends
1169
 * on the current locale, and may result in the number of
1170
 * characters in the string changing.
1171
 * 
1172
 * Returns: a newly allocated string, with all characters
1173
 *    converted to lowercase.  
1174
 **/
1175
gchar *
1176
g_utf8_strdown (const gchar *str,
1177
    gssize       len)
1178
0
{
1179
0
  gsize result_len;
1180
0
  LocaleType locale_type;
1181
0
  gchar *result;
1182
1183
0
  g_return_val_if_fail (str != NULL, NULL);
1184
1185
0
  locale_type = get_locale_type ();
1186
  
1187
  /*
1188
   * We use a two pass approach to keep memory management simple
1189
   */
1190
0
  result_len = real_tolower (str, len, NULL, locale_type);
1191
0
  g_assert (result_len < G_MAXSIZE);
1192
1193
0
  result = g_malloc (result_len + 1);
1194
0
  real_tolower (str, len, result, locale_type);
1195
0
  result[result_len] = '\0';
1196
1197
0
  return result;
1198
0
}
1199
1200
/**
1201
 * g_utf8_casefold:
1202
 * @str: a UTF-8 encoded string
1203
 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
1204
 * 
1205
 * Converts a string into a form that is independent of case. The
1206
 * result will not correspond to any particular case, but can be
1207
 * compared for equality or ordered with the results of calling
1208
 * g_utf8_casefold() on other strings.
1209
 * 
1210
 * Note that calling g_utf8_casefold() followed by g_utf8_collate() is
1211
 * only an approximation to the correct linguistic case insensitive
1212
 * ordering, though it is a fairly good one. Getting this exactly
1213
 * right would require a more sophisticated collation function that
1214
 * takes case sensitivity into account. GLib does not currently
1215
 * provide such a function.
1216
 * 
1217
 * Returns: a newly allocated string, that is a
1218
 *   case independent form of @str.
1219
 **/
1220
gchar *
1221
g_utf8_casefold (const gchar *str,
1222
     gssize       len)
1223
0
{
1224
0
  GString *result;
1225
0
  const char *p;
1226
1227
0
  g_return_val_if_fail (str != NULL, NULL);
1228
1229
0
  result = g_string_new (NULL);
1230
0
  p = str;
1231
0
  while ((len < 0 || p < str + len) && *p)
1232
0
    {
1233
0
      gunichar ch = g_utf8_get_char (p);
1234
1235
0
      int start = 0;
1236
0
      int end = G_N_ELEMENTS (casefold_table);
1237
1238
0
      if (ch >= casefold_table[start].ch &&
1239
0
          ch <= casefold_table[end - 1].ch)
1240
0
  {
1241
0
    while (TRUE)
1242
0
      {
1243
0
        int half = (start + end) / 2;
1244
0
        if (ch == casefold_table[half].ch)
1245
0
    {
1246
0
      g_string_append (result, casefold_table[half].data);
1247
0
      goto next;
1248
0
    }
1249
0
        else if (half == start)
1250
0
    break;
1251
0
        else if (ch > casefold_table[half].ch)
1252
0
    start = half;
1253
0
        else
1254
0
    end = half;
1255
0
      }
1256
0
  }
1257
1258
0
      g_string_append_unichar (result, g_unichar_tolower (ch));
1259
      
1260
0
    next:
1261
0
      p = g_utf8_next_char (p);
1262
0
    }
1263
1264
0
  return g_string_free (result, FALSE); 
1265
0
}
1266
1267
/**
1268
 * g_unichar_get_mirror_char:
1269
 * @ch: a Unicode character
1270
 * @mirrored_ch: (out): location to store the mirrored character
1271
 * 
1272
 * In Unicode, some characters are "mirrored". This means that their
1273
 * images are mirrored horizontally in text that is laid out from right
1274
 * to left. For instance, "(" would become its mirror image, ")", in
1275
 * right-to-left text.
1276
 *
1277
 * If @ch has the Unicode mirrored property and there is another unicode
1278
 * character that typically has a glyph that is the mirror image of @ch's
1279
 * glyph and @mirrored_ch is set, it puts that character in the address
1280
 * pointed to by @mirrored_ch.  Otherwise the original character is put.
1281
 *
1282
 * Returns: %TRUE if @ch has a mirrored character, %FALSE otherwise
1283
 *
1284
 * Since: 2.4
1285
 **/
1286
gboolean
1287
g_unichar_get_mirror_char (gunichar ch,
1288
                           gunichar *mirrored_ch)
1289
0
{
1290
0
  gboolean found;
1291
0
  gunichar mirrored;
1292
1293
0
  mirrored = GLIB_GET_MIRRORING(ch);
1294
1295
0
  found = ch != mirrored;
1296
0
  if (mirrored_ch)
1297
0
    *mirrored_ch = mirrored;
1298
1299
0
  return found;
1300
1301
0
}
1302
1303
0
#define G_SCRIPT_TABLE_MIDPOINT (G_N_ELEMENTS (g_script_table) / 2)
1304
1305
static inline GUnicodeScript
1306
g_unichar_get_script_bsearch (gunichar ch)
1307
0
{
1308
0
  int lower = 0;
1309
0
  int upper = G_N_ELEMENTS (g_script_table) - 1;
1310
0
  static int saved_mid = G_SCRIPT_TABLE_MIDPOINT;
1311
0
  int mid = saved_mid;
1312
1313
1314
0
  do 
1315
0
    {
1316
0
      if (ch < g_script_table[mid].start)
1317
0
  upper = mid - 1;
1318
0
      else if (ch >= g_script_table[mid].start + g_script_table[mid].chars)
1319
0
  lower = mid + 1;
1320
0
      else
1321
0
  return g_script_table[saved_mid = mid].script;
1322
1323
0
      mid = (lower + upper) / 2;
1324
0
    }
1325
0
  while (lower <= upper);
1326
1327
0
  return G_UNICODE_SCRIPT_UNKNOWN;
1328
0
}
1329
1330
/**
1331
 * g_unichar_get_script:
1332
 * @ch: a Unicode character
1333
 * 
1334
 * Looks up the #GUnicodeScript for a particular character (as defined 
1335
 * by Unicode Standard Annex \#24). No check is made for @ch being a
1336
 * valid Unicode character; if you pass in invalid character, the
1337
 * result is undefined.
1338
 *
1339
 * This function is equivalent to pango_script_for_unichar() and the
1340
 * two are interchangeable.
1341
 * 
1342
 * Returns: the #GUnicodeScript for the character.
1343
 *
1344
 * Since: 2.14
1345
 */
1346
GUnicodeScript
1347
g_unichar_get_script (gunichar ch)
1348
0
{
1349
0
  if (ch < G_EASY_SCRIPTS_RANGE)
1350
0
    return g_script_easy_table[ch];
1351
0
  else 
1352
0
    return g_unichar_get_script_bsearch (ch); 
1353
0
}
1354
1355
1356
/* http://unicode.org/iso15924/ */
1357
static const guint32 iso15924_tags[] =
1358
{
1359
#define PACK(a,b,c,d) ((guint32)((((guint8)(a))<<24)|(((guint8)(b))<<16)|(((guint8)(c))<<8)|((guint8)(d))))
1360
1361
    PACK ('Z','y','y','y'), /* G_UNICODE_SCRIPT_COMMON */
1362
    PACK ('Z','i','n','h'), /* G_UNICODE_SCRIPT_INHERITED */
1363
    PACK ('A','r','a','b'), /* G_UNICODE_SCRIPT_ARABIC */
1364
    PACK ('A','r','m','n'), /* G_UNICODE_SCRIPT_ARMENIAN */
1365
    PACK ('B','e','n','g'), /* G_UNICODE_SCRIPT_BENGALI */
1366
    PACK ('B','o','p','o'), /* G_UNICODE_SCRIPT_BOPOMOFO */
1367
    PACK ('C','h','e','r'), /* G_UNICODE_SCRIPT_CHEROKEE */
1368
    PACK ('C','o','p','t'), /* G_UNICODE_SCRIPT_COPTIC */
1369
    PACK ('C','y','r','l'), /* G_UNICODE_SCRIPT_CYRILLIC */
1370
    PACK ('D','s','r','t'), /* G_UNICODE_SCRIPT_DESERET */
1371
    PACK ('D','e','v','a'), /* G_UNICODE_SCRIPT_DEVANAGARI */
1372
    PACK ('E','t','h','i'), /* G_UNICODE_SCRIPT_ETHIOPIC */
1373
    PACK ('G','e','o','r'), /* G_UNICODE_SCRIPT_GEORGIAN */
1374
    PACK ('G','o','t','h'), /* G_UNICODE_SCRIPT_GOTHIC */
1375
    PACK ('G','r','e','k'), /* G_UNICODE_SCRIPT_GREEK */
1376
    PACK ('G','u','j','r'), /* G_UNICODE_SCRIPT_GUJARATI */
1377
    PACK ('G','u','r','u'), /* G_UNICODE_SCRIPT_GURMUKHI */
1378
    PACK ('H','a','n','i'), /* G_UNICODE_SCRIPT_HAN */
1379
    PACK ('H','a','n','g'), /* G_UNICODE_SCRIPT_HANGUL */
1380
    PACK ('H','e','b','r'), /* G_UNICODE_SCRIPT_HEBREW */
1381
    PACK ('H','i','r','a'), /* G_UNICODE_SCRIPT_HIRAGANA */
1382
    PACK ('K','n','d','a'), /* G_UNICODE_SCRIPT_KANNADA */
1383
    PACK ('K','a','n','a'), /* G_UNICODE_SCRIPT_KATAKANA */
1384
    PACK ('K','h','m','r'), /* G_UNICODE_SCRIPT_KHMER */
1385
    PACK ('L','a','o','o'), /* G_UNICODE_SCRIPT_LAO */
1386
    PACK ('L','a','t','n'), /* G_UNICODE_SCRIPT_LATIN */
1387
    PACK ('M','l','y','m'), /* G_UNICODE_SCRIPT_MALAYALAM */
1388
    PACK ('M','o','n','g'), /* G_UNICODE_SCRIPT_MONGOLIAN */
1389
    PACK ('M','y','m','r'), /* G_UNICODE_SCRIPT_MYANMAR */
1390
    PACK ('O','g','a','m'), /* G_UNICODE_SCRIPT_OGHAM */
1391
    PACK ('I','t','a','l'), /* G_UNICODE_SCRIPT_OLD_ITALIC */
1392
    PACK ('O','r','y','a'), /* G_UNICODE_SCRIPT_ORIYA */
1393
    PACK ('R','u','n','r'), /* G_UNICODE_SCRIPT_RUNIC */
1394
    PACK ('S','i','n','h'), /* G_UNICODE_SCRIPT_SINHALA */
1395
    PACK ('S','y','r','c'), /* G_UNICODE_SCRIPT_SYRIAC */
1396
    PACK ('T','a','m','l'), /* G_UNICODE_SCRIPT_TAMIL */
1397
    PACK ('T','e','l','u'), /* G_UNICODE_SCRIPT_TELUGU */
1398
    PACK ('T','h','a','a'), /* G_UNICODE_SCRIPT_THAANA */
1399
    PACK ('T','h','a','i'), /* G_UNICODE_SCRIPT_THAI */
1400
    PACK ('T','i','b','t'), /* G_UNICODE_SCRIPT_TIBETAN */
1401
    PACK ('C','a','n','s'), /* G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL */
1402
    PACK ('Y','i','i','i'), /* G_UNICODE_SCRIPT_YI */
1403
    PACK ('T','g','l','g'), /* G_UNICODE_SCRIPT_TAGALOG */
1404
    PACK ('H','a','n','o'), /* G_UNICODE_SCRIPT_HANUNOO */
1405
    PACK ('B','u','h','d'), /* G_UNICODE_SCRIPT_BUHID */
1406
    PACK ('T','a','g','b'), /* G_UNICODE_SCRIPT_TAGBANWA */
1407
1408
  /* Unicode-4.0 additions */
1409
    PACK ('B','r','a','i'), /* G_UNICODE_SCRIPT_BRAILLE */
1410
    PACK ('C','p','r','t'), /* G_UNICODE_SCRIPT_CYPRIOT */
1411
    PACK ('L','i','m','b'), /* G_UNICODE_SCRIPT_LIMBU */
1412
    PACK ('O','s','m','a'), /* G_UNICODE_SCRIPT_OSMANYA */
1413
    PACK ('S','h','a','w'), /* G_UNICODE_SCRIPT_SHAVIAN */
1414
    PACK ('L','i','n','b'), /* G_UNICODE_SCRIPT_LINEAR_B */
1415
    PACK ('T','a','l','e'), /* G_UNICODE_SCRIPT_TAI_LE */
1416
    PACK ('U','g','a','r'), /* G_UNICODE_SCRIPT_UGARITIC */
1417
1418
  /* Unicode-4.1 additions */
1419
    PACK ('T','a','l','u'), /* G_UNICODE_SCRIPT_NEW_TAI_LUE */
1420
    PACK ('B','u','g','i'), /* G_UNICODE_SCRIPT_BUGINESE */
1421
    PACK ('G','l','a','g'), /* G_UNICODE_SCRIPT_GLAGOLITIC */
1422
    PACK ('T','f','n','g'), /* G_UNICODE_SCRIPT_TIFINAGH */
1423
    PACK ('S','y','l','o'), /* G_UNICODE_SCRIPT_SYLOTI_NAGRI */
1424
    PACK ('X','p','e','o'), /* G_UNICODE_SCRIPT_OLD_PERSIAN */
1425
    PACK ('K','h','a','r'), /* G_UNICODE_SCRIPT_KHAROSHTHI */
1426
1427
  /* Unicode-5.0 additions */
1428
    PACK ('Z','z','z','z'), /* G_UNICODE_SCRIPT_UNKNOWN */
1429
    PACK ('B','a','l','i'), /* G_UNICODE_SCRIPT_BALINESE */
1430
    PACK ('X','s','u','x'), /* G_UNICODE_SCRIPT_CUNEIFORM */
1431
    PACK ('P','h','n','x'), /* G_UNICODE_SCRIPT_PHOENICIAN */
1432
    PACK ('P','h','a','g'), /* G_UNICODE_SCRIPT_PHAGS_PA */
1433
    PACK ('N','k','o','o'), /* G_UNICODE_SCRIPT_NKO */
1434
1435
  /* Unicode-5.1 additions */
1436
    PACK ('K','a','l','i'), /* G_UNICODE_SCRIPT_KAYAH_LI */
1437
    PACK ('L','e','p','c'), /* G_UNICODE_SCRIPT_LEPCHA */
1438
    PACK ('R','j','n','g'), /* G_UNICODE_SCRIPT_REJANG */
1439
    PACK ('S','u','n','d'), /* G_UNICODE_SCRIPT_SUNDANESE */
1440
    PACK ('S','a','u','r'), /* G_UNICODE_SCRIPT_SAURASHTRA */
1441
    PACK ('C','h','a','m'), /* G_UNICODE_SCRIPT_CHAM */
1442
    PACK ('O','l','c','k'), /* G_UNICODE_SCRIPT_OL_CHIKI */
1443
    PACK ('V','a','i','i'), /* G_UNICODE_SCRIPT_VAI */
1444
    PACK ('C','a','r','i'), /* G_UNICODE_SCRIPT_CARIAN */
1445
    PACK ('L','y','c','i'), /* G_UNICODE_SCRIPT_LYCIAN */
1446
    PACK ('L','y','d','i'), /* G_UNICODE_SCRIPT_LYDIAN */
1447
1448
  /* Unicode-5.2 additions */
1449
    PACK ('A','v','s','t'), /* G_UNICODE_SCRIPT_AVESTAN */
1450
    PACK ('B','a','m','u'), /* G_UNICODE_SCRIPT_BAMUM */
1451
    PACK ('E','g','y','p'), /* G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS */
1452
    PACK ('A','r','m','i'), /* G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC */
1453
    PACK ('P','h','l','i'), /* G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI */
1454
    PACK ('P','r','t','i'), /* G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN */
1455
    PACK ('J','a','v','a'), /* G_UNICODE_SCRIPT_JAVANESE */
1456
    PACK ('K','t','h','i'), /* G_UNICODE_SCRIPT_KAITHI */
1457
    PACK ('L','i','s','u'), /* G_UNICODE_SCRIPT_LISU */
1458
    PACK ('M','t','e','i'), /* G_UNICODE_SCRIPT_MEETEI_MAYEK */
1459
    PACK ('S','a','r','b'), /* G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN */
1460
    PACK ('O','r','k','h'), /* G_UNICODE_SCRIPT_OLD_TURKIC */
1461
    PACK ('S','a','m','r'), /* G_UNICODE_SCRIPT_SAMARITAN */
1462
    PACK ('L','a','n','a'), /* G_UNICODE_SCRIPT_TAI_THAM */
1463
    PACK ('T','a','v','t'), /* G_UNICODE_SCRIPT_TAI_VIET */
1464
1465
  /* Unicode-6.0 additions */
1466
    PACK ('B','a','t','k'), /* G_UNICODE_SCRIPT_BATAK */
1467
    PACK ('B','r','a','h'), /* G_UNICODE_SCRIPT_BRAHMI */
1468
    PACK ('M','a','n','d'), /* G_UNICODE_SCRIPT_MANDAIC */
1469
1470
  /* Unicode-6.1 additions */
1471
    PACK ('C','a','k','m'), /* G_UNICODE_SCRIPT_CHAKMA */
1472
    PACK ('M','e','r','c'), /* G_UNICODE_SCRIPT_MEROITIC_CURSIVE */
1473
    PACK ('M','e','r','o'), /* G_UNICODE_SCRIPT_MEROITIC_HIEROGLYPHS */
1474
    PACK ('P','l','r','d'), /* G_UNICODE_SCRIPT_MIAO */
1475
    PACK ('S','h','r','d'), /* G_UNICODE_SCRIPT_SHARADA */
1476
    PACK ('S','o','r','a'), /* G_UNICODE_SCRIPT_SORA_SOMPENG */
1477
    PACK ('T','a','k','r'), /* G_UNICODE_SCRIPT_TAKRI */
1478
1479
  /* Unicode 7.0 additions */
1480
    PACK ('B','a','s','s'), /* G_UNICODE_SCRIPT_BASSA_VAH */
1481
    PACK ('A','g','h','b'), /* G_UNICODE_SCRIPT_CAUCASIAN_ALBANIAN */
1482
    PACK ('D','u','p','l'), /* G_UNICODE_SCRIPT_DUPLOYAN */
1483
    PACK ('E','l','b','a'), /* G_UNICODE_SCRIPT_ELBASAN */
1484
    PACK ('G','r','a','n'), /* G_UNICODE_SCRIPT_GRANTHA */
1485
    PACK ('K','h','o','j'), /* G_UNICODE_SCRIPT_KHOJKI*/
1486
    PACK ('S','i','n','d'), /* G_UNICODE_SCRIPT_KHUDAWADI */
1487
    PACK ('L','i','n','a'), /* G_UNICODE_SCRIPT_LINEAR_A */
1488
    PACK ('M','a','h','j'), /* G_UNICODE_SCRIPT_MAHAJANI */
1489
    PACK ('M','a','n','i'), /* G_UNICODE_SCRIPT_MANICHAEAN */
1490
    PACK ('M','e','n','d'), /* G_UNICODE_SCRIPT_MENDE_KIKAKUI */
1491
    PACK ('M','o','d','i'), /* G_UNICODE_SCRIPT_MODI */
1492
    PACK ('M','r','o','o'), /* G_UNICODE_SCRIPT_MRO */
1493
    PACK ('N','b','a','t'), /* G_UNICODE_SCRIPT_NABATAEAN */
1494
    PACK ('N','a','r','b'), /* G_UNICODE_SCRIPT_OLD_NORTH_ARABIAN */
1495
    PACK ('P','e','r','m'), /* G_UNICODE_SCRIPT_OLD_PERMIC */
1496
    PACK ('H','m','n','g'), /* G_UNICODE_SCRIPT_PAHAWH_HMONG */
1497
    PACK ('P','a','l','m'), /* G_UNICODE_SCRIPT_PALMYRENE */
1498
    PACK ('P','a','u','c'), /* G_UNICODE_SCRIPT_PAU_CIN_HAU */
1499
    PACK ('P','h','l','p'), /* G_UNICODE_SCRIPT_PSALTER_PAHLAVI */
1500
    PACK ('S','i','d','d'), /* G_UNICODE_SCRIPT_SIDDHAM */
1501
    PACK ('T','i','r','h'), /* G_UNICODE_SCRIPT_TIRHUTA */
1502
    PACK ('W','a','r','a'), /* G_UNICODE_SCRIPT_WARANG_CITI */
1503
1504
  /* Unicode 8.0 additions */
1505
    PACK ('A','h','o','m'), /* G_UNICODE_SCRIPT_AHOM */
1506
    PACK ('H','l','u','w'), /* G_UNICODE_SCRIPT_ANATOLIAN_HIEROGLYPHS */
1507
    PACK ('H','a','t','r'), /* G_UNICODE_SCRIPT_HATRAN */
1508
    PACK ('M','u','l','t'), /* G_UNICODE_SCRIPT_MULTANI */
1509
    PACK ('H','u','n','g'), /* G_UNICODE_SCRIPT_OLD_HUNGARIAN */
1510
    PACK ('S','g','n','w'), /* G_UNICODE_SCRIPT_SIGNWRITING */
1511
1512
  /* Unicode 9.0 additions */
1513
    PACK ('A','d','l','m'), /* G_UNICODE_SCRIPT_ADLAM */
1514
    PACK ('B','h','k','s'), /* G_UNICODE_SCRIPT_BHAIKSUKI */
1515
    PACK ('M','a','r','c'), /* G_UNICODE_SCRIPT_MARCHEN */
1516
    PACK ('N','e','w','a'), /* G_UNICODE_SCRIPT_NEWA */
1517
    PACK ('O','s','g','e'), /* G_UNICODE_SCRIPT_OSAGE */
1518
    PACK ('T','a','n','g'), /* G_UNICODE_SCRIPT_TANGUT */
1519
1520
  /* Unicode 10.0 additions */
1521
    PACK ('G','o','n','m'), /* G_UNICODE_SCRIPT_MASARAM_GONDI */
1522
    PACK ('N','s','h','u'), /* G_UNICODE_SCRIPT_NUSHU */
1523
    PACK ('S','o','y','o'), /* G_UNICODE_SCRIPT_SOYOMBO */
1524
    PACK ('Z','a','n','b'), /* G_UNICODE_SCRIPT_ZANABAZAR_SQUARE */
1525
1526
  /* Unicode 11.0 additions */
1527
    PACK ('D','o','g','r'), /* G_UNICODE_SCRIPT_DOGRA */
1528
    PACK ('G','o','n','g'), /* G_UNICODE_SCRIPT_GUNJALA_GONDI */
1529
    PACK ('R','o','h','g'), /* G_UNICODE_SCRIPT_HANIFI_ROHINGYA */
1530
    PACK ('M','a','k','a'), /* G_UNICODE_SCRIPT_MAKASAR */
1531
    PACK ('M','e','d','f'), /* G_UNICODE_SCRIPT_MEDEFAIDRIN */
1532
    PACK ('S','o','g','o'), /* G_UNICODE_SCRIPT_OLD_SOGDIAN */
1533
    PACK ('S','o','g','d'), /* G_UNICODE_SCRIPT_SOGDIAN */
1534
1535
  /* Unicode 12.0 additions */
1536
    PACK ('E','l','y','m'), /* G_UNICODE_SCRIPT_ELYMAIC */
1537
    PACK ('N','a','n','d'), /* G_UNICODE_SCRIPT_NANDINAGARI */
1538
    PACK ('H','m','n','p'), /* G_UNICODE_SCRIPT_NYIAKENG_PUACHUE_HMONG */
1539
    PACK ('W','c','h','o'), /* G_UNICODE_SCRIPT_WANCHO */
1540
1541
  /* Unicode 13.0 additions */
1542
    PACK ('C', 'h', 'r', 's'), /* G_UNICODE_SCRIPT_CHORASMIAN */
1543
    PACK ('D', 'i', 'a', 'k'), /* G_UNICODE_SCRIPT_DIVES_AKURU */
1544
    PACK ('K', 'i', 't', 's'), /* G_UNICODE_SCRIPT_KHITAN_SMALL_SCRIPT */
1545
    PACK ('Y', 'e', 'z', 'i'), /* G_UNICODE_SCRIPT_YEZIDI */
1546
1547
  /* Unicode 14.0 additions */
1548
    PACK ('C', 'p', 'm', 'n'), /* G_UNICODE_SCRIPT_CYPRO_MINOAN */
1549
    PACK ('O', 'u', 'g', 'r'), /* G_UNICODE_SCRIPT_OLD_UYHUR */
1550
    PACK ('T', 'n', 's', 'a'), /* G_UNICODE_SCRIPT_TANGSA */
1551
    PACK ('T', 'o', 't', 'o'), /* G_UNICODE_SCRIPT_TOTO */
1552
    PACK ('V', 'i', 't', 'h'), /* G_UNICODE_SCRIPT_VITHKUQI */
1553
1554
  /* not really a Unicode script, but part of ISO 15924 */
1555
    PACK ('Z', 'm', 't', 'h'), /* G_UNICODE_SCRIPT_MATH */
1556
1557
    /* Unicode 15.0 additions */
1558
    PACK ('K', 'a', 'w', 'i'), /* G_UNICODE_SCRIPT_KAWI */
1559
    PACK ('N', 'a', 'g', 'm'), /* G_UNICODE_SCRIPT_NAG_MUNDARI */
1560
1561
    /* Unicode 16.0 additions */
1562
    PACK ('T', 'o', 'd', 'r'), /* G_UNICODE_SCRIPT_TODHRI */
1563
    PACK ('G', 'a', 'r', 'a'), /* G_UNICODE_SCRIPT_GARAY */
1564
    PACK ('T', 'u', 't', 'g'), /* G_UNICODE_SCRIPT_TULU_TIGALARI */
1565
    PACK ('S', 'u', 'n', 'u'), /* G_UNICODE_SCRIPT_SUNUWAR */
1566
    PACK ('G', 'u', 'k', 'h'), /* G_UNICODE_SCRIPT_GURUNG_KHEMA */
1567
    PACK ('K', 'r', 'a', 'i'), /* G_UNICODE_SCRIPT_KIRAT_RAI */
1568
    PACK ('O', 'n', 'a', 'o'), /* G_UNICODE_SCRIPT_OL_ONAL */
1569
1570
    PACK ('S', 'i', 'd', 't'), /* G_UNICODE_SCRIPT_SIDETIC */
1571
    PACK ('T', 'o', 'l', 's'), /* G_UNICODE_SCRIPT_TOLONG_SIKI */
1572
    PACK ('T', 'a', 'y', 'o'), /* G_UNICODE_SCRIPT_TAI_YO */
1573
    PACK ('B', 'e', 'r', 'f'), /* G_UNICODE_SCRIPT_BERIA_ERFE */
1574
1575
#undef PACK
1576
};
1577
1578
/**
1579
 * g_unicode_script_to_iso15924:
1580
 * @script: a Unicode script
1581
 *
1582
 * Looks up the ISO 15924 code for @script.  ISO 15924 assigns four-letter
1583
 * codes to scripts.  For example, the code for Arabic is 'Arab'.  The
1584
 * four letter codes are encoded as a @guint32 by this function in a
1585
 * big-endian fashion.  That is, the code returned for Arabic is
1586
 * 0x41726162 (0x41 is ASCII code for 'A', 0x72 is ASCII code for 'r', etc).
1587
 *
1588
 * See
1589
 * [Codes for the representation of names of scripts](http://unicode.org/iso15924/codelists.html)
1590
 * for details.
1591
 *
1592
 * Returns: the ISO 15924 code for @script, encoded as an integer,
1593
 *   of zero if @script is %G_UNICODE_SCRIPT_INVALID_CODE or
1594
 *   ISO 15924 code 'Zzzz' (script code for UNKNOWN) if @script is not understood.
1595
 *
1596
 * Since: 2.30
1597
 */
1598
guint32
1599
g_unicode_script_to_iso15924 (GUnicodeScript script)
1600
0
{
1601
0
  if (G_UNLIKELY (script == G_UNICODE_SCRIPT_INVALID_CODE))
1602
0
    return 0;
1603
1604
0
  if (G_UNLIKELY (script < 0 || script >= (int) G_N_ELEMENTS (iso15924_tags)))
1605
0
    return 0x5A7A7A7A;
1606
1607
0
  return iso15924_tags[script];
1608
0
}
1609
1610
/**
1611
 * g_unicode_script_from_iso15924:
1612
 * @iso15924: a Unicode script
1613
 *
1614
 * Looks up the Unicode script for @iso15924.  ISO 15924 assigns four-letter
1615
 * codes to scripts.  For example, the code for Arabic is 'Arab'.
1616
 * This function accepts four letter codes encoded as a @guint32 in a
1617
 * big-endian fashion.  That is, the code expected for Arabic is
1618
 * 0x41726162 (0x41 is ASCII code for 'A', 0x72 is ASCII code for 'r', etc).
1619
 *
1620
 * See
1621
 * [Codes for the representation of names of scripts](http://unicode.org/iso15924/codelists.html)
1622
 * for details.
1623
 *
1624
 * Returns: the Unicode script for @iso15924, or
1625
 *   of %G_UNICODE_SCRIPT_INVALID_CODE if @iso15924 is zero and
1626
 *   %G_UNICODE_SCRIPT_UNKNOWN if @iso15924 is unknown.
1627
 *
1628
 * Since: 2.30
1629
 */
1630
GUnicodeScript
1631
g_unicode_script_from_iso15924 (guint32 iso15924)
1632
0
{
1633
0
  unsigned int i;
1634
1635
0
   if (!iso15924)
1636
0
     return G_UNICODE_SCRIPT_INVALID_CODE;
1637
1638
0
  for (i = 0; i < G_N_ELEMENTS (iso15924_tags); i++)
1639
0
    if (iso15924_tags[i] == iso15924)
1640
0
      return (GUnicodeScript) i;
1641
1642
0
  return G_UNICODE_SCRIPT_UNKNOWN;
1643
0
}