From e7c4a0554c3bbe6c33660dc445df7dc8f78c2ce1 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 9 Oct 2006 09:15:37 +0000 Subject: [PATCH] more unicode work. * 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 | 31 +++++++++++++++++-------------- src/support/lstrings.C | 19 +++++++++++++++++++ src/support/lstrings.h | 7 +++++++ 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/frontends/qt4/validators.C b/src/frontends/qt4/validators.C index 0f388d58f7..1f98e12252 100644 --- a/src/frontends/qt4/validators.C +++ b/src/frontends/qt4/validators.C @@ -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 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; diff --git a/src/support/lstrings.C b/src/support/lstrings.C index a142dae8fb..bbee125ef7 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -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); diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 18a35ff5bc..e6087cf498 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -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". -- 2.39.2