]> git.lyx.org Git - lyx.git/blobdiff - src/support/lstrings.C
Make it possible to uses non-ascii labelstring, endlabelstring and
[lyx.git] / src / support / lstrings.C
index a844f2214bcac5749cd0dad0cfe826b9ec74b061..939d48531b78e621422d5a2a2ee8bc2fad22d9e9 100644 (file)
@@ -226,6 +226,69 @@ bool isStrDbl(string const & str)
 }
 
 
+namespace {
+
+inline
+bool isHexChar(char_type c)
+{
+       return c == '0' ||
+               c == '1' ||
+               c == '2' ||
+               c == '3' ||
+               c == '4' ||
+               c == '5' ||
+               c == '6' ||
+               c == '7' ||
+               c == '8' ||
+               c == '9' ||
+               c == 'a' || c == 'A' ||
+               c == 'b' || c == 'B' ||
+               c == 'c' || c == 'C' ||
+               c == 'd' || c == 'D' ||
+               c == 'e' || c == 'E' ||
+               c == 'f' || c == 'F';
+}
+
+} // anon namespace
+
+
+bool isHex(docstring const & str)
+{
+       int index = 0;
+
+       if (str.length() > 2 && str[0] == '0' &&
+           (str[1] == 'x' || str[1] == 'X'))
+               index = 2;
+
+       int const len = str.length();
+
+       for (; index < len; ++index) {
+               if (!isHexChar(str[index]))
+                       return false;
+       }
+       return true;
+}
+
+
+int hexToInt(docstring const & str)
+{
+       string s = to_ascii(str);
+       int h;
+       sscanf(s.c_str(), "%x", &h);
+       return h;
+}
+
+
+bool isAscii(docstring const & str)
+{
+       int const len = str.length();
+       for (int i = 0; i < len; ++i)
+               if (str[i] >= 0x80)
+                       return false;
+       return true;
+}
+
+
 char lowercase(char c)
 {
        return char(tolower(c));