namespace {
- int ascii_tolower(int c) {
- if (c >= 'A' && c <= 'Z')
- return c - 'A' + 'a';
- return c;
- }
+
+int ascii_tolower(int c) {
+ if (c >= 'A' && c <= 'Z')
+ return c - 'A' + 'a';
+ return c;
}
-int compare_ascii_no_case(string const & s, string const & s2)
+template<typename String> inline
+int do_compare_ascii_no_case(String const & s, String const & s2)
{
- string::const_iterator p = s.begin();
- string::const_iterator p2 = s2.begin();
+ typename String::const_iterator p = s.begin();
+ typename String::const_iterator p2 = s2.begin();
while (p != s.end() && p2 != s2.end()) {
int const lc1 = ascii_tolower(*p);
return 1;
}
+}
+
+
+int compare_ascii_no_case(string const & s, string const & s2)
+{
+ return do_compare_ascii_no_case(s, s2);
+}
+
+
+int compare_ascii_no_case(docstring const & s, docstring const & s2)
+{
+ return do_compare_ascii_no_case(s, s2);
+}
+
int compare_no_case(string const & s, string const & s2, unsigned int len)
{
}
+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));
}
+bool prefixIs(docstring const & a, docstring const & pre)
+{
+ docstring::size_type const prelen = pre.length();
+ docstring::size_type const alen = a.length();
+
+ if (prelen > alen || a.empty())
+ return false;
+ else
+ return a.compare(0, prelen, pre) == 0;
+}
+
+
bool suffixIs(string const & a, char c)
{
if (a.empty()) return false;
namespace {
+/// Substitute all \a oldchar with \a newchar
template<typename Ch> inline
std::basic_string<Ch> const subst_char(std::basic_string<Ch> const & a,
Ch oldchar, Ch newchar)
}
+/// substitutes all instances of \a oldstr with \a newstr
template<typename String> inline
String const subst_string(String const & a,
String const & oldstr, String const & newstr)
string const ltrim(string const & a, char const * p)
{
BOOST_ASSERT(p);
-
if (a.empty() || !*p)
return a;
-
string::size_type l = a.find_first_not_of(p);
-
if (l == string::npos)
return string();
-
return a.substr(l, string::npos);
}
+docstring const ltrim(docstring const & a, char const * p)
+{
+ BOOST_ASSERT(p);
+ if (a.empty() || !*p)
+ return a;
+ size_t l = a.find_first_not_of(from_ascii(p));
+ if (l == docstring::npos)
+ return docstring();
+ return a.substr(l, docstring::npos);
+}
+
+namespace {
+
template<typename String, typename Char> inline
String const doSplit(String const & a, String & piece, Char delim)
{
return tmp;
}
+}
+
string const split(string const & a, string & piece, char delim)
{
// This function escapes 8-bit characters and other problematic
// characters that cause problems in latex labels.
-string const escape(string const & lab)
+docstring const escape(docstring const & lab)
{
- char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
+ lyx::char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- string enc;
- for (string::size_type i = 0; i < lab.length(); ++i) {
- unsigned char c= lab[i];
+ docstring enc;
+ for (docstring::size_type i = 0; i < lab.length(); ++i) {
+ lyx::char_type c = lab[i];
+ // FIXME We must change the following algorithm for UCS4
+ // chars, but that will be a file format change.
if (c >= 128 || c == '=' || c == '%') {
enc += '=';
enc += hexdigit[c>>4];