33#ifndef _UCOMMON_UNICODE_H_
34#define _UCOMMON_UNICODE_H_
36#ifndef _UCOMMON_STRING_H_
83 static const char *
nil;
90 static unsigned size(
const char *codepoint);
97 static size_t count(
const char *
string);
105 static char *
offset(
char *
string, ssize_t position);
162 static const char *
find(
const char *
string,
ucs4_t character,
size_t start = 0);
171 static const char *
rfind(
const char *
string,
ucs4_t character,
size_t end = (
size_t)-1l);
294 return get(unicode, size);
311 return operator()(0, size);
320 return operator()(-((
int)offset), 0);
330 return operator()((
int)offset, size);
338 void cut(
size_t offset,
size_t size = 0);
346 void paste(
size_t offset,
const char *text,
size_t size = 0);
363 return UString::at(position);
371 return (
size_t)utf8::count(str->text);
470 inline operator bool()
const {
512 return (
const char *)text == string;
521 return (
const char *)text != string;
529 return utf8::codepoint((
const char *)text);
544 inline operator char*()
const {
552 inline size_t len(
void)
const {
553 return utf8::count((
const char *)text);
557inline ucs4_t *strudup(
const char *
string) {
561inline ucs2_t *strwdup(
const char *
string) {
565__EXPORT
unicode_t unidup(
const char *
string);
568inline void dupfree<ucs2_t*>(
ucs2_t *
string) {
573inline void dupfree<ucs4_t*>(
ucs4_t *
string) {
578inline void dupfree<unicode_t>(
unicode_t string) {
Common namespace for all ucommon objects.
UString ustring_t
Convenience type for utf8 encoded strings.
utf8_pointer utf8_t
Convenience type for utf8_pointer strings.
T copy(const T &src)
Convenience function to copy objects.
int32_t ucs4_t
32 bit unicode character code.
int16_t ucs2_t
16 bit unicode character code.
void * unicode_t
Resolves issues where wchar_t is not defined.
A copy-on-write string class that operates by reference count.
A core class of ut8 encoded string functions.
static ucs4_t get(const char *cp)
Get a unicode character from a character protocol.
static size_t chars(ucs4_t character)
How many chars requires to encode a given unicode character.
static void put(ucs4_t character, char *buf)
Push a unicode character to a character protocol.
static size_t count(const char *string)
Count ut8 encoded ucs4 codepoints in string.
static const char * nil
A convenient NULL pointer value.
static char * offset(char *string, ssize_t position)
Get codepoint offset in a string.
static ucs2_t * wdup(const char *string)
Dup a utf8 string into a ucs2_t representation.
static const unsigned ucsize
Size of "unicode_t" character codes, may not be ucs4_t size.
static unsigned ccount(const char *string, ucs4_t character)
Count occurrences of a unicode character in string.
static unsigned size(const char *codepoint)
Compute character size of utf8 string codepoint.
static const char * rfind(const char *string, ucs4_t character, size_t end=(size_t) -1l)
Find last occurrence of character in string.
static ucs4_t codepoint(const char *encoded)
Convert a utf8 encoded codepoint to a ucs4 character value.
static const char * find(const char *string, ucs4_t character, size_t start=0)
Find first occurance of character in string.
static size_t chars(const unicode_t string)
How many chars requires to encode a given wchar string.
static size_t unpack(const unicode_t string, char *text, size_t size)
Convert a unicode string into utf8.
static ucs4_t * udup(const char *string)
Dup a utf8 string into a ucs4_t string.
static size_t pack(unicode_t unicode, const char *cp, size_t len)
Convert a utf8 string into a unicode data buffer.
A copy-on-write utf8 string class that operates by reference count.
const char * find(ucs4_t character, size_t start=0) const
Find first occurrence of character in string.
UString(size_t size)
Create an empty string with a buffer pre-allocated to a specified size.
void set(const unicode_t unicode)
Set a utf8 encoded string based on unicode data.
UString operator()(int codepoint, size_t size) const
Get a new substring through object expression.
UString(const unicode_t *text, const unicode_t *end)
Create a string for a substring.
virtual ~UString()
Destroy string.
ucs4_t at(int position) const
Return unicode character found at a specific codepoint in the string.
size_t get(unicode_t unicode, size_t size) const
Extract a unicode byte sequence from utf8 object.
UString(const unicode_t text)
Create a utf8 aware string for a null terminated unicode string.
void cut(size_t offset, size_t size=0)
Cut (remove) text from string using codepoint offsets.
UString left(size_t size) const
Convenience method for left of string.
size_t count(void) const
Count codepoints in current string.
size_t operator()(unicode_t unicode, size_t size) const
Extract a unicode byte sequence from utf8 object.
UString(const char *text, size_t size)
Create a string from null terminated text up to a maximum specified size.
UString(const UString &existing)
Construct a copy of a string object.
const char * operator()(int offset) const
Reference a string in the object by codepoint offset.
ucs4_t operator[](int position) const
Reference a unicode character in string object by array offset.
UString copy(size_t offset, size_t size) const
Convenience method for substring extraction.
UString get(size_t codepoint, size_t size=0) const
Get a new string object as a substring of the current object.
void add(const unicode_t unicode)
Add (append) unicode to a utf8 encoded string.
void paste(size_t offset, const char *text, size_t size=0)
Insert (paste) text into string using codepoint offsets.
const char * rfind(ucs4_t character, size_t end=npos) const
Find last occurrence of character in string.
UString right(size_t offset) const
Convenience method for right of string.
unsigned ccount(ucs4_t character) const
Count occurrences of a unicode character in string.
UString()
Create a new empty utf8 aware string object.
Pointer to utf8 encoded character data.
utf8_pointer operator-(long offset) const
Get new utf8 string after subtracting a codepoint offset.
void inc(void)
Iterative increment of a utf8 pointer to next codepoint.
ucs4_t operator[](long codepoint) const
Extract a unicode character from a specified codepoint.
size_t len(void) const
Get length of null terminated utf8 string in codepoints.
bool operator==(const char *string) const
check if pointer equals another string.
char * c_str(void) const
Get c string we point to.
utf8_pointer operator+(long offset) const
Get new utf8 string after adding a codepoint offset.
utf8_pointer & operator=(const char *string)
Assign a utf8 string to point to.
bool operator!() const
Check if text is an invalid pointer.
utf8_pointer(const utf8_pointer ©)
Create a utf8 pointer as a copy of existing utf8 pointer.
ucs4_t operator*() const
Get unicode character pointed to by pointer.
bool operator!=(const char *string) const
check if pointer does not equal another string.
void dec(void)
Iterative decrement of a utf8 pointer to prior codepoint.
utf8_pointer(const char *string)
Create a utf8 pointer for an existing char pointer.
utf8_pointer()
Create a utf8 pointer set to NULL.
A common string class and character string support functions.