summaryrefslogtreecommitdiff
path: root/glib/src/unicode.hg
blob: 867529386107aceb8cc1f8306520d992031889cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* $Id: unicode.hg,v 1.2 2003/08/20 10:31:23 murrayc Exp $ */

/* Copyright (C) 2002 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

_DEFS(glibmm,glib)

#m4begin
_PUSH()

// m4 helper macros to generate the character-class inline functions.

m4_define(`_UNICHAR_FUNC',`dnl
inline $1 $2(gunichar uc)
  { return g_unichar_$2(uc); }
`'dnl`'')

//MSVC++ needs the != 0 to avoid an int -> bool cast warning.
m4_define(`_UNICHAR_FUNC_BOOL',`dnl
inline $1 $2(gunichar uc)
  { return (g_unichar_$2(uc) != 0); }
`'dnl`'')

m4_define(`_ASCII_FUNC',`dnl
inline $1 $2(char c)
  { return g_ascii_$2(c); }
`'dnl`'')

_POP()
#m4end

#include <glib.h>

// Not used, but we want to get rid of possible <ctype.h> macros.
#include <cctype>

#undef isalnum
#undef isalpha
#undef iscntrl
#undef isdigit
#undef isgraph
#undef islower
#undef isprint
#undef ispunct
#undef isspace
#undef isupper
#undef isxdigit
#undef istitle
#undef isdefined
#undef iswide
#undef toupper
#undef tolower
#undef totitle


namespace Glib
{

_WRAP_ENUM(UnicodeType, GUnicodeType, NO_GTYPE)
_WRAP_ENUM(UnicodeBreakType, GUnicodeBreakType, NO_GTYPE)
_WRAP_ENUM(AsciiType, GAsciiType, NO_GTYPE)
_WRAP_ENUM(NormalizeMode, GNormalizeMode, NO_GTYPE)

/** @defgroup Unicode Unicode Manipulation
 * Functions operating on Unicode characters and UTF-8 strings.
 * @{
 */

namespace Unicode
{

_UNICHAR_FUNC_BOOL(bool, validate)
_UNICHAR_FUNC_BOOL(bool, isalnum)
_UNICHAR_FUNC_BOOL(bool, isalpha)
_UNICHAR_FUNC_BOOL(bool, iscntrl)
_UNICHAR_FUNC_BOOL(bool, isdigit)
_UNICHAR_FUNC_BOOL(bool, isgraph)
_UNICHAR_FUNC_BOOL(bool, islower)
_UNICHAR_FUNC_BOOL(bool, isprint)
_UNICHAR_FUNC_BOOL(bool, ispunct)
_UNICHAR_FUNC_BOOL(bool, isspace)
_UNICHAR_FUNC_BOOL(bool, isupper)
_UNICHAR_FUNC_BOOL(bool, isxdigit)
_UNICHAR_FUNC_BOOL(bool, istitle)
_UNICHAR_FUNC_BOOL(bool, isdefined)
_UNICHAR_FUNC_BOOL(bool, iswide)

_UNICHAR_FUNC(gunichar, toupper)
_UNICHAR_FUNC(gunichar, tolower)
_UNICHAR_FUNC(gunichar, totitle)

_UNICHAR_FUNC(int, digit_value)
_UNICHAR_FUNC(int, xdigit_value)

inline Glib::UnicodeType type(gunichar uc)
  { return static_cast<Glib::UnicodeType>(static_cast<int>(g_unichar_type(uc))); }

inline Glib::UnicodeBreakType break_type(gunichar uc)
  { return static_cast<Glib::UnicodeBreakType>(static_cast<int>(g_unichar_break_type(uc))); }

} // namespace Unicode


namespace Ascii
{

_ASCII_FUNC(bool, isalnum)
_ASCII_FUNC(bool, isalpha)
_ASCII_FUNC(bool, iscntrl)
_ASCII_FUNC(bool, isdigit)
_ASCII_FUNC(bool, isgraph)
_ASCII_FUNC(bool, islower)
_ASCII_FUNC(bool, isprint)
_ASCII_FUNC(bool, ispunct)
_ASCII_FUNC(bool, isspace)
_ASCII_FUNC(bool, isupper)
_ASCII_FUNC(bool, isxdigit)

_ASCII_FUNC(char, tolower)
_ASCII_FUNC(char, toupper)

_ASCII_FUNC(int, digit_value)
_ASCII_FUNC(int, xdigit_value)

} // namespace Ascii


/** @} group Unicode */

} // namespace Glib