From 20d32b2c378e69bb5c70d76ba9a8b18d21fa6c80 Mon Sep 17 00:00:00 2001 From: mahlzeit Date: Tue, 23 Dec 2003 14:07:33 +0000 Subject: [PATCH] There was a conflict on the CVS server between MoreUTF8.h (an old file) and moreUTF8.h, so they were removed by the nice people at SourceForge. I am adding the good file back. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5739 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/BTextView/moreUTF8.h | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/kits/interface/BTextView/moreUTF8.h diff --git a/src/kits/interface/BTextView/moreUTF8.h b/src/kits/interface/BTextView/moreUTF8.h new file mode 100644 index 0000000000..88ca0172f7 --- /dev/null +++ b/src/kits/interface/BTextView/moreUTF8.h @@ -0,0 +1,45 @@ +#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; +} + +#endif