UCommon
unicode.cpp
An example of some unicode-utf8 transcoding.
// Copyright (C) 2009-2014 David Sugar, Tycho Softworks.
// Copyright (C) 2015 Cherokees of Idaho.
//
// This file is part of GNU uCommon C++.
//
// GNU uCommon C++ is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU uCommon C++ 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
#ifndef DEBUG
#define DEBUG
#endif
#include <
ucommon/ucommon.h
>
#include <stdio.h>
using namespace
ucommon
;
extern
"C"
int
main()
{
char
u1[] = {(char)0xc2, (
char
)0xa9, 0x00};
char
u2[] = {(char)0xe2, (
char
)0x89, (char)0xa0, 0x00};
assert(
utf8::size
(u1) == 2);
assert(
utf8::size
(u2) == 3);
assert(
utf8::count
(u1) == 1);
assert(
utf8::count
(u2) == 1);
assert(
utf8::codepoint
(u1) == 0x00a9);
assert(
utf8::codepoint
(u2) == 0x2260);
return
0;
}
ucommon
Common namespace for all ucommon objects.
Definition:
access.h:47
ucommon::utf8::count
static size_t count(const char *string)
Count ut8 encoded ucs4 codepoints in string.
ucommon.h
Top level include file for the GNU uCommon C++ core library.
ucommon::utf8::size
static unsigned size(const char *codepoint)
Compute character size of utf8 string codepoint.
ucommon::utf8::codepoint
static ucs4_t codepoint(const char *encoded)
Convert a utf8 encoded codepoint to a ucs4 character value.
Generated by
1.8.20