1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Unicode.hh for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000, 2002 - 2005
5 // Bradley T Hughes <bhughes at trolltech.com>
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
33 * Returns true if the system supports Unicode conversions.
38 * Unicode character type.
40 typedef unsigned int Uchar
;
43 * Unicode string type.
45 typedef std::basic_string
<Uchar
> ustring
;
48 * Converts multibyte locale-encoded string to wide-char Unicode
49 * string (aka UTF-32).
51 ustring
toUnicode(const std::string
&string
);
54 * Converts wide-char Unicode string (aka UTF-32) to multibyte
55 * locale-encoded string.
57 std::string
toLocale(const ustring
&string
);
60 * Converts UTF-32 to UTF-8.
62 std::string
toUtf8(const ustring
&utf32
);
65 * Convert UTF-8 to UTF-32.
67 ustring
toUtf32(const std::string
&utf8
);
72 * Workaround incomplete std::char_traits<> implementation in come
73 * versions of the GNU C++ compiler.
75 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
80 struct char_traits
<bt::Uchar
>
82 typedef bt::Uchar char_type
;
83 typedef unsigned int int_type
;
84 typedef streampos pos_type
;
85 typedef streamoff off_type
;
86 typedef mbstate_t state_type
;
89 assign(bt::Uchar
&c1
, const bt::Uchar
&c2
)
93 eq(const bt::Uchar
&c1
, const bt::Uchar
&c2
)
97 lt(const bt::Uchar
&c1
, const bt::Uchar
&c2
)
101 compare(const bt::Uchar
*s1
, const bt::Uchar
*s2
, size_t n
) {
102 for (size_t x
= 0; x
< n
; ++x
) {
103 if (lt(s1
[x
], s2
[x
]))
105 if (lt(s2
[x
], s1
[x
]))
112 length(const bt::Uchar
*s
)
115 while (!eq(s
[x
], bt::Uchar()))
120 static const bt::Uchar
*
121 find(const bt::Uchar
*s
, std::size_t n
, const bt::Uchar
&c
)
123 for (std::size_t x
= 0; x
< n
; ++x
)
130 move(bt::Uchar
*d
, const bt::Uchar
*s
, std::size_t n
) {
131 return (static_cast<bt::Uchar
*>
132 (std::memmove(d
, s
, n
*sizeof(bt::Uchar
))));
136 copy(bt::Uchar
*d
, const bt::Uchar
*s
, std::size_t n
) {
137 std::copy(s
, s
+ n
, d
);
142 assign(bt::Uchar
*s
, std::size_t n
, bt::Uchar c
) {
143 std::fill_n(s
, n
, c
);
148 to_char_type(const unsigned int &c
)
152 to_int_type(const bt::Uchar
&c
)
156 eq_int_type(const unsigned int &c1
, const unsigned int &c2
)
161 { return static_cast<unsigned int>(EOF
); }
164 not_eof(const unsigned int &c
)
165 { return (c
== eof()) ? 0 : c
; }
170 # endif // __GNUC__ == 3
171 #endif // __GNUC__ && !__INTEL_COMPILER
173 #endif // __Unicode_hh