]> git.lyx.org Git - lyx.git/commitdiff
more unicode work.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 9 Oct 2006 09:15:37 +0000 (09:15 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 9 Oct 2006 09:15:37 +0000 (09:15 +0000)
* lstrings.[Ch]: new docstring trim() function

* qt4/validators.C: PathValidator::validate() and printable_list() converted to unicode.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15281 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/validators.C
src/support/lstrings.C
src/support/lstrings.h

index 0f388d58f7ace8dd9c57e0335c523d90d40a0d8f..1f98e122525d1d237cf7d8764054a820dffceb3f 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "frontends/controllers/Dialog.h"
 
+#include "support/docstring.h"
 #include "support/lstrings.h"
 #include "support/std_ostream.h"
 
@@ -30,6 +31,8 @@
 #include <sstream>
 
 using lyx::support::isStrDbl;
+using lyx::docstring;
+
 using std::string;
 
 
@@ -98,23 +101,23 @@ PathValidator::PathValidator(bool acceptable_if_empty,
 
 namespace {
 
-string const printable_list(string const & invalid_chars)
+docstring const printable_list(docstring const & invalid_chars)
 {
-       std::ostringstream ss;
-       string::const_iterator const begin = invalid_chars.begin();
-       string::const_iterator const end = invalid_chars.end();
-       string::const_iterator it = begin;
+       docstring s;
+       docstring::const_iterator const begin = invalid_chars.begin();
+       docstring::const_iterator const end = invalid_chars.end();
+       docstring::const_iterator it = begin;
 
        for (; it != end; ++it) {
                if (it != begin)
-                       ss << ", ";
-               if (*it == ' ')
-                       ss << lyx::to_utf8(_("space"));
+                       s += lyx::from_ascii(", ");
+               if (*it == lyx::char_type(' '))
+                       s += _("space");
                else
-                       ss << *it;
+                       s += *it;
        }
 
-       return ss.str();
+       return s;
 }
 
 } // namespace anon
@@ -125,22 +128,22 @@ QValidator::State PathValidator::validate(QString & qtext, int &) const
        if (!latex_doc_)
                return QValidator::Acceptable;
 
-       string const text = lyx::support::trim(fromqstr(qtext));
+       docstring const text = lyx::support::trim(qstring_to_ucs4(qtext));
        if (text.empty())
                return  acceptable_if_empty_ ?
                        QValidator::Acceptable : QValidator::Intermediate;
 
-       string invalid_chars("#$%{}()[]\"^");
+       docstring invalid_chars = lyx::from_ascii("#$%{}()[]\"^");
        if (!tex_allows_spaces_)
                invalid_chars += ' ';
 
-       if (text.find_first_of(invalid_chars) != string::npos) {
+       if (text.find_first_of(invalid_chars) != docstring::npos) {
 
                static int counter = 0;
                if (counter == 0) {
                        lyx::frontend::Alert::error(_("Invalid filename"),
                                     _("LyX does not provide LateX support for file names containing any of these characters:\n") +
-                                        lyx::from_utf8(printable_list(invalid_chars)));
+                                        printable_list(invalid_chars));
                }
                ++counter;
                return QValidator::Intermediate;
index a142dae8fb7dc50d5d63dcee42c570240ecf36a7..bbee125ef7f64a5d2c09de91f06b69da078bbcce 100644 (file)
@@ -472,6 +472,25 @@ docstring const subst(docstring const & a,
 }
 
 
+docstring const trim(docstring const & a, char const * p)
+{
+       BOOST_ASSERT(p);
+
+       if (a.empty() || !*p)
+               return a;
+
+       docstring s = lyx::from_ascii(p);
+       docstring::size_type r = a.find_last_not_of(s);
+       docstring::size_type l = a.find_first_not_of(s);
+
+       // Is this the minimal test? (lgb)
+       if (r == docstring::npos && l == docstring::npos)
+               return docstring();
+
+       return a.substr(l, r - l + 1);
+}
+
+
 string const trim(string const & a, char const * p)
 {
        BOOST_ASSERT(p);
index 18a35ff5bc176e8ebc9c6baf0a73455552bf42c9..e6087cf498457c6d2afb992bbc7ead3b5805a595 100644 (file)
@@ -151,6 +151,13 @@ std::string const subst(std::string const & a,
 lyx::docstring const subst(lyx::docstring const & a,
                lyx::docstring const & oldstr, lyx::docstring const & newstr);
 
+/** Trims characters off the end and beginning of a string.
+    \code
+    trim("ccabccc", "c") == "ab".
+    \endcode
+*/
+lyx::docstring const trim(lyx::docstring const & a, char const * p = " ");
+
 /** Trims characters off the end and beginning of a string.
     \code
     trim("ccabccc", "c") == "ab".