mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Get rid of some locale dependant functions
* src/output_plaintext.C (writePlaintextParagraph): Use compare_ascii_no_case instead of compare_no_case, since the strings to compare are pure ASCII anyway. * src/frontends/qt4/QPrefsDialog.C (setComboxFont): ditto * src/MenuBackend.C (Menu::checkShortcuts): ditto * src/frontends/qt4/QLImage.C (QLImage::loadableFormats): Use ascii_lowercase instead of lowercase since the input is pure ASCII anyway. * src/tex2lyx/text.C (splitLatexLength): ditto * src/support/lstrings.[Ch] (compare_no_case): Get rid of both std::string variants (lowercase): Get rid of std::string variant (uppercase): Change std::string variant to docstring * src/support/tests/regfiles/lstrings: Add new expected output * src/support/tests/lstrings.C: Add tests for docstring functions git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17371 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
7fe43f1aa0
commit
d1f8c007f0
@ -50,7 +50,6 @@
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::compare_no_case;
|
||||
using support::compare_ascii_no_case;
|
||||
using support::contains;
|
||||
using support::makeDisplayPath;
|
||||
@ -401,7 +400,7 @@ void Menu::checkShortcuts() const
|
||||
<< "\" does not contain shortcut `"
|
||||
<< to_utf8(shortcut) << "'." << endl;
|
||||
for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
|
||||
if (!compare_no_case(it2->shortcut(), shortcut)) {
|
||||
if (!compare_ascii_no_case(it2->shortcut(), shortcut)) {
|
||||
lyxerr << "Menu warning: menu entries "
|
||||
<< '"' << to_utf8(it1->fulllabel())
|
||||
<< "\" and \"" << to_utf8(it2->fulllabel())
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "graphics/GraphicsParams.h"
|
||||
|
||||
#include "support/filename.h"
|
||||
#include "support/lstrings.h" // lowercase
|
||||
#include "support/lstrings.h" // ascii_lowercase
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPictureIO>
|
||||
@ -31,7 +31,7 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
using lyx::support::lowercase;
|
||||
using lyx::support::ascii_lowercase;
|
||||
|
||||
using boost::bind;
|
||||
|
||||
@ -89,7 +89,7 @@ Image::FormatList QLImage::loadableFormats()
|
||||
|
||||
lyxerr[Debug::GRAPHICS] << (const char *) *it << ", ";
|
||||
|
||||
string ext = lowercase((const char *) *it);
|
||||
string ext = ascii_lowercase((const char *) *it);
|
||||
|
||||
// special case
|
||||
if (ext == "jpeg")
|
||||
|
@ -56,7 +56,7 @@
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using lyx::support::compare_no_case;
|
||||
using lyx::support::compare_ascii_no_case;
|
||||
using lyx::support::os::external_path;
|
||||
using lyx::support::os::external_path_list;
|
||||
using lyx::support::os::internal_path;
|
||||
@ -110,7 +110,7 @@ void setComboxFont(QComboBox * cb, string const & family, string const & foundry
|
||||
// We count in reverse in order to prefer the Xft foundry
|
||||
for (int i = cb->count() - 1; i >= 0; --i) {
|
||||
pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
|
||||
if (compare_no_case(tmp.first, family) == 0) {
|
||||
if (compare_ascii_no_case(tmp.first, family) == 0) {
|
||||
cb->setCurrentIndex(i);
|
||||
return;
|
||||
}
|
||||
@ -122,7 +122,7 @@ void setComboxFont(QComboBox * cb, string const & family, string const & foundry
|
||||
// We count in reverse in order to prefer the Xft foundry
|
||||
for (int i = cb->count() - 1; i >= 0; --i) {
|
||||
pair<string, string> tmp = parseFontName(fromqstr(cb->itemText(i)));
|
||||
if (compare_no_case(tmp.first, tmpfam.first) == 0) {
|
||||
if (compare_ascii_no_case(tmp.first, tmpfam.first) == 0) {
|
||||
cb->setCurrentIndex(i);
|
||||
return;
|
||||
}
|
||||
@ -156,7 +156,7 @@ void setComboxFont(QComboBox * cb, string const & family, string const & foundry
|
||||
|
||||
for (int i = 0; i < cb->count(); ++i) {
|
||||
lyxerr << "Looking at " << fromqstr(cb->itemText(i)) << endl;
|
||||
if (compare_no_case(fromqstr(cb->itemText(i)),
|
||||
if (compare_ascii_no_case(fromqstr(cb->itemText(i)),
|
||||
default_font_name) == 0) {
|
||||
cb->setCurrentIndex(i);
|
||||
return;
|
||||
|
@ -29,7 +29,6 @@ namespace lyx {
|
||||
|
||||
using support::ascii_lowercase;
|
||||
using support::compare_ascii_no_case;
|
||||
using support::compare_no_case;
|
||||
using support::contains;
|
||||
using support::FileName;
|
||||
|
||||
@ -91,7 +90,7 @@ void writePlaintextParagraph(Buffer const & buf,
|
||||
|
||||
// First write the layout
|
||||
string const & tmp = par.layout()->name();
|
||||
if (compare_no_case(tmp, "itemize") == 0) {
|
||||
if (compare_ascii_no_case(tmp, "itemize") == 0) {
|
||||
ltype = 1;
|
||||
ltype_depth = depth + 1;
|
||||
} else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
|
||||
|
@ -48,28 +48,6 @@ using std::toupper;
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
|
||||
int compare_no_case(string const & s, string const & s2)
|
||||
{
|
||||
string::const_iterator p = s.begin();
|
||||
string::const_iterator p2 = s2.begin();
|
||||
|
||||
while (p != s.end() && p2 != s2.end()) {
|
||||
int const lc1 = tolower(*p);
|
||||
int const lc2 = tolower(*p2);
|
||||
if (lc1 != lc2)
|
||||
return (lc1 < lc2) ? -1 : 1;
|
||||
++p;
|
||||
++p2;
|
||||
}
|
||||
|
||||
if (s.size() == s2.size())
|
||||
return 0;
|
||||
if (s.size() < s2.size())
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int compare_no_case(docstring const & s, docstring const & s2)
|
||||
{
|
||||
docstring::const_iterator p = s.begin();
|
||||
@ -148,29 +126,6 @@ int compare_ascii_no_case(docstring const & s, docstring const & s2)
|
||||
}
|
||||
|
||||
|
||||
int compare_no_case(string const & s, string const & s2, unsigned int len)
|
||||
{
|
||||
string::const_iterator p = s.begin();
|
||||
string::const_iterator p2 = s2.begin();
|
||||
unsigned int i = 0;
|
||||
while (i < len && p != s.end() && p2 != s2.end()) {
|
||||
int const lc1 = tolower(*p);
|
||||
int const lc2 = tolower(*p2);
|
||||
if (lc1 != lc2)
|
||||
return (lc1 < lc2) ? -1 : 1;
|
||||
++i;
|
||||
++p;
|
||||
++p2;
|
||||
}
|
||||
|
||||
if (s.size() >= len && s2.size() >= len)
|
||||
return 0;
|
||||
if (s.size() < s2.size())
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bool isStrInt(string const & str)
|
||||
{
|
||||
if (str.empty()) return false;
|
||||
@ -335,9 +290,6 @@ namespace {
|
||||
// calls to std::transform yet, we use these helper clases. (Lgb)
|
||||
|
||||
struct local_lowercase {
|
||||
char operator()(char c) const {
|
||||
return tolower(c);
|
||||
}
|
||||
char_type operator()(char_type c) const {
|
||||
if (!is_utf16(c))
|
||||
// We don't know how to lowercase a non-utf16 char
|
||||
@ -347,8 +299,11 @@ struct local_lowercase {
|
||||
};
|
||||
|
||||
struct local_uppercase {
|
||||
char operator()(char c) const {
|
||||
return toupper(c);
|
||||
char_type operator()(char_type c) const {
|
||||
if (!is_utf16(c))
|
||||
// We don't know how to uppercase a non-utf16 char
|
||||
return c;
|
||||
return qchar_to_ucs4(ucs4_to_qchar(c).toUpper());
|
||||
}
|
||||
};
|
||||
|
||||
@ -360,14 +315,6 @@ template<typename Char> struct local_ascii_lowercase {
|
||||
|
||||
} // end of anon namespace
|
||||
|
||||
string const lowercase(string const & a)
|
||||
{
|
||||
string tmp(a);
|
||||
transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase());
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
docstring const lowercase(docstring const & a)
|
||||
{
|
||||
docstring tmp(a);
|
||||
@ -376,9 +323,9 @@ docstring const lowercase(docstring const & a)
|
||||
}
|
||||
|
||||
|
||||
string const uppercase(string const & a)
|
||||
docstring const uppercase(docstring const & a)
|
||||
{
|
||||
string tmp(a);
|
||||
docstring tmp(a);
|
||||
transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase());
|
||||
return tmp;
|
||||
}
|
||||
|
@ -24,10 +24,6 @@
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
|
||||
/// Compare \p s and \p s2, ignoring the case.
|
||||
/// Caution: Depends on the locale
|
||||
int compare_no_case(std::string const & s, std::string const & s2);
|
||||
|
||||
/// Compare \p s and \p s2, ignoring the case.
|
||||
/// Does not depend on the locale.
|
||||
int compare_no_case(docstring const & s, docstring const & s2);
|
||||
@ -38,10 +34,6 @@ int compare_ascii_no_case(std::string const & s, std::string const & s2);
|
||||
/// Compare \p s and \p s2, ignoring the case of ASCII characters only.
|
||||
int compare_ascii_no_case(docstring const & s, docstring const & s2);
|
||||
|
||||
/// Compare the first \p len characters of \p s and \p s2, ignoring the case.
|
||||
/// Caution: Depends on the locale
|
||||
int compare_no_case(std::string const & s, std::string const & s2, unsigned int len);
|
||||
|
||||
///
|
||||
inline
|
||||
int compare(char const * a, char const * b)
|
||||
@ -100,17 +92,13 @@ char_type uppercase(char_type c);
|
||||
std::string const ascii_lowercase(std::string const &);
|
||||
docstring const ascii_lowercase(docstring const &);
|
||||
|
||||
/// Changes the case of \p s to lowercase.
|
||||
/// Caution: Depends on the locale
|
||||
std::string const lowercase(std::string const & s);
|
||||
|
||||
/// Changes the case of \p s to lowercase.
|
||||
/// Does not depend on the locale.
|
||||
docstring const lowercase(docstring const & s);
|
||||
|
||||
/// Changes the case of \p s to uppercase.
|
||||
/// Caution: Depends on the locale
|
||||
std::string const uppercase(std::string const & s);
|
||||
/// Does not depend on the locale.
|
||||
docstring const uppercase(docstring const & s);
|
||||
|
||||
/// Does the string start with this prefix?
|
||||
bool prefixIs(docstring const &, char_type);
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "../lstrings.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace lyx::support;
|
||||
using namespace lyx;
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -13,14 +16,17 @@ namespace lyx {
|
||||
|
||||
void test_lowercase()
|
||||
{
|
||||
cout << to_ascii(docstring(1, lowercase(char_type('A')))) << endl;
|
||||
cout << to_ascii(lowercase(from_ascii("AlLe"))) << endl;
|
||||
cout << lowercase('A') << endl;
|
||||
cout << lowercase("AlLe") << endl;
|
||||
cout << ascii_lowercase("AlLe") << endl;
|
||||
}
|
||||
|
||||
void test_uppercase()
|
||||
{
|
||||
cout << to_ascii(docstring(1, uppercase(char_type('a')))) << endl;
|
||||
cout << to_ascii(uppercase(from_ascii("AlLe"))) << endl;
|
||||
cout << uppercase('a') << endl;
|
||||
cout << uppercase("AlLe") << endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
|
@ -1,4 +1,7 @@
|
||||
a
|
||||
alle
|
||||
a
|
||||
alle
|
||||
A
|
||||
ALLE
|
||||
A
|
||||
|
@ -262,7 +262,7 @@ bool splitLatexLength(string const & len, string & value, string & unit)
|
||||
if (contains(len, '\\'))
|
||||
unit = trim(string(len, i));
|
||||
else
|
||||
unit = lyx::support::lowercase(trim(string(len, i)));
|
||||
unit = support::ascii_lowercase(trim(string(len, i)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user