Blame glib/guniprop.c

Packit ae235b
/* guniprop.c - Unicode character properties.
Packit ae235b
 *
Packit ae235b
 * Copyright (C) 1999 Tom Tromey
Packit ae235b
 * Copyright (C) 2000 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public
Packit ae235b
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include <stdlib.h>
Packit ae235b
#include <stddef.h>
Packit ae235b
#include <string.h>
Packit ae235b
#include <locale.h>
Packit ae235b
Packit ae235b
#include "gmem.h"
Packit ae235b
#include "gstring.h"
Packit ae235b
#include "gtestutils.h"
Packit ae235b
#include "gtypes.h"
Packit ae235b
#include "gunicode.h"
Packit ae235b
#include "gunichartables.h"
Packit ae235b
#include "gmirroringtable.h"
Packit ae235b
#include "gscripttable.h"
Packit ae235b
#include "gunicodeprivate.h"
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
#include "gwin32.h"
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#define ATTR_TABLE(Page) (((Page) <= G_UNICODE_LAST_PAGE_PART1) \
Packit ae235b
                          ? attr_table_part1[Page] \
Packit ae235b
                          : attr_table_part2[(Page) - 0xe00])
Packit ae235b
Packit ae235b
#define ATTTABLE(Page, Char) \
Packit ae235b
  ((ATTR_TABLE(Page) == G_UNICODE_MAX_TABLE_INDEX) ? 0 : (attr_data[ATTR_TABLE(Page)][Char]))
Packit ae235b
Packit ae235b
#define TTYPE_PART1(Page, Char) \
Packit ae235b
  ((type_table_part1[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
Packit ae235b
   ? (type_table_part1[Page] - G_UNICODE_MAX_TABLE_INDEX) \
Packit ae235b
   : (type_data[type_table_part1[Page]][Char]))
Packit ae235b
Packit ae235b
#define TTYPE_PART2(Page, Char) \
Packit ae235b
  ((type_table_part2[Page] >= G_UNICODE_MAX_TABLE_INDEX) \
Packit ae235b
   ? (type_table_part2[Page] - G_UNICODE_MAX_TABLE_INDEX) \
Packit ae235b
   : (type_data[type_table_part2[Page]][Char]))
Packit ae235b
Packit ae235b
#define TYPE(Char) \
Packit ae235b
  (((Char) <= G_UNICODE_LAST_CHAR_PART1) \
Packit ae235b
   ? TTYPE_PART1 ((Char) >> 8, (Char) & 0xff) \
Packit ae235b
   : (((Char) >= 0xe0000 && (Char) <= G_UNICODE_LAST_CHAR) \
Packit ae235b
      ? TTYPE_PART2 (((Char) - 0xe0000) >> 8, (Char) & 0xff) \
Packit ae235b
      : G_UNICODE_UNASSIGNED))
Packit ae235b
Packit ae235b
Packit ae235b
#define IS(Type, Class)	(((guint)1 << (Type)) & (Class))
Packit ae235b
#define OR(Type, Rest)	(((guint)1 << (Type)) | (Rest))
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
#define ISALPHA(Type)	IS ((Type),				\
Packit ae235b
			    OR (G_UNICODE_LOWERCASE_LETTER,	\
Packit ae235b
			    OR (G_UNICODE_UPPERCASE_LETTER,	\
Packit ae235b
			    OR (G_UNICODE_TITLECASE_LETTER,	\
Packit ae235b
			    OR (G_UNICODE_MODIFIER_LETTER,	\
Packit ae235b
			    OR (G_UNICODE_OTHER_LETTER,		0))))))
Packit ae235b
Packit ae235b
#define ISALDIGIT(Type)	IS ((Type),				\
Packit ae235b
			    OR (G_UNICODE_DECIMAL_NUMBER,	\
Packit ae235b
			    OR (G_UNICODE_LETTER_NUMBER,	\
Packit ae235b
			    OR (G_UNICODE_OTHER_NUMBER,		\
Packit ae235b
			    OR (G_UNICODE_LOWERCASE_LETTER,	\
Packit ae235b
			    OR (G_UNICODE_UPPERCASE_LETTER,	\
Packit ae235b
			    OR (G_UNICODE_TITLECASE_LETTER,	\
Packit ae235b
			    OR (G_UNICODE_MODIFIER_LETTER,	\
Packit ae235b
			    OR (G_UNICODE_OTHER_LETTER,		0)))))))))
Packit ae235b
Packit ae235b
#define ISMARK(Type)	IS ((Type),				\
Packit ae235b
			    OR (G_UNICODE_NON_SPACING_MARK,	\
Packit ae235b
			    OR (G_UNICODE_SPACING_MARK,	\
Packit ae235b
			    OR (G_UNICODE_ENCLOSING_MARK,	0))))
Packit ae235b
Packit ae235b
#define ISZEROWIDTHTYPE(Type)	IS ((Type),			\
Packit ae235b
			    OR (G_UNICODE_NON_SPACING_MARK,	\
Packit ae235b
			    OR (G_UNICODE_ENCLOSING_MARK,	\
Packit ae235b
			    OR (G_UNICODE_FORMAT,		0))))
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_isalnum:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines whether a character is alphanumeric.
Packit ae235b
 * Given some UTF-8 text, obtain a character value
Packit ae235b
 * with g_utf8_get_char().
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @c is an alphanumeric character
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_isalnum (gunichar c)
Packit ae235b
{
Packit ae235b
  return ISALDIGIT (TYPE (c)) ? TRUE : FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_isalpha:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines whether a character is alphabetic (i.e. a letter).
Packit ae235b
 * Given some UTF-8 text, obtain a character value with
Packit ae235b
 * g_utf8_get_char().
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @c is an alphabetic character
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_isalpha (gunichar c)
Packit ae235b
{
Packit ae235b
  return ISALPHA (TYPE (c)) ? TRUE : FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_iscntrl:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines whether a character is a control character.
Packit ae235b
 * Given some UTF-8 text, obtain a character value with
Packit ae235b
 * g_utf8_get_char().
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @c is a control character
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_iscntrl (gunichar c)
Packit ae235b
{
Packit ae235b
  return TYPE (c) == G_UNICODE_CONTROL;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_isdigit:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines whether a character is numeric (i.e. a digit).  This
Packit ae235b
 * covers ASCII 0-9 and also digits in other languages/scripts.  Given
Packit ae235b
 * some UTF-8 text, obtain a character value with g_utf8_get_char().
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @c is a digit
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_isdigit (gunichar c)
Packit ae235b
{
Packit ae235b
  return TYPE (c) == G_UNICODE_DECIMAL_NUMBER;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_isgraph:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines whether a character is printable and not a space
Packit ae235b
 * (returns %FALSE for control characters, format characters, and
Packit ae235b
 * spaces). g_unichar_isprint() is similar, but returns %TRUE for
Packit ae235b
 * spaces. Given some UTF-8 text, obtain a character value with
Packit ae235b
 * g_utf8_get_char().
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @c is printable unless it's a space
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_isgraph (gunichar c)
Packit ae235b
{
Packit ae235b
  return !IS (TYPE(c),
Packit ae235b
	      OR (G_UNICODE_CONTROL,
Packit ae235b
	      OR (G_UNICODE_FORMAT,
Packit ae235b
	      OR (G_UNICODE_UNASSIGNED,
Packit ae235b
	      OR (G_UNICODE_SURROGATE,
Packit ae235b
	      OR (G_UNICODE_SPACE_SEPARATOR,
Packit ae235b
	     0))))));
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_islower:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines whether a character is a lowercase letter.
Packit ae235b
 * Given some UTF-8 text, obtain a character value with
Packit ae235b
 * g_utf8_get_char().
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @c is a lowercase letter
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_islower (gunichar c)
Packit ae235b
{
Packit ae235b
  return TYPE (c) == G_UNICODE_LOWERCASE_LETTER;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_isprint:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines whether a character is printable.
Packit ae235b
 * Unlike g_unichar_isgraph(), returns %TRUE for spaces.
Packit ae235b
 * Given some UTF-8 text, obtain a character value with
Packit ae235b
 * g_utf8_get_char().
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @c is printable
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_isprint (gunichar c)
Packit ae235b
{
Packit ae235b
  return !IS (TYPE(c),
Packit ae235b
	      OR (G_UNICODE_CONTROL,
Packit ae235b
	      OR (G_UNICODE_FORMAT,
Packit ae235b
	      OR (G_UNICODE_UNASSIGNED,
Packit ae235b
	      OR (G_UNICODE_SURROGATE,
Packit ae235b
	     0)))));
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_ispunct:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines whether a character is punctuation or a symbol.
Packit ae235b
 * Given some UTF-8 text, obtain a character value with
Packit ae235b
 * g_utf8_get_char().
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @c is a punctuation or symbol character
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_ispunct (gunichar c)
Packit ae235b
{
Packit ae235b
  return IS (TYPE(c),
Packit ae235b
	     OR (G_UNICODE_CONNECT_PUNCTUATION,
Packit ae235b
	     OR (G_UNICODE_DASH_PUNCTUATION,
Packit ae235b
	     OR (G_UNICODE_CLOSE_PUNCTUATION,
Packit ae235b
	     OR (G_UNICODE_FINAL_PUNCTUATION,
Packit ae235b
	     OR (G_UNICODE_INITIAL_PUNCTUATION,
Packit ae235b
	     OR (G_UNICODE_OTHER_PUNCTUATION,
Packit ae235b
	     OR (G_UNICODE_OPEN_PUNCTUATION,
Packit ae235b
	     OR (G_UNICODE_CURRENCY_SYMBOL,
Packit ae235b
	     OR (G_UNICODE_MODIFIER_SYMBOL,
Packit ae235b
	     OR (G_UNICODE_MATH_SYMBOL,
Packit ae235b
	     OR (G_UNICODE_OTHER_SYMBOL,
Packit ae235b
	    0)))))))))))) ? TRUE : FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_isspace:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines whether a character is a space, tab, or line separator
Packit ae235b
 * (newline, carriage return, etc.).  Given some UTF-8 text, obtain a
Packit ae235b
 * character value with g_utf8_get_char().
Packit ae235b
 *
Packit ae235b
 * (Note: don't use this to do word breaking; you have to use
Packit ae235b
 * Pango or equivalent to get word breaking right, the algorithm
Packit ae235b
 * is fairly complex.)
Packit ae235b
 *  
Packit ae235b
 * Returns: %TRUE if @c is a space character
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_isspace (gunichar c)
Packit ae235b
{
Packit ae235b
  switch (c)
Packit ae235b
    {
Packit ae235b
      /* special-case these since Unicode thinks they are not spaces */
