2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
11 #include <UnicodeChar.h>
27 UTF8Char(const char* c
)
29 SetTo(c
, ByteCount(*c
));
32 UTF8Char(const char* c
, int32 count
)
37 void SetTo(const char* c
, int32 count
)
50 static int32
ByteCount(char firstChar
)
52 // Note, this does not recognize invalid chars
58 return c
< 0xf0 ? 3 : 4;
61 int32
ByteCount() const
63 return ByteCount(bytes
[0]);
66 bool IsFullWidth() const
68 switch (BUnicodeChar::EastAsianWidth(BUnicodeChar::FromUTF8(bytes
))) {
69 case B_UNICODE_EA_FULLWIDTH
:
70 case B_UNICODE_EA_WIDE
:
80 return BUnicodeChar::IsSpace(BUnicodeChar::FromUTF8(bytes
));
85 return BUnicodeChar::IsAlNum(BUnicodeChar::FromUTF8(bytes
));
88 UTF8Char
ToLower() const
90 uint32 c
= BUnicodeChar::ToLower(BUnicodeChar::FromUTF8(bytes
));
93 char* utf8
= character
.bytes
;
94 BUnicodeChar::ToUTF8(c
, &utf8
);
99 bool operator==(const UTF8Char
& other
) const
101 int32 byteCount
= ByteCount();
102 bool equals
= bytes
[0] == other
.bytes
[0];
103 if (byteCount
> 1 && equals
) {
104 equals
= bytes
[1] == other
.bytes
[1];
105 if (byteCount
> 2 && equals
) {
106 equals
= bytes
[2] == other
.bytes
[2];
107 if (byteCount
> 3 && equals
)
108 equals
= bytes
[3] == other
.bytes
[3];
114 bool operator!=(const UTF8Char
& other
) const
116 return !(*this == other
);
121 #endif // UTF8_CHAR_H