diff --git a/nel/include/nel/misc/ucstring.h b/nel/include/nel/misc/ucstring.h index 5f0616d8f..28afcdb9a 100644 --- a/nel/include/nel/misc/ucstring.h +++ b/nel/include/nel/misc/ucstring.h @@ -35,95 +35,98 @@ typedef std::basic_string ucstringbase; class ucstring : public ucstringbase { public: + ucstring() { } - ucstring () {} - - ucstring (const ucstringbase &str) : ucstringbase (str) {} + ucstring(const ucstringbase &str) + : ucstringbase(str) + { + } - ucstring (const std::string &str) : ucstringbase () + ucstring(const std::string &str) + : ucstringbase() { rawCopy(str); } - ~ucstring () {} + ~ucstring() { } - ucstring &operator= (ucchar c) + ucstring &operator=(ucchar c) { - resize (1); + resize(1); operator[](0) = c; return *this; } - ucstring &operator= (const char *str) + ucstring &operator=(const char *str) { - resize (strlen (str)); - for (uint i = 0; i < strlen (str); i++) + resize(strlen(str)); + for (uint i = 0; i < strlen(str); i++) { operator[](i) = uint8(str[i]); } return *this; } - ucstring &operator= (const std::string &str) + ucstring &operator=(const std::string &str) { - resize (str.size ()); - for (uint i = 0; i < str.size (); i++) + resize(str.size()); + for (uint i = 0; i < str.size(); i++) { operator[](i) = uint8(str[i]); } return *this; } - ucstring &operator= (const ucstringbase &str) + ucstring &operator=(const ucstringbase &str) { - ucstringbase::operator =(str); + ucstringbase::operator=(str); return *this; } - ucstring& operator= (const ucchar *str) + ucstring &operator=(const ucchar *str) { - ucstringbase::operator =(str); + ucstringbase::operator=(str); return *this; } - ucstring &operator+= (ucchar c) + ucstring &operator+=(ucchar c) { - resize (size() + 1); - operator[](size()-1) = c; + resize(size() + 1); + operator[](size() - 1) = c; return *this; } - ucstring &operator+= (const char *str) + ucstring &operator+=(const char *str) { size_t s = size(); - resize (s + strlen(str)); + resize(s + strlen(str)); for (uint i = 0; i < strlen(str); i++) { - operator[](s+i) = uint8(str[i]); + operator[](s + i) = uint8(str[i]); } return *this; } - ucstring &operator+= (const std::string &str) + ucstring &operator+=(const std::string &str) { size_t s = size(); - resize (s + str.size()); + resize(s + str.size()); for (uint i = 0; i < str.size(); i++) { - operator[](s+i) = uint8(str[i]); + operator[](s + i) = uint8(str[i]); } return *this; } - ucstring &operator+= (const ucstringbase &str) + ucstring &operator+=(const ucstringbase &str) { - ucstringbase::operator +=(str); + ucstringbase::operator+=(str); return *this; } const ucchar *c_str() const { const ucchar *tmp = ucstringbase::c_str(); - const_cast(tmp)[size()] = 0; + const_cast(tmp)[size()] = 0; return tmp; } @@ -131,7 +134,7 @@ public: void toString(std::string &str) const; /// Converts the controlled ucstring and returns the resulting string - std::string toString () const + std::string toString() const { std::string str; toString(str); @@ -165,70 +168,72 @@ public: private: void rawCopy(const std::string &str); - }; inline ucstring operator+(const ucstringbase &ucstr, ucchar c) { - ucstring ret; - ret= ucstr; - ret+= c; + ucstring ret; + ret = ucstr; + ret += c; return ret; } inline ucstring operator+(const ucstringbase &ucstr, const char *c) { - ucstring ret; - ret= ucstr; - ret+= c; + ucstring ret; + ret = ucstr; + ret += c; return ret; } inline ucstring operator+(const ucstringbase &ucstr, const std::string &c) { - ucstring ret; - ret= ucstr; - ret+= c; + ucstring ret; + ret = ucstr; + ret += c; return ret; } inline ucstring operator+(ucchar c, const ucstringbase &ucstr) { - ucstring ret; - ret= c; + ucstring ret; + ret = c; ret += ucstr; return ret; } inline ucstring operator+(const char *c, const ucstringbase &ucstr) { - ucstring ret; - ret= c; + ucstring ret; + ret = c; ret += ucstr; return ret; } inline ucstring operator+(const std::string &c, const ucstringbase &ucstr) { - ucstring ret; - ret= c; + ucstring ret; + ret = c; ret += ucstr; return ret; } -namespace NLMISC -{ +namespace NLMISC { // Traits for hash_map using CEntityId struct CUCStringHashMapTraits { - enum { bucket_size = 4, min_buckets = 8 }; + enum + { + bucket_size = 4, + min_buckets = 8 + }; CUCStringHashMapTraits() { } - size_t operator() (const ucstring &id ) const + size_t operator()(const ucstring &id) const { return id.size(); } - bool operator() (const ucstring &id1, const ucstring &id2) const + bool operator()(const ucstring &id1, const ucstring &id2) const { return id1 < id2; } @@ -239,18 +244,18 @@ struct CUCStringHashMapTraits * \param a string or a char to transform to lower case */ -ucstring toLower (const ucstring &str); -void toLower (ucchar *str); -ucchar toLower (ucchar c); +ucstring toLower(const ucstring &str); +void toLower(ucchar *str); +ucchar toLower(ucchar c); /** Convert an unicode string in upper case. * Characters with accent are converted in a uppercase character without accent * \param a string or a char to transform to upper case */ -ucstring toUpper (const ucstring &str); -void toUpper (ucchar *str); -ucchar toUpper (ucchar c); +ucstring toUpper(const ucstring &str); +void toUpper(ucchar *str); +ucchar toUpper(ucchar c); }; diff --git a/nel/src/misc/ucstring.cpp b/nel/src/misc/ucstring.cpp index df8f52406..8f81cbea1 100644 --- a/nel/src/misc/ucstring.cpp +++ b/nel/src/misc/ucstring.cpp @@ -20,18 +20,18 @@ void ucstring::toString(std::string &str) const { str.resize(size()); - for (uint i = 0; i < str.size (); i++) + for (uint i = 0; i < str.size(); i++) { if (operator[](i) > 255) str[i] = '?'; else - str[i] = (char) operator[](i); + str[i] = (char)operator[](i); } } std::string ucstring::toUtf8() const { - std::string res; + std::string res; ucstring::const_iterator first(begin()), last(end()); for (; first != last; ++first) { @@ -56,9 +56,9 @@ std::string ucstring::toUtf8() const nbLoop = 2; } - for (uint i=0; i> ((nbLoop - i - 1) * 6); c = c & 0x3F; res += char(c) | 0x80; @@ -77,7 +77,7 @@ void ucstring::fromUtf8(const std::string &stringUtf8) sint iterations = 0; std::string::const_iterator first(stringUtf8.begin()), last(stringUtf8.end()); - for (; first != last; ) + for (; first != last;) { c = *first++; code = c; @@ -131,7 +131,7 @@ void ucstring::fromUtf8(const std::string &stringUtf8) } uint8 ch; - ch = *first ++; + ch = *first++; if ((ch & 0xC0) != 0x80) { @@ -155,7 +155,7 @@ void ucstring::rawCopy(const std::string &str) resize(str.size()); std::string::const_iterator first(str.begin()), last(str.end()); iterator dest(begin()); - for (;first != last; ++first, ++dest) + for (; first != last; ++first, ++dest) { *dest = uint8(*first); }