mirror of
https://review.haiku-os.org/haiku
synced 2025-01-20 05:21:28 +01:00
7220b138f2
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12750 a95241bf-73f2-0310-859d-f6bbb57e9c96
74 lines
1.0 KiB
C
74 lines
1.0 KiB
C
#ifndef __MOREUTF8
|
|
#define __MOREUTF8
|
|
|
|
|
|
static inline bool
|
|
IsInsideGlyph(uchar ch)
|
|
{
|
|
return (ch & 0xC0) == 0x80;
|
|
}
|
|
|
|
|
|
static inline uint32
|
|
UTF8NextCharLen(const char *text)
|
|
{
|
|
const char *ptr = text;
|
|
|
|
if (ptr == NULL || *ptr == 0)
|
|
return 0;
|
|
|
|
do {
|
|
ptr++;
|
|
} while (IsInsideGlyph(*ptr));
|
|
|
|
return ptr - text;
|
|
}
|
|
|
|
static inline uint32
|
|
UTF8PreviousCharLen(const char *text, const char *limit)
|
|
{
|
|
const char *ptr = text;
|
|
|
|
if (ptr == NULL || limit == NULL)
|
|
return 0;
|
|
|
|
do {
|
|
if (ptr == limit)
|
|
break;
|
|
ptr--;
|
|
} while (IsInsideGlyph(*ptr));
|
|
|
|
return text - ptr;
|
|
}
|
|
|
|
static inline uint32
|
|
UTF8CountBytes(const char *text, uint32 numChars)
|
|
{
|
|
const char *ptr = text;
|
|
|
|
while (numChars) {
|
|
ptr += UTF8NextCharLen(ptr);
|
|
numChars--;
|
|
}
|
|
|
|
return ptr - text;
|
|
}
|
|
|
|
static inline uint32
|
|
UTF8CountChars(const char *text, int32 numBytes)
|
|
{
|
|
const char* ptr = text;
|
|
const char* last = ptr + numBytes - 1;
|
|
|
|
uint32 count = 0;
|
|
while (ptr <= last) {
|
|
ptr += UTF8NextCharLen(ptr);
|
|
count++;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
|
|
#endif
|