Packit ae235b
    case '\t':
Packit ae235b
    case '\n':
Packit ae235b
    case '\r':
Packit ae235b
    case '\f':
Packit ae235b
      return TRUE;
Packit ae235b
      break;
Packit ae235b
      
Packit ae235b
    default:
Packit ae235b
      {
Packit ae235b
	return IS (TYPE(c),
Packit ae235b
	           OR (G_UNICODE_SPACE_SEPARATOR,
Packit ae235b
	           OR (G_UNICODE_LINE_SEPARATOR,
Packit ae235b
                   OR (G_UNICODE_PARAGRAPH_SEPARATOR,
Packit ae235b
		  0)))) ? TRUE : FALSE;
Packit ae235b
      }
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_ismark:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 *
Packit ae235b
 * Determines whether a character is a mark (non-spacing mark,
Packit ae235b
 * combining mark, or enclosing mark in Unicode speak).
Packit ae235b
 * Given some UTF-8 text, obtain a character value
Packit ae235b
 * with g_utf8_get_char().
Packit ae235b
 *
Packit ae235b
 * Note: in most cases where isalpha characters are allowed,
Packit ae235b
 * ismark characters should be allowed to as they are essential
Packit ae235b
 * for writing most European languages as well as many non-Latin
Packit ae235b
 * scripts.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @c is a mark character
Packit ae235b
 *
