From: Abdelrazak Younes Date: Sun, 3 Sep 2006 14:09:24 +0000 (+0000) Subject: * MSVC compilation fix: replace subst template with subst_char and sub_string X-Git-Tag: 1.6.10~12654 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a6e0f26fe236aa5c4cb15b39da49ca8a2c16ff1b;p=features.git * MSVC compilation fix: replace subst template with subst_char and sub_string * add lowercase() and uppercase() functions for unicode char_type. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14881 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 46072dc6aa..3658249d39 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -198,6 +198,31 @@ char uppercase(char c) return char(toupper(c)); } +// FIXME for lowercase() and uppercase() function below: +// 1) std::tolower() and std::toupper() are templates that +// compile fine with char_type. With the test (c >= 256) we +// do not trust these function to do the right thing with +// unicode char. +// 2) these functions use the current locale, which is wrong +// if it is not latin1 based (latin1 is a subset of UCS4). + +char_type lowercase(char_type c) +{ + if (c >= 256) + return c; + + return tolower(c); +} + + +char_type uppercase(char_type c) +{ + if (c >= 256) + return c; + + return toupper(c); +} + namespace { @@ -341,7 +366,8 @@ int tokenPos(string const & a, char delim, string const & tok) namespace { template inline -std::basic_string const subst(std::basic_string const & a, Ch oldchar, Ch newchar) +std::basic_string const subst_char(std::basic_string const & a, + Ch oldchar, Ch newchar) { typedef std::basic_string String; String tmp(a); @@ -355,8 +381,8 @@ std::basic_string const subst(std::basic_string const & a, Ch oldchar, C template inline -String const subst(String const & a, - String const & oldstr, String const & newstr) +String const subst_string(String const & a, + String const & oldstr, String const & newstr) { BOOST_ASSERT(!oldstr.empty()); String lstr = a; @@ -375,28 +401,28 @@ String const subst(String const & a, string const subst(string const & a, char oldchar, char newchar) { - return subst(a, oldchar, newchar); + return subst_char(a, oldchar, newchar); } docstring const subst(docstring const & a, char_type oldchar, char_type newchar) { - return subst(a, oldchar, newchar); + return subst_char(a, oldchar, newchar); } string const subst(string const & a, string const & oldstr, string const & newstr) { - return subst(a, oldstr, newstr); + return subst_string(a, oldstr, newstr); } docstring const subst(docstring const & a, docstring const & oldstr, docstring const & newstr) { - return subst(a, oldstr, newstr); + return subst_string(a, oldstr, newstr); } diff --git a/src/support/lstrings.h b/src/support/lstrings.h index a7470744ec..5b4266e92f 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -70,6 +70,12 @@ char lowercase(char c); /// char uppercase(char c); +/// changes the case only if c is a one-byte char +char_type lowercase(char_type c); + +/// changes the case only if c is a one-byte char +char_type uppercase(char_type c); + /// same as lowercase(), but ignores locale std::string const ascii_lowercase(std::string const &);