]> git.lyx.org Git - features.git/commitdiff
* MSVC compilation fix: replace subst template with subst_char and sub_string
authorAbdelrazak Younes <younes@lyx.org>
Sun, 3 Sep 2006 14:09:24 +0000 (14:09 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 3 Sep 2006 14:09:24 +0000 (14:09 +0000)
* 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

src/support/lstrings.C
src/support/lstrings.h

index 46072dc6aa26060ff1c4225eb3d9637ee3d62f19..3658249d397be30f237ad035e796203f195ff53d 100644 (file)
@@ -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<typename Ch> inline
-std::basic_string<Ch> const subst(std::basic_string<Ch> const & a, Ch oldchar, Ch newchar)
+std::basic_string<Ch> const subst_char(std::basic_string<Ch> const & a,
+               Ch oldchar, Ch newchar)
 {
        typedef std::basic_string<Ch> String;
        String tmp(a);
@@ -355,8 +381,8 @@ std::basic_string<Ch> const subst(std::basic_string<Ch> const & a, Ch oldchar, C
 
 
 template<typename String> 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<char>(a, oldchar, newchar);
+       return subst_char(a, oldchar, newchar);
 }
 
 
 docstring const subst(docstring const & a,
                char_type oldchar, char_type newchar)
 {
-       return subst<char_type>(a, oldchar, newchar);
+       return subst_char(a, oldchar, newchar);
 }
 
 
 string const subst(string const & a,
                string const & oldstr, string const & newstr)
 {
-       return subst<string>(a, oldstr, newstr);
+       return subst_string(a, oldstr, newstr);
 }
 
 
 docstring const subst(docstring const & a,
                docstring const & oldstr, docstring const & newstr)
 {
-       return subst<docstring>(a, oldstr, newstr);
+       return subst_string(a, oldstr, newstr);
 }
 
 
index a7470744ec8e2ae27d3b689488a96c0e47cb1af1..5b4266e92f08a9b4a9d032e56d9f82ec4826e8c6 100644 (file)
@@ -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 &);