#include "support/docstring.h"
+#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/qstring_helpers.h"
#include "support/unicode.h"
-#include <locale>
-#include <iostream>
-#include <typeinfo>
-
#include <QFile>
-#include "support/assert.h"
+//Needed in Ubuntu
+#include <typeinfo>
+#if ! defined(USE_WCHAR_T) && defined(__GNUC__)
+#include <locale>
+#include <iostream>
+#endif
using namespace std;
-namespace lyx {
+using lyx::support::isHexChar;
+namespace lyx {
docstring const from_ascii(char const * ascii)
{
docstring s;
- for (char const * c = ascii; *c; ++c) {
- LASSERT(static_cast<unsigned char>(*c) < 0x80, /**/);
- s.push_back(*c);
+ if (int n = strlen(ascii)) {
+ s.resize(n);
+ char_type *d = &s[0];
+ while (--n >= 0) {
+ d[n] = ascii[n];
+ LATTEST(static_cast<unsigned char>(ascii[n]) < 0x80);
+ }
}
return s;
}
{
int const len = ascii.length();
for (int i = 0; i < len; ++i)
- LASSERT(static_cast<unsigned char>(ascii[i]) < 0x80, /**/);
+ LATTEST(static_cast<unsigned char>(ascii[i]) < 0x80);
return docstring(ascii.begin(), ascii.end());
}
string ascii;
ascii.resize(len);
for (int i = 0; i < len; ++i) {
- LASSERT(ucs4[i] < 0x80, /**/);
+ LATTEST(ucs4[i] < 0x80);
ascii[i] = static_cast<char>(ucs4[i]);
}
return ascii;
}
-IconvProcessor & utf8ToUcs4()
-{
- static IconvProcessor iconv(ucs4_codeset, "UTF-8");
- return iconv;
-}
-
-
-
void utf8_to_ucs4(string const & utf8, docstring & ucs4)
{
size_t n = utf8.size();
string const to_utf8(docstring const & ucs4)
{
- vector<char> const utf8 =
- ucs4_to_utf8(ucs4.data(), ucs4.size());
+ vector<char> const utf8 = ucs4_to_utf8(ucs4.data(), ucs4.size());
return string(utf8.begin(), utf8.end());
}
if (s.empty())
return string();
QByteArray const local = toqstr(s).toLocal8Bit();
- if (local.size() == 0)
+ if (local.isEmpty())
throw to_local8bit_failure();
return string(local.begin(), local.end());
}
}
+string const to_iconv_encoding(docstring const & s, string const & encoding)
+{
+ std::vector<char> const encoded =
+ ucs4_to_eightbit(s.data(), s.length(), encoding);
+ return string(encoded.begin(), encoded.end());
+}
+
+
+docstring const from_iconv_encoding(string const & s, string const & encoding)
+{
+ std::vector<char_type> const ucs4 =
+ eightbit_to_ucs4(s.data(), s.length(), encoding);
+ return docstring(ucs4.begin(), ucs4.end());
+}
+
+
docstring const normalize_c(docstring const & s)
{
return qstring_to_ucs4(toqstr(s).normalized(QString::NormalizationForm_C));
lyx::docstring::const_iterator it = l.begin();
lyx::docstring::const_iterator end = l.end();
for (; it != end; ++it, ++r) {
- LASSERT(static_cast<unsigned char>(*r) < 0x80, /**/);
+ LASSERT(static_cast<unsigned char>(*r) < 0x80, return false);
if (!*r)
return false;
if (*it != static_cast<lyx::docstring::value_type>(*r))
{
lyx::docstring s(l);
for (char const * c = r; *c; ++c) {
- LASSERT(static_cast<unsigned char>(*c) < 0x80, /**/);
+ LASSERT(static_cast<unsigned char>(*c) < 0x80, return l);
s.push_back(*c);
}
return s;
{
lyx::docstring s;
for (char const * c = l; *c; ++c) {
- LASSERT(static_cast<unsigned char>(*c) < 0x80, /**/);
+ LASSERT(static_cast<unsigned char>(*c) < 0x80, return r);
s.push_back(*c);
}
s += r;
lyx::docstring operator+(lyx::docstring const & l, char r)
{
- LASSERT(static_cast<unsigned char>(r) < 0x80, /**/);
+ LASSERT(static_cast<unsigned char>(r) < 0x80, return l);
docstring s = l;
s += docstring::value_type(r);
return s;
lyx::docstring operator+(char l, lyx::docstring const & r)
{
- LASSERT(static_cast<unsigned char>(l) < 0x80, /**/);
+ LASSERT(static_cast<unsigned char>(l) < 0x80, return r);
return lyx::docstring::value_type(l) + r;
}
lyx::docstring & operator+=(lyx::docstring & l, char const * r)
{
for (char const * c = r; *c; ++c) {
- LASSERT(static_cast<unsigned char>(*c) < 0x80, /**/);
+ LASSERT(static_cast<unsigned char>(*c) < 0x80, return l);
l.push_back(*c);
}
return l;
lyx::docstring & operator+=(lyx::docstring & l, char r)
{
- LASSERT(static_cast<unsigned char>(r) < 0x80, /**/);
+ LASSERT(static_cast<unsigned char>(r) < 0x80, return l);
l.push_back(r);
return l;
}
ctype<lyx::char_type>::do_narrow(const lyx::char_type, char) const { return 0; }
template<> const lyx::char_type *
ctype<lyx::char_type>::do_narrow(const lyx::char_type *, const lyx::char_type *, char, char *) const { return 0; }
-}
+} // namespace std
namespace lyx {
return do_put_helper(oit, b, fill, v);
}
-#ifdef _GLIBCXX_USE_LONG_LONG
+#ifdef HAVE_LONG_LONG_INT
iter_type
do_put(iter_type oit, ios_base & b, char_type fill, long long v) const
{
return do_get_integer(iit, eit, b, err, v);
}
-#ifdef _GLIBCXX_USE_LONG_LONG
+#ifdef HAVE_LONG_LONG_INT
iter_type
do_get(iter_type iit, iter_type eit, ios_base & b,
ios_base::iostate & err, long long & v) const
bool isNumpunct(lyx::char_type const c) const
{
/// Only account for the standard numpunct "C" locale facet.
- return c < 0x80 && (c == '-' || c == '+' || isdigit(c)
- || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')
- || c == 'x' || c == 'X');
+ return c == '-' || c == '+'
+ || c == 'x' || c == 'X'
+ || isHexChar(c);
}
template <typename ValueType>
// [+-]? [0-9]* .? [0-9]* ([eE] [+-]? [0-9]+)?
string s;
s.reserve(64);
- char c;
numpunct_facet p;
char const dot = p.decimal_point();
char const sep = p.thousands_sep();
/// make sure that our facets get used
static locale_initializer initializer;
-}
-}
+} // namespace
+} // namespace lyx
#endif