summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-27 07:02:45 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-27 07:02:45 +0000
commit1718ecd06e6bb305385e5dea79c5649af6e9470a (patch)
tree9a9e7fb3f1243d73765d17f33740518897f1c9b1
parent94e5f742581f4b670cdb6ca09c18c86ce05629a9 (diff)
Utf8CheckString moved from dbtool to mir_core
git-svn-id: http://svn.miranda-ng.org/main/trunk@1207 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--bin10/lib/mir_core.libbin29038 -> 29258 bytes
-rw-r--r--bin10/lib/mir_core64.libbin26524 -> 26726 bytes
-rw-r--r--include/m_core.h3
-rw-r--r--src/mir_core/mir_core.def1
-rw-r--r--src/mir_core/utf.cpp45
5 files changed, 48 insertions, 1 deletions
diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib
index feea4859f1..447d28d1e7 100644
--- a/bin10/lib/mir_core.lib
+++ b/bin10/lib/mir_core.lib
Binary files differ
diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib
index afde07408a..e8f3620a49 100644
--- a/bin10/lib/mir_core64.lib
+++ b/bin10/lib/mir_core64.lib
Binary files differ
diff --git a/include/m_core.h b/include/m_core.h
index 249aca42aa..e0534750be 100644
--- a/include/m_core.h
+++ b/include/m_core.h
@@ -497,9 +497,10 @@ MIR_CORE_DLL(char*) Utf8Encode(const char* str);
MIR_CORE_DLL(char*) Utf8EncodeCP(const char* src, int codepage);
MIR_CORE_DLL(char*) Utf8EncodeW(const wchar_t* str);
-
MIR_CORE_DLL(int) Ucs2toUtf8Len(const wchar_t *src);
+MIR_CORE_DLL(BOOL) Utf8CheckString(const char* str);
+
#define Utf8DecodeT Utf8DecodeW
#define Utf8EncodeT Utf8EncodeW
diff --git a/src/mir_core/mir_core.def b/src/mir_core/mir_core.def
index 41585d0845..66324ec1ed 100644
--- a/src/mir_core/mir_core.def
+++ b/src/mir_core/mir_core.def
@@ -129,3 +129,4 @@ replaceStrW @126
db_setCurrent @127
CmdLine_GetOption @128
CmdLine_Parse @129
+Utf8CheckString @130
diff --git a/src/mir_core/utf.cpp b/src/mir_core/utf.cpp
index ddf2d1ca9f..a9e7145973 100644
--- a/src/mir_core/utf.cpp
+++ b/src/mir_core/utf.cpp
@@ -404,3 +404,48 @@ MIR_CORE_DLL(char*) Utf8EncodeW(const wchar_t* src)
return result;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Utf8Encode - converts UCS2 string to the UTF8-encoded format
+
+MIR_CORE_DLL(BOOL) Utf8CheckString(const char* str)
+{
+ int expect_bytes = 0, utf_found = 0;
+
+ if (!str) return 0;
+
+ while (*str) {
+ if ((*str & 0x80) == 0) {
+ /* Looks like an ASCII character */
+ if (expect_bytes)
+ /* byte of UTF-8 character expected */
+ return 0;
+ }
+ else {
+ /* Looks like byte of an UTF-8 character */
+ if (expect_bytes) {
+ /* expect_bytes already set: first byte of UTF-8 char already seen */
+ if ((*str & 0xC0) != 0x80) {
+ /* again first byte ?!?! */
+ return 0;
+ }
+ }
+ else {
+ /* First byte of the UTF-8 character */
+ /* count initial one bits and set expect_bytes to 1 less */
+ char ch = *str;
+ while (ch & 0x80) {
+ expect_bytes++;
+ ch = (ch & 0x7f) << 1;
+ }
+ }
+ /* OK, next byte of UTF-8 character */
+ /* Decrement number of expected bytes */
+ if (--expect_bytes == 0)
+ utf_found = 1;
+ }
+ str++;
+ }
+
+ return (utf_found && expect_bytes == 0);
+}