From 00843bd5e3981abe0fffac4f322e5f8f58e4591c Mon Sep 17 00:00:00 2001 From: seife Date: Sun, 1 Jan 2012 11:57:20 +0000 Subject: [PATCH] lcdd: add isUTF8() from edvbstring git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-beta@2028 e54a6e83-5905-42d5-8d5c-058d10e6a962 --- src/driver/lcdd.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/driver/lcdd.cpp b/src/driver/lcdd.cpp index 90dbd6785..be4a1e0e1 100644 --- a/src/driver/lcdd.cpp +++ b/src/driver/lcdd.cpp @@ -53,6 +53,38 @@ #include extern CRemoteControl * g_RemoteControl; /* neutrino.cpp */ +/* from edvbstring.cpp */ +static bool isUTF8(const std::string &string) +{ + unsigned int len=string.size(); + + for (unsigned int i=0; i < len; ++i) + { + if (!(string[i]&0x80)) // normal ASCII + continue; + if ((string[i] & 0xE0) == 0xC0) // one char following. + { + // first, length check: + if (i+1 >= len) + return false; // certainly NOT utf-8 + i++; + if ((string[i]&0xC0) != 0x80) + return false; // no, not UTF-8. + } else if ((string[i] & 0xF0) == 0xE0) + { + if ((i+1) >= len) + return false; + i++; + if ((string[i]&0xC0) != 0x80) + return false; + i++; + if ((string[i]&0xC0) != 0x80) + return false; + } + } + return true; // can be UTF8 (or pure ASCII, at least no non-UTF-8 8bit characters) +} + CLCD::CLCD() : configfile('\t') {