root/maint/gnulib/lib/unictype/pr_byname.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. uc_property_byname

   1 /* Properties of Unicode characters.
   2    Copyright (C) 2007, 2011-2021 Free Software Foundation, Inc.
   3    Written by Bruno Haible <bruno@clisp.org>, 2007.
   4 
   5    This file is free software.
   6    It is dual-licensed under "the GNU LGPLv3+ or the GNU GPLv2+".
   7    You can redistribute it and/or modify it under either
   8      - the terms of the GNU Lesser General Public License as published
   9        by the Free Software Foundation; either version 3, or (at your
  10        option) any later version, or
  11      - the terms of the GNU General Public License as published by the
  12        Free Software Foundation; either version 2, or (at your option)
  13        any later version, or
  14      - the same dual license "the GNU LGPLv3+ or the GNU GPLv2+".
  15 
  16    This file is distributed in the hope that it will be useful,
  17    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19    Lesser General Public License and the GNU General Public License
  20    for more details.
  21 
  22    You should have received a copy of the GNU Lesser General Public
  23    License and of the GNU General Public License along with this
  24    program.  If not, see <https://www.gnu.org/licenses/>.  */
  25 
  26 #include <config.h>
  27 
  28 /* Specification.  */
  29 #include "unictype.h"
  30 
  31 #include <stdlib.h>
  32 #include <string.h>
  33 
  34 /* Indices stored in the 'struct named_category' elements of the perfect hash
  35    table.  We don't use uc_general_category_t values or their addresses
  36    directly, because this would introduce load-time relocations.  */
  37 enum
  38 {
  39   /* General.  */
  40   UC_PROPERTY_INDEX_WHITE_SPACE,
  41   UC_PROPERTY_INDEX_ALPHABETIC,
  42   UC_PROPERTY_INDEX_OTHER_ALPHABETIC,
  43   UC_PROPERTY_INDEX_NOT_A_CHARACTER,
  44   UC_PROPERTY_INDEX_DEFAULT_IGNORABLE_CODE_POINT,
  45   UC_PROPERTY_INDEX_OTHER_DEFAULT_IGNORABLE_CODE_POINT,
  46   UC_PROPERTY_INDEX_DEPRECATED,
  47   UC_PROPERTY_INDEX_LOGICAL_ORDER_EXCEPTION,
  48   UC_PROPERTY_INDEX_VARIATION_SELECTOR,
  49   UC_PROPERTY_INDEX_PRIVATE_USE,
  50   UC_PROPERTY_INDEX_UNASSIGNED_CODE_VALUE,
  51   /* Case.  */
  52   UC_PROPERTY_INDEX_UPPERCASE,
  53   UC_PROPERTY_INDEX_OTHER_UPPERCASE,
  54   UC_PROPERTY_INDEX_LOWERCASE,
  55   UC_PROPERTY_INDEX_OTHER_LOWERCASE,
  56   UC_PROPERTY_INDEX_TITLECASE,
  57   UC_PROPERTY_INDEX_CASED,
  58   UC_PROPERTY_INDEX_CASE_IGNORABLE,
  59   UC_PROPERTY_INDEX_CHANGES_WHEN_LOWERCASED,
  60   UC_PROPERTY_INDEX_CHANGES_WHEN_UPPERCASED,
  61   UC_PROPERTY_INDEX_CHANGES_WHEN_TITLECASED,
  62   UC_PROPERTY_INDEX_CHANGES_WHEN_CASEFOLDED,
  63   UC_PROPERTY_INDEX_CHANGES_WHEN_CASEMAPPED,
  64   UC_PROPERTY_INDEX_SOFT_DOTTED,
  65   /* Identifiers.  */
  66   UC_PROPERTY_INDEX_ID_START,
  67   UC_PROPERTY_INDEX_OTHER_ID_START,
  68   UC_PROPERTY_INDEX_ID_CONTINUE,
  69   UC_PROPERTY_INDEX_OTHER_ID_CONTINUE,
  70   UC_PROPERTY_INDEX_XID_START,
  71   UC_PROPERTY_INDEX_XID_CONTINUE,
  72   UC_PROPERTY_INDEX_PATTERN_WHITE_SPACE,
  73   UC_PROPERTY_INDEX_PATTERN_SYNTAX,
  74   /* Shaping and rendering.  */
  75   UC_PROPERTY_INDEX_JOIN_CONTROL,
  76   UC_PROPERTY_INDEX_GRAPHEME_BASE,
  77   UC_PROPERTY_INDEX_GRAPHEME_EXTEND,
  78   UC_PROPERTY_INDEX_OTHER_GRAPHEME_EXTEND,
  79   UC_PROPERTY_INDEX_GRAPHEME_LINK,
  80   /* Bidi.  */
  81   UC_PROPERTY_INDEX_BIDI_CONTROL,
  82   UC_PROPERTY_INDEX_BIDI_LEFT_TO_RIGHT,
  83   UC_PROPERTY_INDEX_BIDI_HEBREW_RIGHT_TO_LEFT,
  84   UC_PROPERTY_INDEX_BIDI_ARABIC_RIGHT_TO_LEFT,
  85   UC_PROPERTY_INDEX_BIDI_EUROPEAN_DIGIT,
  86   UC_PROPERTY_INDEX_BIDI_EUR_NUM_SEPARATOR,
  87   UC_PROPERTY_INDEX_BIDI_EUR_NUM_TERMINATOR,
  88   UC_PROPERTY_INDEX_BIDI_ARABIC_DIGIT,
  89   UC_PROPERTY_INDEX_BIDI_COMMON_SEPARATOR,
  90   UC_PROPERTY_INDEX_BIDI_BLOCK_SEPARATOR,
  91   UC_PROPERTY_INDEX_BIDI_SEGMENT_SEPARATOR,
  92   UC_PROPERTY_INDEX_BIDI_WHITESPACE,
  93   UC_PROPERTY_INDEX_BIDI_NON_SPACING_MARK,
  94   UC_PROPERTY_INDEX_BIDI_BOUNDARY_NEUTRAL,
  95   UC_PROPERTY_INDEX_BIDI_PDF,
  96   UC_PROPERTY_INDEX_BIDI_EMBEDDING_OR_OVERRIDE,
  97   UC_PROPERTY_INDEX_BIDI_OTHER_NEUTRAL,
  98   /* Numeric.  */
  99   UC_PROPERTY_INDEX_HEX_DIGIT,
 100   UC_PROPERTY_INDEX_ASCII_HEX_DIGIT,
 101   /* CJK.  */
 102   UC_PROPERTY_INDEX_IDEOGRAPHIC,
 103   UC_PROPERTY_INDEX_UNIFIED_IDEOGRAPH,
 104   UC_PROPERTY_INDEX_RADICAL,
 105   UC_PROPERTY_INDEX_IDS_BINARY_OPERATOR,
 106   UC_PROPERTY_INDEX_IDS_TRINARY_OPERATOR,
 107   /* Misc.  */
 108   UC_PROPERTY_INDEX_ZERO_WIDTH,
 109   UC_PROPERTY_INDEX_SPACE,
 110   UC_PROPERTY_INDEX_NON_BREAK,
 111   UC_PROPERTY_INDEX_ISO_CONTROL,
 112   UC_PROPERTY_INDEX_FORMAT_CONTROL,
 113   UC_PROPERTY_INDEX_DASH,
 114   UC_PROPERTY_INDEX_HYPHEN,
 115   UC_PROPERTY_INDEX_PUNCTUATION,
 116   UC_PROPERTY_INDEX_LINE_SEPARATOR,
 117   UC_PROPERTY_INDEX_PARAGRAPH_SEPARATOR,
 118   UC_PROPERTY_INDEX_QUOTATION_MARK,
 119   UC_PROPERTY_INDEX_SENTENCE_TERMINAL,
 120   UC_PROPERTY_INDEX_TERMINAL_PUNCTUATION,
 121   UC_PROPERTY_INDEX_CURRENCY_SYMBOL,
 122   UC_PROPERTY_INDEX_MATH,
 123   UC_PROPERTY_INDEX_OTHER_MATH,
 124   UC_PROPERTY_INDEX_PAIRED_PUNCTUATION,
 125   UC_PROPERTY_INDEX_LEFT_OF_PAIR,
 126   UC_PROPERTY_INDEX_COMBINING,
 127   UC_PROPERTY_INDEX_COMPOSITE,
 128   UC_PROPERTY_INDEX_DECIMAL_DIGIT,
 129   UC_PROPERTY_INDEX_NUMERIC,
 130   UC_PROPERTY_INDEX_DIACRITIC,
 131   UC_PROPERTY_INDEX_EXTENDER,
 132   UC_PROPERTY_INDEX_IGNORABLE_CONTROL
 133 };
 134 
 135 /* Get gperf generated lookup function.  */
 136 #include "unictype/pr_byname.h"
 137 
 138 static const uc_property_t UC_PROPERTY_NONE = { NULL };
 139 
 140 uc_property_t
 141 uc_property_byname (const char *property_name)
     /* [previous][next][first][last][top][bottom][index][help] */
 142 {
 143   char buf[MAX_WORD_LENGTH + 1];
 144   const char *cp;
 145   char *bp;
 146   unsigned int count;
 147   const struct named_property *found;
 148 
 149   for (cp = property_name, bp = buf, count = MAX_WORD_LENGTH + 1; ; cp++, bp++)
 150     {
 151       unsigned char c = (unsigned char) *cp;
 152       if (c >= 0x80)
 153         goto invalid;
 154       if (c >= 'A' && c <= 'Z')
 155         c += 'a' - 'A';
 156       else if (c == ' ' || c == '-')
 157         c = '_';
 158       *bp = c;
 159       if (c == '\0')
 160         break;
 161       if (--count == 0)
 162         goto invalid;
 163     }
 164   found = uc_property_lookup (buf, bp - buf);
 165   if (found != NULL)
 166     /* Use a 'switch' statement here, because a table would introduce load-time
 167        relocations.  */
 168     switch (found->property_index)
 169       {
 170       case UC_PROPERTY_INDEX_WHITE_SPACE:
 171         return UC_PROPERTY_WHITE_SPACE;
 172       case UC_PROPERTY_INDEX_ALPHABETIC:
 173         return UC_PROPERTY_ALPHABETIC;
 174       case UC_PROPERTY_INDEX_OTHER_ALPHABETIC:
 175         return UC_PROPERTY_OTHER_ALPHABETIC;
 176       case UC_PROPERTY_INDEX_NOT_A_CHARACTER:
 177         return UC_PROPERTY_NOT_A_CHARACTER;
 178       case UC_PROPERTY_INDEX_DEFAULT_IGNORABLE_CODE_POINT:
 179         return UC_PROPERTY_DEFAULT_IGNORABLE_CODE_POINT;
 180       case UC_PROPERTY_INDEX_OTHER_DEFAULT_IGNORABLE_CODE_POINT:
 181         return UC_PROPERTY_OTHER_DEFAULT_IGNORABLE_CODE_POINT;
 182       case UC_PROPERTY_INDEX_DEPRECATED:
 183         return UC_PROPERTY_DEPRECATED;
 184       case UC_PROPERTY_INDEX_LOGICAL_ORDER_EXCEPTION:
 185         return UC_PROPERTY_LOGICAL_ORDER_EXCEPTION;
 186       case UC_PROPERTY_INDEX_VARIATION_SELECTOR:
 187         return UC_PROPERTY_VARIATION_SELECTOR;
 188       case UC_PROPERTY_INDEX_PRIVATE_USE:
 189         return UC_PROPERTY_PRIVATE_USE;
 190       case UC_PROPERTY_INDEX_UNASSIGNED_CODE_VALUE:
 191         return UC_PROPERTY_UNASSIGNED_CODE_VALUE;
 192       case UC_PROPERTY_INDEX_UPPERCASE:
 193         return UC_PROPERTY_UPPERCASE;
 194       case UC_PROPERTY_INDEX_OTHER_UPPERCASE:
 195         return UC_PROPERTY_OTHER_UPPERCASE;
 196       case UC_PROPERTY_INDEX_LOWERCASE:
 197         return UC_PROPERTY_LOWERCASE;
 198       case UC_PROPERTY_INDEX_OTHER_LOWERCASE:
 199         return UC_PROPERTY_OTHER_LOWERCASE;
 200       case UC_PROPERTY_INDEX_TITLECASE:
 201         return UC_PROPERTY_TITLECASE;
 202       case UC_PROPERTY_INDEX_CASED:
 203         return UC_PROPERTY_CASED;
 204       case UC_PROPERTY_INDEX_CASE_IGNORABLE:
 205         return UC_PROPERTY_CASE_IGNORABLE;
 206       case UC_PROPERTY_INDEX_CHANGES_WHEN_LOWERCASED:
 207         return UC_PROPERTY_CHANGES_WHEN_LOWERCASED;
 208       case UC_PROPERTY_INDEX_CHANGES_WHEN_UPPERCASED:
 209         return UC_PROPERTY_CHANGES_WHEN_UPPERCASED;
 210       case UC_PROPERTY_INDEX_CHANGES_WHEN_TITLECASED:
 211         return UC_PROPERTY_CHANGES_WHEN_TITLECASED;
 212       case UC_PROPERTY_INDEX_CHANGES_WHEN_CASEFOLDED:
 213         return UC_PROPERTY_CHANGES_WHEN_CASEFOLDED;
 214       case UC_PROPERTY_INDEX_CHANGES_WHEN_CASEMAPPED:
 215         return UC_PROPERTY_CHANGES_WHEN_CASEMAPPED;
 216       case UC_PROPERTY_INDEX_SOFT_DOTTED:
 217         return UC_PROPERTY_SOFT_DOTTED;
 218       case UC_PROPERTY_INDEX_ID_START:
 219         return UC_PROPERTY_ID_START;
 220       case UC_PROPERTY_INDEX_OTHER_ID_START:
 221         return UC_PROPERTY_OTHER_ID_START;
 222       case UC_PROPERTY_INDEX_ID_CONTINUE:
 223         return UC_PROPERTY_ID_CONTINUE;
 224       case UC_PROPERTY_INDEX_OTHER_ID_CONTINUE:
 225         return UC_PROPERTY_OTHER_ID_CONTINUE;
 226       case UC_PROPERTY_INDEX_XID_START:
 227         return UC_PROPERTY_XID_START;
 228       case UC_PROPERTY_INDEX_XID_CONTINUE:
 229         return UC_PROPERTY_XID_CONTINUE;
 230       case UC_PROPERTY_INDEX_PATTERN_WHITE_SPACE:
 231         return UC_PROPERTY_PATTERN_WHITE_SPACE;
 232       case UC_PROPERTY_INDEX_PATTERN_SYNTAX:
 233         return UC_PROPERTY_PATTERN_SYNTAX;
 234       case UC_PROPERTY_INDEX_JOIN_CONTROL:
 235         return UC_PROPERTY_JOIN_CONTROL;
 236       case UC_PROPERTY_INDEX_GRAPHEME_BASE:
 237         return UC_PROPERTY_GRAPHEME_BASE;
 238       case UC_PROPERTY_INDEX_GRAPHEME_EXTEND:
 239         return UC_PROPERTY_GRAPHEME_EXTEND;
 240       case UC_PROPERTY_INDEX_OTHER_GRAPHEME_EXTEND:
 241         return UC_PROPERTY_OTHER_GRAPHEME_EXTEND;
 242       case UC_PROPERTY_INDEX_GRAPHEME_LINK:
 243         return UC_PROPERTY_GRAPHEME_LINK;
 244       case UC_PROPERTY_INDEX_BIDI_CONTROL:
 245         return UC_PROPERTY_BIDI_CONTROL;
 246       case UC_PROPERTY_INDEX_BIDI_LEFT_TO_RIGHT:
 247         return UC_PROPERTY_BIDI_LEFT_TO_RIGHT;
 248       case UC_PROPERTY_INDEX_BIDI_HEBREW_RIGHT_TO_LEFT:
 249         return UC_PROPERTY_BIDI_HEBREW_RIGHT_TO_LEFT;
 250       case UC_PROPERTY_INDEX_BIDI_ARABIC_RIGHT_TO_LEFT:
 251         return UC_PROPERTY_BIDI_ARABIC_RIGHT_TO_LEFT;
 252       case UC_PROPERTY_INDEX_BIDI_EUROPEAN_DIGIT:
 253         return UC_PROPERTY_BIDI_EUROPEAN_DIGIT;
 254       case UC_PROPERTY_INDEX_BIDI_EUR_NUM_SEPARATOR:
 255         return UC_PROPERTY_BIDI_EUR_NUM_SEPARATOR;
 256       case UC_PROPERTY_INDEX_BIDI_EUR_NUM_TERMINATOR:
 257         return UC_PROPERTY_BIDI_EUR_NUM_TERMINATOR;
 258       case UC_PROPERTY_INDEX_BIDI_ARABIC_DIGIT:
 259         return UC_PROPERTY_BIDI_ARABIC_DIGIT;
 260       case UC_PROPERTY_INDEX_BIDI_COMMON_SEPARATOR:
 261         return UC_PROPERTY_BIDI_COMMON_SEPARATOR;
 262       case UC_PROPERTY_INDEX_BIDI_BLOCK_SEPARATOR:
 263         return UC_PROPERTY_BIDI_BLOCK_SEPARATOR;
 264       case UC_PROPERTY_INDEX_BIDI_SEGMENT_SEPARATOR:
 265         return UC_PROPERTY_BIDI_SEGMENT_SEPARATOR;
 266       case UC_PROPERTY_INDEX_BIDI_WHITESPACE:
 267         return UC_PROPERTY_BIDI_WHITESPACE;
 268       case UC_PROPERTY_INDEX_BIDI_NON_SPACING_MARK:
 269         return UC_PROPERTY_BIDI_NON_SPACING_MARK;
 270       case UC_PROPERTY_INDEX_BIDI_BOUNDARY_NEUTRAL:
 271         return UC_PROPERTY_BIDI_BOUNDARY_NEUTRAL;
 272       case UC_PROPERTY_INDEX_BIDI_PDF:
 273         return UC_PROPERTY_BIDI_PDF;
 274       case UC_PROPERTY_INDEX_BIDI_EMBEDDING_OR_OVERRIDE:
 275         return UC_PROPERTY_BIDI_EMBEDDING_OR_OVERRIDE;
 276       case UC_PROPERTY_INDEX_BIDI_OTHER_NEUTRAL:
 277         return UC_PROPERTY_BIDI_OTHER_NEUTRAL;
 278       case UC_PROPERTY_INDEX_HEX_DIGIT:
 279         return UC_PROPERTY_HEX_DIGIT;
 280       case UC_PROPERTY_INDEX_ASCII_HEX_DIGIT:
 281         return UC_PROPERTY_ASCII_HEX_DIGIT;
 282       case UC_PROPERTY_INDEX_IDEOGRAPHIC:
 283         return UC_PROPERTY_IDEOGRAPHIC;
 284       case UC_PROPERTY_INDEX_UNIFIED_IDEOGRAPH:
 285         return UC_PROPERTY_UNIFIED_IDEOGRAPH;
 286       case UC_PROPERTY_INDEX_RADICAL:
 287         return UC_PROPERTY_RADICAL;
 288       case UC_PROPERTY_INDEX_IDS_BINARY_OPERATOR:
 289         return UC_PROPERTY_IDS_BINARY_OPERATOR;
 290       case UC_PROPERTY_INDEX_IDS_TRINARY_OPERATOR:
 291         return UC_PROPERTY_IDS_TRINARY_OPERATOR;
 292       case UC_PROPERTY_INDEX_ZERO_WIDTH:
 293         return UC_PROPERTY_ZERO_WIDTH;
 294       case UC_PROPERTY_INDEX_SPACE:
 295         return UC_PROPERTY_SPACE;
 296       case UC_PROPERTY_INDEX_NON_BREAK:
 297         return UC_PROPERTY_NON_BREAK;
 298       case UC_PROPERTY_INDEX_ISO_CONTROL:
 299         return UC_PROPERTY_ISO_CONTROL;
 300       case UC_PROPERTY_INDEX_FORMAT_CONTROL:
 301         return UC_PROPERTY_FORMAT_CONTROL;
 302       case UC_PROPERTY_INDEX_DASH:
 303         return UC_PROPERTY_DASH;
 304       case UC_PROPERTY_INDEX_HYPHEN:
 305         return UC_PROPERTY_HYPHEN;
 306       case UC_PROPERTY_INDEX_PUNCTUATION:
 307         return UC_PROPERTY_PUNCTUATION;
 308       case UC_PROPERTY_INDEX_LINE_SEPARATOR:
 309         return UC_PROPERTY_LINE_SEPARATOR;
 310       case UC_PROPERTY_INDEX_PARAGRAPH_SEPARATOR:
 311         return UC_PROPERTY_PARAGRAPH_SEPARATOR;
 312       case UC_PROPERTY_INDEX_QUOTATION_MARK:
 313         return UC_PROPERTY_QUOTATION_MARK;
 314       case UC_PROPERTY_INDEX_SENTENCE_TERMINAL:
 315         return UC_PROPERTY_SENTENCE_TERMINAL;
 316       case UC_PROPERTY_INDEX_TERMINAL_PUNCTUATION:
 317         return UC_PROPERTY_TERMINAL_PUNCTUATION;
 318       case UC_PROPERTY_INDEX_CURRENCY_SYMBOL:
 319         return UC_PROPERTY_CURRENCY_SYMBOL;
 320       case UC_PROPERTY_INDEX_MATH:
 321         return UC_PROPERTY_MATH;
 322       case UC_PROPERTY_INDEX_OTHER_MATH:
 323         return UC_PROPERTY_OTHER_MATH;
 324       case UC_PROPERTY_INDEX_PAIRED_PUNCTUATION:
 325         return UC_PROPERTY_PAIRED_PUNCTUATION;
 326       case UC_PROPERTY_INDEX_LEFT_OF_PAIR:
 327         return UC_PROPERTY_LEFT_OF_PAIR;
 328       case UC_PROPERTY_INDEX_COMBINING:
 329         return UC_PROPERTY_COMBINING;
 330       case UC_PROPERTY_INDEX_COMPOSITE:
 331         return UC_PROPERTY_COMPOSITE;
 332       case UC_PROPERTY_INDEX_DECIMAL_DIGIT:
 333         return UC_PROPERTY_DECIMAL_DIGIT;
 334       case UC_PROPERTY_INDEX_NUMERIC:
 335         return UC_PROPERTY_NUMERIC;
 336       case UC_PROPERTY_INDEX_DIACRITIC:
 337         return UC_PROPERTY_DIACRITIC;
 338       case UC_PROPERTY_INDEX_EXTENDER:
 339         return UC_PROPERTY_EXTENDER;
 340       case UC_PROPERTY_INDEX_IGNORABLE_CONTROL:
 341         return UC_PROPERTY_IGNORABLE_CONTROL;
 342       default:
 343         abort ();
 344       }
 345  invalid:
 346   return UC_PROPERTY_NONE;
 347 }

/* [previous][next][first][last][top][bottom][index][help] */