Packit ae235b
 * Since: 2.14
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_ismark (gunichar c)
Packit ae235b
{
Packit ae235b
  return ISMARK (TYPE (c));
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_isupper:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines if a character is uppercase.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if @c is an uppercase character
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_isupper (gunichar c)
Packit ae235b
{
Packit ae235b
  return TYPE (c) == G_UNICODE_UPPERCASE_LETTER;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_istitle:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines if a character is titlecase. Some characters in
Packit ae235b
 * Unicode which are composites, such as the DZ digraph
Packit ae235b
 * have three case variants instead of just two. The titlecase
Packit ae235b
 * form is used at the beginning of a word where only the
Packit ae235b
 * first letter is capitalized. The titlecase form of the DZ
Packit ae235b
 * digraph is U+01F2 LATIN CAPITAL LETTTER D WITH SMALL LETTER Z.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the character is titlecase
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_istitle (gunichar c)
Packit ae235b
{
Packit ae235b
  unsigned int i;
Packit ae235b
  for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
Packit ae235b
    if (title_table[i][0] == c)
Packit ae235b
      return TRUE;
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_isxdigit:
Packit ae235b
 * @c: a Unicode character.
Packit ae235b
 * 
Packit ae235b
 * Determines if a character is a hexidecimal digit.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the character is a hexadecimal digit
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_isxdigit (gunichar c)
Packit ae235b
{
Packit ae235b
  return ((c >= 'a' && c <= 'f')
Packit ae235b
	  || (c >= 'A' && c <= 'F')
Packit ae235b
	  || (TYPE (c) == G_UNICODE_DECIMAL_NUMBER));
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_isdefined:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines if a given character is assigned in the Unicode
Packit ae235b
 * standard.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the character has an assigned value
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_isdefined (gunichar c)
Packit ae235b
{
Packit ae235b
  return !IS (TYPE(c),
Packit ae235b
	      OR (G_UNICODE_UNASSIGNED,
Packit ae235b
	      OR (G_UNICODE_SURROGATE,
Packit ae235b
	     0)));
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_iszerowidth:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines if a given character typically takes zero width when rendered.
Packit ae235b
 * The return value is %TRUE for all non-spacing and enclosing marks
Packit ae235b
 * (e.g., combining accents), format characters, zero-width
Packit ae235b
 * space, but not U+00AD SOFT HYPHEN.
Packit ae235b
 *
Packit ae235b
 * A typical use of this function is with one of g_unichar_iswide() or
Packit ae235b
 * g_unichar_iswide_cjk() to determine the number of cells a string occupies
Packit ae235b
 * when displayed on a grid display (terminals).  However, note that not all
Packit ae235b
 * terminals support zero-width rendering of zero-width marks.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the character has zero width
Packit ae235b
 *
Packit ae235b
 * Since: 2.14
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_iszerowidth (gunichar c)
Packit ae235b
{
Packit ae235b
  if (G_UNLIKELY (c == 0x00AD))
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  if (G_UNLIKELY (ISZEROWIDTHTYPE (TYPE (c))))
Packit ae235b
    return TRUE;
Packit ae235b
Packit ae235b
  if (G_UNLIKELY ((c >= 0x1160 && c < 0x1200) ||
Packit ae235b
		  c == 0x200B))
Packit ae235b
    return TRUE;
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
static int
Packit ae235b
interval_compare (const void *key, const void *elt)
Packit ae235b
{
Packit ae235b
  gunichar c = GPOINTER_TO_UINT (key);
Packit ae235b
  struct Interval *interval = (struct Interval *)elt;
Packit ae235b
Packit ae235b
  if (c < interval->start)
Packit ae235b
    return -1;
Packit ae235b
  if (c > interval->end)
Packit ae235b
    return +1;
Packit ae235b
Packit ae235b
  return 0;
Packit ae235b
}
Packit ae235b
Packit ae235b
#define G_WIDTH_TABLE_MIDPOINT (G_N_ELEMENTS (g_unicode_width_table_wide) / 2)
Packit ae235b
Packit ae235b
static inline gboolean
Packit ae235b
g_unichar_iswide_bsearch (gunichar ch)
Packit ae235b
{
Packit ae235b
  int lower = 0;
Packit ae235b
  int upper = G_N_ELEMENTS (g_unicode_width_table_wide) - 1;
Packit ae235b
  static int saved_mid = G_WIDTH_TABLE_MIDPOINT;
Packit ae235b
  int mid = saved_mid;
Packit ae235b
Packit ae235b
  do
Packit ae235b
    {
Packit ae235b
      if (ch < g_unicode_width_table_wide[mid].start)
Packit ae235b
	upper = mid - 1;
Packit ae235b
      else if (ch > g_unicode_width_table_wide[mid].end)
Packit ae235b
	lower = mid + 1;
Packit ae235b
      else
Packit ae235b
	return TRUE;
Packit ae235b
Packit ae235b
      mid = (lower + upper) / 2;
Packit ae235b
    }
Packit ae235b
  while (lower <= upper);
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_iswide:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines if a character is typically rendered in a double-width
Packit ae235b
 * cell.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the character is wide
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_iswide (gunichar c)
Packit ae235b
{
Packit ae235b
  if (c < g_unicode_width_table_wide[0].start)
Packit ae235b
    return FALSE;
Packit ae235b
  else
Packit ae235b
    return g_unichar_iswide_bsearch (c);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_iswide_cjk:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Determines if a character is typically rendered in a double-width
Packit ae235b
 * cell under legacy East Asian locales.  If a character is wide according to
Packit ae235b
 * g_unichar_iswide(), then it is also reported wide with this function, but
Packit ae235b
 * the converse is not necessarily true. See the
Packit ae235b
 * [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
Packit ae235b
 * for details.
Packit ae235b
 *
Packit ae235b
 * If a character passes the g_unichar_iswide() test then it will also pass
Packit ae235b
 * this test, but not the other way around.  Note that some characters may
Packit ae235b
 * pass both this test and g_unichar_iszerowidth().
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the character is wide in legacy East Asian locales
Packit ae235b
 *
Packit ae235b
 * Since: 2.12
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_unichar_iswide_cjk (gunichar c)
Packit ae235b
{
Packit ae235b
  if (g_unichar_iswide (c))
Packit ae235b
    return TRUE;
Packit ae235b
Packit ae235b
  /* bsearch() is declared attribute(nonnull(1)) so we can't validly search
Packit ae235b
   * for a NULL key */
Packit ae235b
  if (c == 0)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  if (bsearch (GUINT_TO_POINTER (c), 
Packit ae235b
               g_unicode_width_table_ambiguous,
Packit ae235b
               G_N_ELEMENTS (g_unicode_width_table_ambiguous),
Packit ae235b
               sizeof g_unicode_width_table_ambiguous[0],
Packit ae235b
	       interval_compare))
Packit ae235b
    return TRUE;
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_toupper:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Converts a character to uppercase.
Packit ae235b
 * 
Packit ae235b
 * Returns: the result of converting @c to uppercase.
Packit ae235b
 *               If @c is not an lowercase or titlecase character,
Packit ae235b
 *               or has no upper case equivalent @c is returned unchanged.
Packit ae235b
 **/
Packit ae235b
gunichar
Packit ae235b
g_unichar_toupper (gunichar c)
Packit ae235b
{
Packit ae235b
  int t = TYPE (c);
Packit ae235b
  if (t == G_UNICODE_LOWERCASE_LETTER)
Packit ae235b
    {
Packit ae235b
      gunichar val = ATTTABLE (c >> 8, c & 0xff);
Packit ae235b
      if (val >= 0x1000000)
Packit ae235b
	{
Packit ae235b
	  const gchar *p = special_case_table + val - 0x1000000;
Packit ae235b
          val = g_utf8_get_char (p);
Packit ae235b
	}
Packit ae235b
      /* Some lowercase letters, e.g., U+000AA, FEMININE ORDINAL INDICATOR,
Packit ae235b
       * do not have an uppercase equivalent, in which case val will be
Packit ae235b
       * zero. 
Packit ae235b
       */
Packit ae235b
      return val ? val : c;
Packit ae235b
    }
Packit ae235b
  else if (t == G_UNICODE_TITLECASE_LETTER)
Packit ae235b
    {
Packit ae235b
      unsigned int i;
Packit ae235b
      for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
Packit ae235b
	{
Packit ae235b
	  if (title_table[i][0] == c)
Packit ae235b
	    return title_table[i][1] ? title_table[i][1] : c;
Packit ae235b
	}
Packit ae235b
    }
Packit ae235b
  return c;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_tolower:
Packit ae235b
 * @c: a Unicode character.
Packit ae235b
 * 
Packit ae235b
 * Converts a character to lower case.
Packit ae235b
 * 
Packit ae235b
 * Returns: the result of converting @c to lower case.
Packit ae235b
 *               If @c is not an upperlower or titlecase character,
Packit ae235b
 *               or has no lowercase equivalent @c is returned unchanged.
Packit ae235b
 **/
Packit ae235b
gunichar
Packit ae235b
g_unichar_tolower (gunichar c)
Packit ae235b
{
Packit ae235b
  int t = TYPE (c);
Packit ae235b
  if (t == G_UNICODE_UPPERCASE_LETTER)
Packit ae235b
    {
Packit ae235b
      gunichar val = ATTTABLE (c >> 8, c & 0xff);
Packit ae235b
      if (val >= 0x1000000)
Packit ae235b
	{
Packit ae235b
	  const gchar *p = special_case_table + val - 0x1000000;
Packit ae235b
	  return g_utf8_get_char (p);
Packit ae235b
	}
Packit ae235b
      else
Packit ae235b
	{
Packit ae235b
	  /* Not all uppercase letters are guaranteed to have a lowercase
Packit ae235b
	   * equivalent.  If this is the case, val will be zero. */
Packit ae235b
	  return val ? val : c;
Packit ae235b
	}
Packit ae235b
    }
Packit ae235b
  else if (t == G_UNICODE_TITLECASE_LETTER)
Packit ae235b
    {
Packit ae235b
      unsigned int i;
Packit ae235b
      for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
Packit ae235b
	{
Packit ae235b
	  if (title_table[i][0] == c)
Packit ae235b
	    return title_table[i][2];
Packit ae235b
	}
Packit ae235b
    }
Packit ae235b
  return c;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_totitle:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Converts a character to the titlecase.
Packit ae235b
 * 
Packit ae235b
 * Returns: the result of converting @c to titlecase.
Packit ae235b
 *               If @c is not an uppercase or lowercase character,
Packit ae235b
 *               @c is returned unchanged.
Packit ae235b
 **/
Packit ae235b
gunichar
Packit ae235b
g_unichar_totitle (gunichar c)
Packit ae235b
{
Packit ae235b
  unsigned int i;
Packit ae235b
  for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
Packit ae235b
    {
Packit ae235b
      if (title_table[i][0] == c || title_table[i][1] == c
Packit ae235b
	  || title_table[i][2] == c)
Packit ae235b
	return title_table[i][0];
Packit ae235b
    }
Packit ae235b
    
Packit ae235b
  if (TYPE (c) == G_UNICODE_LOWERCASE_LETTER)
Packit ae235b
    return g_unichar_toupper (c);
Packit ae235b
Packit ae235b
  return c;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_digit_value:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 *
Packit ae235b
 * Determines the numeric value of a character as a decimal
Packit ae235b
 * digit.
Packit ae235b
 *
Packit ae235b
 * Returns: If @c is a decimal digit (according to
Packit ae235b
 * g_unichar_isdigit()), its numeric value. Otherwise, -1.
Packit ae235b
 **/
Packit ae235b
int
Packit ae235b
g_unichar_digit_value (gunichar c)
Packit ae235b
{
Packit ae235b
  if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
Packit ae235b
    return ATTTABLE (c >> 8, c & 0xff);
Packit ae235b
  return -1;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_xdigit_value:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 *
Packit ae235b
 * Determines the numeric value of a character as a hexidecimal
Packit ae235b
 * digit.
Packit ae235b
 *
Packit ae235b
 * Returns: If @c is a hex digit (according to
Packit ae235b
 * g_unichar_isxdigit()), its numeric value. Otherwise, -1.
Packit ae235b
 **/
Packit ae235b
int
Packit ae235b
g_unichar_xdigit_value (gunichar c)
Packit ae235b
{
Packit ae235b
  if (c >= 'A' && c <= 'F')
Packit ae235b
    return c - 'A' + 10;
Packit ae235b
  if (c >= 'a' && c <= 'f')
Packit ae235b
    return c - 'a' + 10;
Packit ae235b
  if (TYPE (c) == G_UNICODE_DECIMAL_NUMBER)
Packit ae235b
    return ATTTABLE (c >> 8, c & 0xff);
Packit ae235b
  return -1;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_type:
Packit ae235b
 * @c: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Classifies a Unicode character by type.
Packit ae235b
 * 
Packit ae235b
 * Returns: the type of the character.
Packit ae235b
 **/
Packit ae235b
GUnicodeType
Packit ae235b
g_unichar_type (gunichar c)
Packit ae235b
{
Packit ae235b
  return TYPE (c);
Packit ae235b
}
Packit ae235b
Packit ae235b
/*
Packit ae235b
 * Case mapping functions
Packit ae235b
 */
Packit ae235b
Packit ae235b
typedef enum {
Packit ae235b
  LOCALE_NORMAL,
Packit ae235b
  LOCALE_TURKIC,
Packit ae235b
  LOCALE_LITHUANIAN
Packit ae235b
} LocaleType;
Packit ae235b
Packit ae235b
static LocaleType
Packit ae235b
get_locale_type (void)
Packit ae235b
{
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
  char *tem = g_win32_getlocale ();
Packit ae235b
  char locale[2];
Packit ae235b
Packit ae235b
  locale[0] = tem[0];
Packit ae235b
  locale[1] = tem[1];
Packit ae235b
  g_free (tem);
Packit ae235b
#else
Packit ae235b
  const char *locale = setlocale (LC_CTYPE, NULL);
Packit ae235b
Packit ae235b
  if (locale == NULL)
Packit ae235b
    return LOCALE_NORMAL;
Packit ae235b
#endif
Packit ae235b
Packit ae235b
  switch (locale[0])
Packit ae235b
    {
Packit ae235b
   case 'a':
Packit ae235b
      if (locale[1] == 'z')
Packit ae235b
	return LOCALE_TURKIC;
Packit ae235b
      break;
Packit ae235b
    case 'l':
Packit ae235b
      if (locale[1] == 't')
Packit ae235b
	return LOCALE_LITHUANIAN;
Packit ae235b
      break;
Packit ae235b
    case 't':
Packit ae235b
      if (locale[1] == 'r')
Packit ae235b
	return LOCALE_TURKIC;
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return LOCALE_NORMAL;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gint
Packit ae235b
output_marks (const char **p_inout,
Packit ae235b
	      char        *out_buffer,
Packit ae235b
	      gboolean     remove_dot)
Packit ae235b
{
Packit ae235b
  const char *p = *p_inout;
Packit ae235b
  gint len = 0;
Packit ae235b
  
Packit ae235b
  while (*p)
Packit ae235b
    {
Packit ae235b
      gunichar c = g_utf8_get_char (p);
Packit ae235b
      
Packit ae235b
      if (ISMARK (TYPE (c)))
Packit ae235b
	{
Packit ae235b
	  if (!remove_dot || c != 0x307 /* COMBINING DOT ABOVE */)
Packit ae235b
	    len += g_unichar_to_utf8 (c, out_buffer ? out_buffer + len : NULL);
Packit ae235b
	  p = g_utf8_next_char (p);
Packit ae235b
	}
Packit ae235b
      else
Packit ae235b
	break;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  *p_inout = p;
Packit ae235b
  return len;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gint
Packit ae235b
output_special_case (gchar *out_buffer,
Packit ae235b
		     int    offset,
Packit ae235b
		     int    type,
Packit ae235b
		     int    which)
Packit ae235b
{
Packit ae235b
  const gchar *p = special_case_table + offset;
Packit ae235b
  gint len;
Packit ae235b
Packit ae235b
  if (type != G_UNICODE_TITLECASE_LETTER)
Packit ae235b
    p = g_utf8_next_char (p);
Packit ae235b
Packit ae235b
  if (which == 1)
Packit ae235b
    p += strlen (p) + 1;
Packit ae235b
Packit ae235b
  len = strlen (p);
Packit ae235b
  if (out_buffer)
Packit ae235b
    memcpy (out_buffer, p, len);
Packit ae235b
Packit ae235b
  return len;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gsize
Packit ae235b
real_toupper (const gchar *str,
Packit ae235b
	      gssize       max_len,
Packit ae235b
	      gchar       *out_buffer,
Packit ae235b
	      LocaleType   locale_type)
Packit ae235b
{
Packit ae235b
  const gchar *p = str;
Packit ae235b
  const char *last = NULL;
Packit ae235b
  gsize len = 0;
Packit ae235b
  gboolean last_was_i = FALSE;
Packit ae235b
Packit ae235b
  while ((max_len < 0 || p < str + max_len) && *p)
Packit ae235b
    {
Packit ae235b
      gunichar c = g_utf8_get_char (p);
Packit ae235b
      int t = TYPE (c);
Packit ae235b
      gunichar val;
Packit ae235b
Packit ae235b
      last = p;
Packit ae235b
      p = g_utf8_next_char (p);
Packit ae235b
Packit ae235b
      if (locale_type == LOCALE_LITHUANIAN)
Packit ae235b
	{
Packit ae235b
	  if (c == 'i')
Packit ae235b
	    last_was_i = TRUE;
Packit ae235b
	  else 
Packit ae235b
	    {
Packit ae235b
	      if (last_was_i)
Packit ae235b
		{
Packit ae235b
		  /* Nasty, need to remove any dot above. Though
Packit ae235b
		   * I think only E WITH DOT ABOVE occurs in practice
Packit ae235b
		   * which could simplify this considerably.
Packit ae235b
		   */
Packit ae235b
		  gsize decomp_len, i;
Packit ae235b
		  gunichar decomp[G_UNICHAR_MAX_DECOMPOSITION_LENGTH];
Packit ae235b
Packit ae235b
		  decomp_len = g_unichar_fully_decompose (c, FALSE, decomp, G_N_ELEMENTS (decomp));
Packit ae235b
		  for (i=0; i < decomp_len; i++)
Packit ae235b
		    {
Packit ae235b
		      if (decomp[i] != 0x307 /* COMBINING DOT ABOVE */)
Packit ae235b
			len += g_unichar_to_utf8 (g_unichar_toupper (decomp[i]), out_buffer ? out_buffer + len : NULL);
Packit ae235b
		    }
Packit ae235b
		  
Packit ae235b
		  len += output_marks (&p, out_buffer ? out_buffer + len : NULL, TRUE);
Packit ae235b
Packit ae235b
		  continue;
Packit ae235b
		}
Packit ae235b
Packit ae235b
	      if (!ISMARK (t))
Packit ae235b
		last_was_i = FALSE;
Packit ae235b
	    }
Packit ae235b
	}
Packit ae235b
Packit ae235b
      if (locale_type == LOCALE_TURKIC && c == 'i')
Packit ae235b
	{
Packit ae235b
	  /* i => LATIN CAPITAL LETTER I WITH DOT ABOVE */
Packit ae235b
	  len += g_unichar_to_utf8 (0x130, out_buffer ? out_buffer + len : NULL); 
Packit ae235b
	}
Packit ae235b
      else if (c == 0x0345)	/* COMBINING GREEK YPOGEGRAMMENI */
Packit ae235b
	{
Packit ae235b
	  /* Nasty, need to move it after other combining marks .. this would go away if
Packit ae235b
	   * we normalized first.
Packit ae235b
	   */
Packit ae235b
	  len += output_marks (&p, out_buffer ? out_buffer + len : NULL, FALSE);
Packit ae235b
Packit ae235b
	  /* And output as GREEK CAPITAL LETTER IOTA */
Packit ae235b
	  len += g_unichar_to_utf8 (0x399, out_buffer ? out_buffer + len : NULL); 	  
Packit ae235b
	}
Packit ae235b
      else if (IS (t,
Packit ae235b
		   OR (G_UNICODE_LOWERCASE_LETTER,
Packit ae235b
		   OR (G_UNICODE_TITLECASE_LETTER,
Packit ae235b
		  0))))
Packit ae235b
	{
Packit ae235b
	  val = ATTTABLE (c >> 8, c & 0xff);
Packit ae235b
Packit ae235b
	  if (val >= 0x1000000)
Packit ae235b
	    {
Packit ae235b
	      len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t,
Packit ae235b
					  t == G_UNICODE_LOWERCASE_LETTER ? 0 : 1);
Packit ae235b
	    }
Packit ae235b
	  else
Packit ae235b
	    {
Packit ae235b
	      if (t == G_UNICODE_TITLECASE_LETTER)
Packit ae235b
		{
Packit ae235b
		  unsigned int i;
Packit ae235b
		  for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
Packit ae235b
		    {
Packit ae235b
		      if (title_table[i][0] == c)
Packit ae235b
			{
Packit ae235b
			  val = title_table[i][1];
Packit ae235b
			  break;
Packit ae235b
			}
Packit ae235b
		    }
Packit ae235b
		}
Packit ae235b
Packit ae235b
	      /* Some lowercase letters, e.g., U+000AA, FEMININE ORDINAL INDICATOR,
Packit ae235b
	       * do not have an uppercase equivalent, in which case val will be
Packit ae235b
	       * zero. */
Packit ae235b
	      len += g_unichar_to_utf8 (val ? val : c, out_buffer ? out_buffer + len : NULL);
Packit ae235b
	    }
Packit ae235b
	}
Packit ae235b
      else
Packit ae235b
	{
Packit ae235b
	  gsize char_len = g_utf8_skip[*(guchar *)last];
Packit ae235b
Packit ae235b
	  if (out_buffer)
Packit ae235b
	    memcpy (out_buffer + len, last, char_len);
Packit ae235b
Packit ae235b
	  len += char_len;
Packit ae235b
	}
Packit ae235b
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return len;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_utf8_strup:
Packit ae235b
 * @str: a UTF-8 encoded string
Packit ae235b
 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
Packit ae235b
 * 
Packit ae235b
 * Converts all Unicode characters in the string that have a case
Packit ae235b
 * to uppercase. The exact manner that this is done depends
Packit ae235b
 * on the current locale, and may result in the number of
Packit ae235b
 * characters in the string increasing. (For instance, the
Packit ae235b
 * German ess-zet will be changed to SS.)
Packit ae235b
 * 
Packit ae235b
 * Returns: a newly allocated string, with all characters
Packit ae235b
 *    converted to uppercase.  
Packit ae235b
 **/
Packit ae235b
gchar *
Packit ae235b
g_utf8_strup (const gchar *str,
Packit ae235b
	      gssize       len)
Packit ae235b
{
Packit ae235b
  gsize result_len;
Packit ae235b
  LocaleType locale_type;
Packit ae235b
  gchar *result;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (str != NULL, NULL);
Packit ae235b
Packit ae235b
  locale_type = get_locale_type ();
Packit ae235b
  
Packit ae235b
  /*
Packit ae235b
   * We use a two pass approach to keep memory management simple
Packit ae235b
   */
Packit ae235b
  result_len = real_toupper (str, len, NULL, locale_type);
Packit ae235b
  result = g_malloc (result_len + 1);
Packit ae235b
  real_toupper (str, len, result, locale_type);
Packit ae235b
  result[result_len] = '\0';
Packit ae235b
Packit ae235b
  return result;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* traverses the string checking for characters with combining class == 230
Packit ae235b
 * until a base character is found */
Packit ae235b
static gboolean
Packit ae235b
has_more_above (const gchar *str)
Packit ae235b
{
Packit ae235b
  const gchar *p = str;
Packit ae235b
  gint combining_class;
Packit ae235b
Packit ae235b
  while (*p)
Packit ae235b
    {
Packit ae235b
      combining_class = g_unichar_combining_class (g_utf8_get_char (p));
Packit ae235b
      if (combining_class == 230)
Packit ae235b
        return TRUE;
Packit ae235b
      else if (combining_class == 0)
Packit ae235b
        break;
Packit ae235b
Packit ae235b
      p = g_utf8_next_char (p);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gsize
Packit ae235b
real_tolower (const gchar *str,
Packit ae235b
	      gssize       max_len,
Packit ae235b
	      gchar       *out_buffer,
Packit ae235b
	      LocaleType   locale_type)
Packit ae235b
{
Packit ae235b
  const gchar *p = str;
Packit ae235b
  const char *last = NULL;
Packit ae235b
  gsize len = 0;
Packit ae235b
Packit ae235b
  while ((max_len < 0 || p < str + max_len) && *p)
Packit ae235b
    {
Packit ae235b
      gunichar c = g_utf8_get_char (p);
Packit ae235b
      int t = TYPE (c);
Packit ae235b
      gunichar val;
Packit ae235b
Packit ae235b
      last = p;
Packit ae235b
      p = g_utf8_next_char (p);
Packit ae235b
Packit ae235b
      if (locale_type == LOCALE_TURKIC && c == 'I')
Packit ae235b
	{
Packit ae235b
          if (g_utf8_get_char (p) == 0x0307)
Packit ae235b
            {
Packit ae235b
              /* I + COMBINING DOT ABOVE => i (U+0069) */
Packit ae235b
              len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL); 
Packit ae235b
              p = g_utf8_next_char (p);
Packit ae235b
            }
Packit ae235b
          else
Packit ae235b
            {
Packit ae235b
              /* I => LATIN SMALL LETTER DOTLESS I */
Packit ae235b
              len += g_unichar_to_utf8 (0x131, out_buffer ? out_buffer + len : NULL); 
Packit ae235b
            }
Packit ae235b
        }
Packit ae235b
      /* Introduce an explicit dot above when lowercasing capital I's and J's
Packit ae235b
       * whenever there are more accents above. [SpecialCasing.txt] */
Packit ae235b
      else if (locale_type == LOCALE_LITHUANIAN && 
Packit ae235b
               (c == 0x00cc || c == 0x00cd || c == 0x0128))
Packit ae235b
        {
Packit ae235b
          len += g_unichar_to_utf8 (0x0069, out_buffer ? out_buffer + len : NULL); 
Packit ae235b
          len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL); 
Packit ae235b
Packit ae235b
          switch (c)
Packit ae235b
            {
Packit ae235b
            case 0x00cc: 
Packit ae235b
              len += g_unichar_to_utf8 (0x0300, out_buffer ? out_buffer + len : NULL); 
Packit ae235b
              break;
Packit ae235b
            case 0x00cd: 
Packit ae235b
              len += g_unichar_to_utf8 (0x0301, out_buffer ? out_buffer + len : NULL); 
Packit ae235b
              break;
Packit ae235b
            case 0x0128: 
Packit ae235b
              len += g_unichar_to_utf8 (0x0303, out_buffer ? out_buffer + len : NULL); 
Packit ae235b
              break;
Packit ae235b
            }
Packit ae235b
        }
Packit ae235b
      else if (locale_type == LOCALE_LITHUANIAN && 
Packit ae235b
               (c == 'I' || c == 'J' || c == 0x012e) && 
Packit ae235b
               has_more_above (p))
Packit ae235b
        {
Packit ae235b
          len += g_unichar_to_utf8 (g_unichar_tolower (c), out_buffer ? out_buffer + len : NULL); 
Packit ae235b
          len += g_unichar_to_utf8 (0x0307, out_buffer ? out_buffer + len : NULL); 
Packit ae235b
        }
Packit ae235b
      else if (c == 0x03A3)	/* GREEK CAPITAL LETTER SIGMA */
Packit ae235b
	{
Packit ae235b
	  if ((max_len < 0 || p < str + max_len) && *p)
Packit ae235b
	    {
Packit ae235b
	      gunichar next_c = g_utf8_get_char (p);
Packit ae235b
	      int next_type = TYPE(next_c);
Packit ae235b
Packit ae235b
	      /* SIGMA mapps differently depending on whether it is
Packit ae235b
	       * final or not. The following simplified test would
Packit ae235b
	       * fail in the case of combining marks following the
Packit ae235b
	       * sigma, but I don't think that occurs in real text.
Packit ae235b
	       * The test here matches that in ICU.
Packit ae235b
	       */
Packit ae235b
	      if (ISALPHA (next_type)) /* Lu,Ll,Lt,Lm,Lo */
Packit ae235b
		val = 0x3c3;	/* GREEK SMALL SIGMA */
Packit ae235b
	      else
Packit ae235b
		val = 0x3c2;	/* GREEK SMALL FINAL SIGMA */
Packit ae235b
	    }
Packit ae235b
	  else
Packit ae235b
	    val = 0x3c2;	/* GREEK SMALL FINAL SIGMA */
Packit ae235b
Packit ae235b
	  len += g_unichar_to_utf8 (val, out_buffer ? out_buffer + len : NULL);
Packit ae235b
	}
Packit ae235b
      else if (IS (t,
Packit ae235b
		   OR (G_UNICODE_UPPERCASE_LETTER,
Packit ae235b
		   OR (G_UNICODE_TITLECASE_LETTER,
Packit ae235b
		  0))))
Packit ae235b
	{
Packit ae235b
	  val = ATTTABLE (c >> 8, c & 0xff);
Packit ae235b
Packit ae235b
	  if (val >= 0x1000000)
Packit ae235b
	    {
Packit ae235b
	      len += output_special_case (out_buffer ? out_buffer + len : NULL, val - 0x1000000, t, 0);
Packit ae235b
	    }
Packit ae235b
	  else
Packit ae235b
	    {
Packit ae235b
	      if (t == G_UNICODE_TITLECASE_LETTER)
Packit ae235b
		{
Packit ae235b
		  unsigned int i;
Packit ae235b
		  for (i = 0; i < G_N_ELEMENTS (title_table); ++i)
Packit ae235b
		    {
Packit ae235b
		      if (title_table[i][0] == c)
Packit ae235b
			{
Packit ae235b
			  val = title_table[i][2];
Packit ae235b
			  break;
Packit ae235b
			}
Packit ae235b
		    }
Packit ae235b
		}
Packit ae235b
Packit ae235b
	      /* Not all uppercase letters are guaranteed to have a lowercase
Packit ae235b
	       * equivalent.  If this is the case, val will be zero. */
Packit ae235b
	      len += g_unichar_to_utf8 (val ? val : c, out_buffer ? out_buffer + len : NULL);
Packit ae235b
	    }
Packit ae235b
	}
Packit ae235b
      else
Packit ae235b
	{
Packit ae235b
	  gsize char_len = g_utf8_skip[*(guchar *)last];
Packit ae235b
Packit ae235b
	  if (out_buffer)
Packit ae235b
	    memcpy (out_buffer + len, last, char_len);
Packit ae235b
Packit ae235b
	  len += char_len;
Packit ae235b
	}
Packit ae235b
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return len;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_utf8_strdown:
Packit ae235b
 * @str: a UTF-8 encoded string
Packit ae235b
 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
Packit ae235b
 * 
Packit ae235b
 * Converts all Unicode characters in the string that have a case
Packit ae235b
 * to lowercase. The exact manner that this is done depends
Packit ae235b
 * on the current locale, and may result in the number of
Packit ae235b
 * characters in the string changing.
Packit ae235b
 * 
Packit ae235b
 * Returns: a newly allocated string, with all characters
Packit ae235b
 *    converted to lowercase.  
Packit ae235b
 **/
Packit ae235b
gchar *
Packit ae235b
g_utf8_strdown (const gchar *str,
Packit ae235b
		gssize       len)
Packit ae235b
{
Packit ae235b
  gsize result_len;
Packit ae235b
  LocaleType locale_type;
Packit ae235b
  gchar *result;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (str != NULL, NULL);
Packit ae235b
Packit ae235b
  locale_type = get_locale_type ();
Packit ae235b
  
Packit ae235b
  /*
Packit ae235b
   * We use a two pass approach to keep memory management simple
Packit ae235b
   */
Packit ae235b
  result_len = real_tolower (str, len, NULL, locale_type);
Packit ae235b
  result = g_malloc (result_len + 1);
Packit ae235b
  real_tolower (str, len, result, locale_type);
Packit ae235b
  result[result_len] = '\0';
Packit ae235b
Packit ae235b
  return result;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_utf8_casefold:
Packit ae235b
 * @str: a UTF-8 encoded string
Packit ae235b
 * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
Packit ae235b
 * 
Packit ae235b
 * Converts a string into a form that is independent of case. The
Packit ae235b
 * result will not correspond to any particular case, but can be
Packit ae235b
 * compared for equality or ordered with the results of calling
Packit ae235b
 * g_utf8_casefold() on other strings.
Packit ae235b
 * 
Packit ae235b
 * Note that calling g_utf8_casefold() followed by g_utf8_collate() is
Packit ae235b
 * only an approximation to the correct linguistic case insensitive
Packit ae235b
 * ordering, though it is a fairly good one. Getting this exactly
Packit ae235b
 * right would require a more sophisticated collation function that
Packit ae235b
 * takes case sensitivity into account. GLib does not currently
Packit ae235b
 * provide such a function.
Packit ae235b
 * 
Packit ae235b
 * Returns: a newly allocated string, that is a
Packit ae235b
 *   case independent form of @str.
Packit ae235b
 **/
Packit ae235b
gchar *
Packit ae235b
g_utf8_casefold (const gchar *str,
Packit ae235b
		 gssize       len)
Packit ae235b
{
Packit ae235b
  GString *result;
Packit ae235b
  const char *p;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (str != NULL, NULL);
Packit ae235b
Packit ae235b
  result = g_string_new (NULL);
Packit ae235b
  p = str;
Packit ae235b
  while ((len < 0 || p < str + len) && *p)
Packit ae235b
    {
Packit ae235b
      gunichar ch = g_utf8_get_char (p);
Packit ae235b
Packit ae235b
      int start = 0;
Packit ae235b
      int end = G_N_ELEMENTS (casefold_table);
Packit ae235b
Packit ae235b
      if (ch >= casefold_table[start].ch &&
Packit ae235b
          ch <= casefold_table[end - 1].ch)
Packit ae235b
	{
Packit ae235b
	  while (TRUE)
Packit ae235b
	    {
Packit ae235b
	      int half = (start + end) / 2;
Packit ae235b
	      if (ch == casefold_table[half].ch)
Packit ae235b
		{
Packit ae235b
		  g_string_append (result, casefold_table[half].data);
Packit ae235b
		  goto next;
Packit ae235b
		}
Packit ae235b
	      else if (half == start)
Packit ae235b
		break;
Packit ae235b
	      else if (ch > casefold_table[half].ch)
Packit ae235b
		start = half;
Packit ae235b
	      else
Packit ae235b
		end = half;
Packit ae235b
	    }
Packit ae235b
	}
Packit ae235b
Packit ae235b
      g_string_append_unichar (result, g_unichar_tolower (ch));
Packit ae235b
      
Packit ae235b
    next:
Packit ae235b
      p = g_utf8_next_char (p);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return g_string_free (result, FALSE); 
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_get_mirror_char:
Packit ae235b
 * @ch: a Unicode character
Packit ae235b
 * @mirrored_ch: location to store the mirrored character
Packit ae235b
 * 
Packit ae235b
 * In Unicode, some characters are "mirrored". This means that their
Packit ae235b
 * images are mirrored horizontally in text that is laid out from right
Packit ae235b
 * to left. For instance, "(" would become its mirror image, ")", in
Packit ae235b
 * right-to-left text.
Packit ae235b
 *
Packit ae235b
 * If @ch has the Unicode mirrored property and there is another unicode
Packit ae235b
 * character that typically has a glyph that is the mirror image of @ch's
Packit ae235b
 * glyph and @mirrored_ch is set, it puts that character in the address
Packit ae235b
 * pointed to by @mirrored_ch.  Otherwise the original character is put.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @ch has a mirrored character, %FALSE otherwise
Packit ae235b
 *
Packit ae235b
 * Since: 2.4
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_unichar_get_mirror_char (gunichar ch,
Packit ae235b
                           gunichar *mirrored_ch)
Packit ae235b
{
Packit ae235b
  gboolean found;
Packit ae235b
  gunichar mirrored;
Packit ae235b
Packit ae235b
  mirrored = GLIB_GET_MIRRORING(ch);
Packit ae235b
Packit ae235b
  found = ch != mirrored;
Packit ae235b
  if (mirrored_ch)
Packit ae235b
    *mirrored_ch = mirrored;
Packit ae235b
Packit ae235b
  return found;
Packit ae235b
Packit ae235b
}
Packit ae235b
Packit ae235b
#define G_SCRIPT_TABLE_MIDPOINT (G_N_ELEMENTS (g_script_table) / 2)
Packit ae235b
Packit ae235b
static inline GUnicodeScript
Packit ae235b
g_unichar_get_script_bsearch (gunichar ch)
Packit ae235b
{
Packit ae235b
  int lower = 0;
Packit ae235b
  int upper = G_N_ELEMENTS (g_script_table) - 1;
Packit ae235b
  static int saved_mid = G_SCRIPT_TABLE_MIDPOINT;
Packit ae235b
  int mid = saved_mid;
Packit ae235b
Packit ae235b
Packit ae235b
  do 
Packit ae235b
    {
Packit ae235b
      if (ch < g_script_table[mid].start)
Packit ae235b
	upper = mid - 1;
Packit ae235b
      else if (ch >= g_script_table[mid].start + g_script_table[mid].chars)
Packit ae235b
	lower = mid + 1;
Packit ae235b
      else
Packit ae235b
	return g_script_table[saved_mid = mid].script;
Packit ae235b
Packit ae235b
      mid = (lower + upper) / 2;
Packit ae235b
    }
Packit ae235b
  while (lower <= upper);
Packit ae235b
Packit ae235b
  return G_UNICODE_SCRIPT_UNKNOWN;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unichar_get_script:
Packit ae235b
 * @ch: a Unicode character
Packit ae235b
 * 
Packit ae235b
 * Looks up the #GUnicodeScript for a particular character (as defined 
Packit ae235b
 * by Unicode Standard Annex \#24). No check is made for @ch being a
Packit ae235b
 * valid Unicode character; if you pass in invalid character, the
Packit ae235b
 * result is undefined.
Packit ae235b
 *
Packit ae235b
 * This function is equivalent to pango_script_for_unichar() and the
Packit ae235b
 * two are interchangeable.
Packit ae235b
 * 
Packit ae235b
 * Returns: the #GUnicodeScript for the character.
Packit ae235b
 *
Packit ae235b
 * Since: 2.14
Packit ae235b
 */
Packit ae235b
GUnicodeScript
Packit ae235b
g_unichar_get_script (gunichar ch)
Packit ae235b
{
Packit ae235b
  if (ch < G_EASY_SCRIPTS_RANGE)
Packit ae235b
    return g_script_easy_table[ch];
Packit ae235b
  else 
Packit ae235b
    return g_unichar_get_script_bsearch (ch); 
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/* http://unicode.org/iso15924/ */
Packit ae235b
static const guint32 iso15924_tags[] =
Packit ae235b
{
Packit ae235b
#define PACK(a,b,c,d) ((guint32)((((guint8)(a))<<24)|(((guint8)(b))<<16)|(((guint8)(c))<<8)|((guint8)(d))))
Packit ae235b
Packit ae235b
    PACK ('Z','y','y','y'), /* G_UNICODE_SCRIPT_COMMON */
Packit ae235b
    PACK ('Z','i','n','h'), /* G_UNICODE_SCRIPT_INHERITED */
Packit ae235b
    PACK ('A','r','a','b'), /* G_UNICODE_SCRIPT_ARABIC */
Packit ae235b
    PACK ('A','r','m','n'), /* G_UNICODE_SCRIPT_ARMENIAN */
Packit ae235b
    PACK ('B','e','n','g'), /* G_UNICODE_SCRIPT_BENGALI */
Packit ae235b
    PACK ('B','o','p','o'), /* G_UNICODE_SCRIPT_BOPOMOFO */
Packit ae235b
    PACK ('C','h','e','r'), /* G_UNICODE_SCRIPT_CHEROKEE */
Packit ae235b
    PACK ('C','o','p','t'), /* G_UNICODE_SCRIPT_COPTIC */
Packit ae235b
    PACK ('C','y','r','l'), /* G_UNICODE_SCRIPT_CYRILLIC */
Packit ae235b
    PACK ('D','s','r','t'), /* G_UNICODE_SCRIPT_DESERET */
Packit ae235b
    PACK ('D','e','v','a'), /* G_UNICODE_SCRIPT_DEVANAGARI */
Packit ae235b
    PACK ('E','t','h','i'), /* G_UNICODE_SCRIPT_ETHIOPIC */
Packit ae235b
    PACK ('G','e','o','r'), /* G_UNICODE_SCRIPT_GEORGIAN */
Packit ae235b
    PACK ('G','o','t','h'), /* G_UNICODE_SCRIPT_GOTHIC */
Packit ae235b
    PACK ('G','r','e','k'), /* G_UNICODE_SCRIPT_GREEK */
Packit ae235b
    PACK ('G','u','j','r'), /* G_UNICODE_SCRIPT_GUJARATI */
Packit ae235b
    PACK ('G','u','r','u'), /* G_UNICODE_SCRIPT_GURMUKHI */
Packit ae235b
    PACK ('H','a','n','i'), /* G_UNICODE_SCRIPT_HAN */
Packit ae235b
    PACK ('H','a','n','g'), /* G_UNICODE_SCRIPT_HANGUL */
Packit ae235b
    PACK ('H','e','b','r'), /* G_UNICODE_SCRIPT_HEBREW */
Packit ae235b
    PACK ('H','i','r','a'), /* G_UNICODE_SCRIPT_HIRAGANA */
Packit ae235b
    PACK ('K','n','d','a'), /* G_UNICODE_SCRIPT_KANNADA */
Packit ae235b
    PACK ('K','a','n','a'), /* G_UNICODE_SCRIPT_KATAKANA */
Packit ae235b
    PACK ('K','h','m','r'), /* G_UNICODE_SCRIPT_KHMER */
Packit ae235b
    PACK ('L','a','o','o'), /* G_UNICODE_SCRIPT_LAO */
Packit ae235b
    PACK ('L','a','t','n'), /* G_UNICODE_SCRIPT_LATIN */
Packit ae235b
    PACK ('M','l','y','m'), /* G_UNICODE_SCRIPT_MALAYALAM */
Packit ae235b
    PACK ('M','o','n','g'), /* G_UNICODE_SCRIPT_MONGOLIAN */
Packit ae235b
    PACK ('M','y','m','r'), /* G_UNICODE_SCRIPT_MYANMAR */
Packit ae235b
    PACK ('O','g','a','m'), /* G_UNICODE_SCRIPT_OGHAM */
Packit ae235b
    PACK ('I','t','a','l'), /* G_UNICODE_SCRIPT_OLD_ITALIC */
Packit ae235b
    PACK ('O','r','y','a'), /* G_UNICODE_SCRIPT_ORIYA */
Packit ae235b
    PACK ('R','u','n','r'), /* G_UNICODE_SCRIPT_RUNIC */
Packit ae235b
    PACK ('S','i','n','h'), /* G_UNICODE_SCRIPT_SINHALA */
Packit ae235b
    PACK ('S','y','r','c'), /* G_UNICODE_SCRIPT_SYRIAC */
Packit ae235b
    PACK ('T','a','m','l'), /* G_UNICODE_SCRIPT_TAMIL */
Packit ae235b
    PACK ('T','e','l','u'), /* G_UNICODE_SCRIPT_TELUGU */
Packit ae235b
    PACK ('T','h','a','a'), /* G_UNICODE_SCRIPT_THAANA */
Packit ae235b
    PACK ('T','h','a','i'), /* G_UNICODE_SCRIPT_THAI */
Packit ae235b
    PACK ('T','i','b','t'), /* G_UNICODE_SCRIPT_TIBETAN */
Packit ae235b
    PACK ('C','a','n','s'), /* G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL */
Packit ae235b
    PACK ('Y','i','i','i'), /* G_UNICODE_SCRIPT_YI */
Packit ae235b
    PACK ('T','g','l','g'), /* G_UNICODE_SCRIPT_TAGALOG */
Packit ae235b
    PACK ('H','a','n','o'), /* G_UNICODE_SCRIPT_HANUNOO */
Packit ae235b
    PACK ('B','u','h','d'), /* G_UNICODE_SCRIPT_BUHID */
Packit ae235b
    PACK ('T','a','g','b'), /* G_UNICODE_SCRIPT_TAGBANWA */
Packit ae235b
Packit ae235b
  /* Unicode-4.0 additions */
Packit ae235b
    PACK ('B','r','a','i'), /* G_UNICODE_SCRIPT_BRAILLE */
Packit ae235b
    PACK ('C','p','r','t'), /* G_UNICODE_SCRIPT_CYPRIOT */
Packit ae235b
    PACK ('L','i','m','b'), /* G_UNICODE_SCRIPT_LIMBU */
Packit ae235b
    PACK ('O','s','m','a'), /* G_UNICODE_SCRIPT_OSMANYA */
Packit ae235b
    PACK ('S','h','a','w'), /* G_UNICODE_SCRIPT_SHAVIAN */
Packit ae235b
    PACK ('L','i','n','b'), /* G_UNICODE_SCRIPT_LINEAR_B */
Packit ae235b
    PACK ('T','a','l','e'), /* G_UNICODE_SCRIPT_TAI_LE */
Packit ae235b
    PACK ('U','g','a','r'), /* G_UNICODE_SCRIPT_UGARITIC */
Packit ae235b
Packit ae235b
  /* Unicode-4.1 additions */
Packit ae235b
    PACK ('T','a','l','u'), /* G_UNICODE_SCRIPT_NEW_TAI_LUE */
Packit ae235b
    PACK ('B','u','g','i'), /* G_UNICODE_SCRIPT_BUGINESE */
Packit ae235b
    PACK ('G','l','a','g'), /* G_UNICODE_SCRIPT_GLAGOLITIC */
Packit ae235b
    PACK ('T','f','n','g'), /* G_UNICODE_SCRIPT_TIFINAGH */
Packit ae235b
    PACK ('S','y','l','o'), /* G_UNICODE_SCRIPT_SYLOTI_NAGRI */
Packit ae235b
    PACK ('X','p','e','o'), /* G_UNICODE_SCRIPT_OLD_PERSIAN */
Packit ae235b
    PACK ('K','h','a','r'), /* G_UNICODE_SCRIPT_KHAROSHTHI */
Packit ae235b
Packit ae235b
  /* Unicode-5.0 additions */
Packit ae235b
    PACK ('Z','z','z','z'), /* G_UNICODE_SCRIPT_UNKNOWN */
Packit ae235b
    PACK ('B','a','l','i'), /* G_UNICODE_SCRIPT_BALINESE */
Packit ae235b
    PACK ('X','s','u','x'), /* G_UNICODE_SCRIPT_CUNEIFORM */
Packit ae235b
    PACK ('P','h','n','x'), /* G_UNICODE_SCRIPT_PHOENICIAN */
Packit ae235b
    PACK ('P','h','a','g'), /* G_UNICODE_SCRIPT_PHAGS_PA */
Packit ae235b
    PACK ('N','k','o','o'), /* G_UNICODE_SCRIPT_NKO */
Packit ae235b
Packit ae235b
  /* Unicode-5.1 additions */
Packit ae235b
    PACK ('K','a','l','i'), /* G_UNICODE_SCRIPT_KAYAH_LI */
Packit ae235b
    PACK ('L','e','p','c'), /* G_UNICODE_SCRIPT_LEPCHA */
Packit ae235b
    PACK ('R','j','n','g'), /* G_UNICODE_SCRIPT_REJANG */
Packit ae235b
    PACK ('S','u','n','d'), /* G_UNICODE_SCRIPT_SUNDANESE */
Packit ae235b
    PACK ('S','a','u','r'), /* G_UNICODE_SCRIPT_SAURASHTRA */
Packit ae235b
    PACK ('C','h','a','m'), /* G_UNICODE_SCRIPT_CHAM */
Packit ae235b
    PACK ('O','l','c','k'), /* G_UNICODE_SCRIPT_OL_CHIKI */
Packit ae235b
    PACK ('V','a','i','i'), /* G_UNICODE_SCRIPT_VAI */
Packit ae235b
    PACK ('C','a','r','i'), /* G_UNICODE_SCRIPT_CARIAN */
Packit ae235b
    PACK ('L','y','c','i'), /* G_UNICODE_SCRIPT_LYCIAN */
Packit ae235b
    PACK ('L','y','d','i'), /* G_UNICODE_SCRIPT_LYDIAN */
Packit ae235b
Packit ae235b
  /* Unicode-5.2 additions */
Packit ae235b
    PACK ('A','v','s','t'), /* G_UNICODE_SCRIPT_AVESTAN */
Packit ae235b
    PACK ('B','a','m','u'), /* G_UNICODE_SCRIPT_BAMUM */
Packit ae235b
    PACK ('E','g','y','p'), /* G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS */
Packit ae235b
    PACK ('A','r','m','i'), /* G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC */
Packit ae235b
    PACK ('P','h','l','i'), /* G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI */
Packit ae235b
    PACK ('P','r','t','i'), /* G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN */
Packit ae235b
    PACK ('J','a','v','a'), /* G_UNICODE_SCRIPT_JAVANESE */
Packit ae235b
    PACK ('K','t','h','i'), /* G_UNICODE_SCRIPT_KAITHI */
Packit ae235b
    PACK ('L','i','s','u'), /* G_UNICODE_SCRIPT_LISU */
Packit ae235b
    PACK ('M','t','e','i'), /* G_UNICODE_SCRIPT_MEETEI_MAYEK */
Packit ae235b
    PACK ('S','a','r','b'), /* G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN */
Packit ae235b
    PACK ('O','r','k','h'), /* G_UNICODE_SCRIPT_OLD_TURKIC */
Packit ae235b
    PACK ('S','a','m','r'), /* G_UNICODE_SCRIPT_SAMARITAN */
Packit ae235b
    PACK ('L','a','n','a'), /* G_UNICODE_SCRIPT_TAI_THAM */
Packit ae235b
    PACK ('T','a','v','t'), /* G_UNICODE_SCRIPT_TAI_VIET */
Packit ae235b
Packit ae235b
  /* Unicode-6.0 additions */
Packit ae235b
    PACK ('B','a','t','k'), /* G_UNICODE_SCRIPT_BATAK */
Packit ae235b
    PACK ('B','r','a','h'), /* G_UNICODE_SCRIPT_BRAHMI */
Packit ae235b
    PACK ('M','a','n','d'), /* G_UNICODE_SCRIPT_MANDAIC */
Packit ae235b
Packit ae235b
  /* Unicode-6.1 additions */
Packit ae235b
    PACK ('C','a','k','m'), /* G_UNICODE_SCRIPT_CHAKMA */
Packit ae235b
    PACK ('M','e','r','c'), /* G_UNICODE_SCRIPT_MEROITIC_CURSIVE */
Packit ae235b
    PACK ('M','e','r','o'), /* G_UNICODE_SCRIPT_MEROITIC_HIEROGLYPHS */
Packit ae235b
    PACK ('P','l','r','d'), /* G_UNICODE_SCRIPT_MIAO */
Packit ae235b
    PACK ('S','h','r','d'), /* G_UNICODE_SCRIPT_SHARADA */
Packit ae235b
    PACK ('S','o','r','a'), /* G_UNICODE_SCRIPT_SORA_SOMPENG */
Packit ae235b
    PACK ('T','a','k','r'), /* G_UNICODE_SCRIPT_TAKRI */
Packit ae235b
Packit ae235b
  /* Unicode 7.0 additions */
Packit ae235b
    PACK ('B','a','s','s'), /* G_UNICODE_SCRIPT_BASSA_VAH */
Packit ae235b
    PACK ('A','g','h','b'), /* G_UNICODE_SCRIPT_CAUCASIAN_ALBANIAN */
Packit ae235b
    PACK ('D','u','p','l'), /* G_UNICODE_SCRIPT_DUPLOYAN */
Packit ae235b
    PACK ('E','l','b','a'), /* G_UNICODE_SCRIPT_ELBASAN */
Packit ae235b
    PACK ('G','r','a','n'), /* G_UNICODE_SCRIPT_GRANTHA */
Packit ae235b
    PACK ('K','h','o','j'), /* G_UNICODE_SCRIPT_KHOJKI*/
Packit ae235b
    PACK ('S','i','n','d'), /* G_UNICODE_SCRIPT_KHUDAWADI */
Packit ae235b
    PACK ('L','i','n','a'), /* G_UNICODE_SCRIPT_LINEAR_A */
Packit ae235b
    PACK ('M','a','h','j'), /* G_UNICODE_SCRIPT_MAHAJANI */
Packit ae235b
    PACK ('M','a','n','u'), /* G_UNICODE_SCRIPT_MANICHAEAN */
Packit ae235b
    PACK ('M','e','n','d'), /* G_UNICODE_SCRIPT_MENDE_KIKAKUI */
Packit ae235b
    PACK ('M','o','d','i'), /* G_UNICODE_SCRIPT_MODI */
Packit ae235b
    PACK ('M','r','o','o'), /* G_UNICODE_SCRIPT_MRO */
Packit ae235b
    PACK ('N','b','a','t'), /* G_UNICODE_SCRIPT_NABATAEAN */
Packit ae235b
    PACK ('N','a','r','b'), /* G_UNICODE_SCRIPT_OLD_NORTH_ARABIAN */
Packit ae235b
    PACK ('P','e','r','m'), /* G_UNICODE_SCRIPT_OLD_PERMIC */
Packit ae235b
    PACK ('H','m','n','g'), /* G_UNICODE_SCRIPT_PAHAWH_HMONG */
Packit ae235b
    PACK ('P','a','l','m'), /* G_UNICODE_SCRIPT_PALMYRENE */
Packit ae235b
    PACK ('P','a','u','c'), /* G_UNICODE_SCRIPT_PAU_CIN_HAU */
Packit ae235b
    PACK ('P','h','l','p'), /* G_UNICODE_SCRIPT_PSALTER_PAHLAVI */
Packit ae235b
    PACK ('S','i','d','d'), /* G_UNICODE_SCRIPT_SIDDHAM */
Packit ae235b
    PACK ('T','i','r','h'), /* G_UNICODE_SCRIPT_TIRHUTA */
Packit ae235b
    PACK ('W','a','r','a'), /* G_UNICODE_SCRIPT_WARANG_CITI */
Packit ae235b
Packit ae235b
  /* Unicode 8.0 additions */
Packit ae235b
    PACK ('A','h','o','m'), /* G_UNICODE_SCRIPT_AHOM */
Packit ae235b
    PACK ('H','l','u','w'), /* G_UNICODE_SCRIPT_ANATOLIAN_HIEROGLYPHS */
Packit ae235b
    PACK ('H','a','t','r'), /* G_UNICODE_SCRIPT_HATRAN */
Packit ae235b
    PACK ('M','u','l','t'), /* G_UNICODE_SCRIPT_MULTANI */
Packit ae235b
    PACK ('H','u','n','g'), /* G_UNICODE_SCRIPT_OLD_HUNGARIAN */
Packit ae235b
    PACK ('S','g','n','w'), /* G_UNICODE_SCRIPT_SIGNWRITING */
Packit ae235b
Packit ae235b
  /* Unicode 9.0 additions */
Packit ae235b
    PACK ('A','d','l','m'), /* G_UNICODE_SCRIPT_ADLAM */
Packit ae235b
    PACK ('B','h','k','s'), /* G_UNICODE_SCRIPT_BHAIKSUKI */
Packit ae235b
    PACK ('M','a','r','c'), /* G_UNICODE_SCRIPT_MARCHEN */
Packit ae235b
    PACK ('N','e','w','a'), /* G_UNICODE_SCRIPT_NEWA */
Packit ae235b
    PACK ('O','s','g','e'), /* G_UNICODE_SCRIPT_OSAGE */
Packit ae235b
    PACK ('T','a','n','g'), /* G_UNICODE_SCRIPT_TANGUT */
Packit ae235b
Packit ae235b
  /* Unicode 10.0 additions */
Packit ae235b
    PACK ('G','o','n','m'), /* G_UNICODE_SCRIPT_MASARAM_GONDI */
Packit ae235b
    PACK ('N','s','h','u'), /* G_UNICODE_SCRIPT_NUSHU */
Packit ae235b
    PACK ('S','o','y','o'), /* G_UNICODE_SCRIPT_SOYOMBO */
Packit ae235b
    PACK ('Z','a','n','b'), /* G_UNICODE_SCRIPT_ZANABAZAR_SQUARE */
Packit ae235b
#undef PACK
Packit ae235b
};
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unicode_script_to_iso15924:
Packit ae235b
 * @script: a Unicode script
Packit ae235b
 *
Packit ae235b
 * Looks up the ISO 15924 code for @script.  ISO 15924 assigns four-letter
Packit ae235b
 * codes to scripts.  For example, the code for Arabic is 'Arab'.  The
Packit ae235b
 * four letter codes are encoded as a @guint32 by this function in a
Packit ae235b
 * big-endian fashion.  That is, the code returned for Arabic is
Packit ae235b
 * 0x41726162 (0x41 is ASCII code for 'A', 0x72 is ASCII code for 'r', etc).
Packit ae235b
 *
Packit ae235b
 * See
Packit ae235b
 * [Codes for the representation of names of scripts](http://unicode.org/iso15924/codelists.html)
Packit ae235b
 * for details.
Packit ae235b
 *
Packit ae235b
 * Returns: the ISO 15924 code for @script, encoded as an integer,
Packit ae235b
 *   of zero if @script is %G_UNICODE_SCRIPT_INVALID_CODE or
Packit ae235b
 *   ISO 15924 code 'Zzzz' (script code for UNKNOWN) if @script is not understood.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
guint32
Packit ae235b
g_unicode_script_to_iso15924 (GUnicodeScript script)
Packit ae235b
{
Packit ae235b
  if (G_UNLIKELY (script == G_UNICODE_SCRIPT_INVALID_CODE))
Packit ae235b
    return 0;
Packit ae235b
Packit ae235b
  if (G_UNLIKELY (script < 0 || script >= (int) G_N_ELEMENTS (iso15924_tags)))
Packit ae235b
    return 0x5A7A7A7A;
Packit ae235b
Packit ae235b
  return iso15924_tags[script];
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_unicode_script_from_iso15924:
Packit ae235b
 * @iso15924: a Unicode script
Packit ae235b
 *
Packit ae235b
 * Looks up the Unicode script for @iso15924.  ISO 15924 assigns four-letter
Packit ae235b
 * codes to scripts.  For example, the code for Arabic is 'Arab'.
Packit ae235b
 * This function accepts four letter codes encoded as a @guint32 in a
Packit ae235b
 * big-endian fashion.  That is, the code expected for Arabic is
Packit ae235b
 * 0x41726162 (0x41 is ASCII code for 'A', 0x72 is ASCII code for 'r', etc).
Packit ae235b
 *
Packit ae235b
 * See
Packit ae235b
 * [Codes for the representation of names of scripts](http://unicode.org/iso15924/codelists.html)
Packit ae235b
 * for details.
Packit ae235b
 *
Packit ae235b
 * Returns: the Unicode script for @iso15924, or
Packit ae235b
 *   of %G_UNICODE_SCRIPT_INVALID_CODE if @iso15924 is zero and
Packit ae235b
 *   %G_UNICODE_SCRIPT_UNKNOWN if @iso15924 is unknown.
Packit ae235b
 *
Packit ae235b
 * Since: 2.30
Packit ae235b
 */
Packit ae235b
GUnicodeScript
Packit ae235b
g_unicode_script_from_iso15924 (guint32 iso15924)
Packit ae235b
{
Packit ae235b
  unsigned int i;
Packit ae235b
Packit ae235b
   if (!iso15924)
Packit ae235b
     return G_UNICODE_SCRIPT_INVALID_CODE;
Packit ae235b
Packit ae235b
  for (i = 0; i < G_N_ELEMENTS (iso15924_tags); i++)
Packit ae235b
    if (iso15924_tags[i] == iso15924)
Packit ae235b
      return (GUnicodeScript) i;
Packit ae235b
Packit ae235b
  return G_UNICODE_SCRIPT_UNKNOWN;
Packit ae235b
}