Reviewed by Maciej.
[WebKit-https.git] / JavaScriptCore / kxmlcore / unicode / icu / UnicodeIcu.h
1 // -*- c-basic-offset: 2 -*-
2 /*
3  *  This file is part of the KDE libraries
4  *  Copyright (C) 2006 George Staikos <staikos@kde.org>
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public License
17  *  along with this library; see the file COPYING.LIB.  If not, write to
18  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301, USA.
20  *
21  */
22
23 #ifndef KJS_UNICODE_ICU_H
24 #define KJS_UNICODE_ICU_H
25
26 #include <unicode/uchar.h>
27
28 #include "../UnicodeCategory.h"
29
30 namespace KXMLCore {
31   namespace Unicode {
32     inline unsigned short toLower(unsigned short c) {
33       return u_tolower(c);
34     }
35
36     inline unsigned short toUpper(unsigned short c) {
37       return u_toupper(c);
38     }
39
40     inline bool isFormatChar(unsigned short c) {
41       return u_charType(c) == U_FORMAT_CHAR;
42     }
43
44     inline bool isSeparatorSpace(unsigned short c) {
45       return u_charType(c) == U_SPACE_SEPARATOR;
46     }
47
48     inline CharCategory category(unsigned short c) {
49       switch (u_charType(c)) {
50         case U_NON_SPACING_MARK:
51           return Mark_NonSpacing;
52         case U_COMBINING_SPACING_MARK:
53           return Mark_SpacingCombining;
54         case U_ENCLOSING_MARK:
55           return Mark_Enclosing;
56         case U_DECIMAL_DIGIT_NUMBER:
57           return Number_DecimalDigit;
58         case U_LETTER_NUMBER:
59           return Number_Letter;
60         case U_OTHER_NUMBER:
61           return Number_Other;
62         case U_SPACE_SEPARATOR:
63           return Separator_Space;
64         case U_LINE_SEPARATOR:
65           return Separator_Line;
66         case U_PARAGRAPH_SEPARATOR:
67           return Separator_Paragraph;
68         case U_CONTROL_CHAR:
69           return Other_Control;
70         case U_FORMAT_CHAR:
71           return Other_Format;
72         case U_SURROGATE:
73           return Other_Surrogate;
74         case U_PRIVATE_USE_CHAR:
75           return Other_PrivateUse;
76         case U_GENERAL_OTHER_TYPES:
77           return Other_NotAssigned;
78         case U_UPPERCASE_LETTER:
79           return Letter_Uppercase;
80         case U_LOWERCASE_LETTER:
81           return Letter_Lowercase;
82         case U_TITLECASE_LETTER:
83           return Letter_Titlecase;
84         case U_MODIFIER_LETTER:
85           return Letter_Modifier;
86         case U_OTHER_LETTER:
87           return Letter_Other;
88         case U_CONNECTOR_PUNCTUATION:
89           return Punctuation_Connector;
90         case U_DASH_PUNCTUATION:
91           return Punctuation_Dash;
92         case U_START_PUNCTUATION:
93           return Punctuation_Open;
94         case U_END_PUNCTUATION:
95           return Punctuation_Close;
96         case U_INITIAL_PUNCTUATION:
97           return Punctuation_InitialQuote;
98         case U_FINAL_PUNCTUATION:
99           return Punctuation_FinalQuote;
100         case U_OTHER_PUNCTUATION:
101           return Punctuation_Other;
102         case U_MATH_SYMBOL:
103           return Symbol_Math;
104         case U_CURRENCY_SYMBOL:
105           return Symbol_Currency;
106         case U_MODIFIER_SYMBOL:
107           return Symbol_Modifier;
108         case U_OTHER_SYMBOL:
109           return Symbol_Other;
110         default:
111           return NoCategory;
112       }
113     }
114   }
115 }
116
117 #endif
118 // vim: ts=2 sw=2 et