From 07f7e739b927296da4329d64a59022d5f0f568ef Mon Sep 17 00:00:00 2001 From: Sergey Yershov Date: Tue, 31 May 2016 13:44:55 +0300 Subject: Clang-format for review --- base/string_utils.cpp | 44 +++++++------------------ base/string_utils.hpp | 89 ++++++++++++++++++++++++--------------------------- 2 files changed, 53 insertions(+), 80 deletions(-) (limited to 'base') diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 22dfad3030..de986d77a3 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -11,7 +11,6 @@ namespace strings { - bool UniString::IsEqualAscii(char const * s) const { return (size() == strlen(s) && equal(begin(), end(), s)); @@ -71,7 +70,6 @@ bool to_uint(char const * start, unsigned int & i, int base /*= 10*/) return IntegerCheck(start, stop, v, i); } - bool to_uint64(char const * s, uint64_t & i) { char * stop; @@ -183,33 +181,21 @@ void NormalizeDigits(UniString & us) namespace { - char ascii_to_lower(char in) - { - char const diff = 'z' - 'Z'; - static_assert(diff == 'a' - 'A', ""); - static_assert(diff > 0, ""); - - if (in >= 'A' && in <= 'Z') - return (in + diff); - return in; - } -} - -void AsciiToLower(string & s) +char ascii_to_lower(char in) { - transform(s.begin(), s.end(), s.begin(), &ascii_to_lower); -} + char const diff = 'z' - 'Z'; + static_assert(diff == 'a' - 'A', ""); + static_assert(diff > 0, ""); -void Trim(string & s) -{ - boost::trim(s); + if (in >= 'A' && in <= 'Z') + return (in + diff); + return in; } - -void Trim(string & s, char const * anyOf) -{ - boost::trim_if(s, boost::is_any_of(anyOf)); } +void AsciiToLower(string & s) { transform(s.begin(), s.end(), s.begin(), &ascii_to_lower); } +void Trim(string & s) { boost::trim(s); } +void Trim(string & s, char const * anyOf) { boost::trim_if(s, boost::is_any_of(anyOf)); } bool EqualNoCase(string const & s1, string const & s2) { return MakeLowerCase(s1) == MakeLowerCase(s2); @@ -238,9 +224,7 @@ bool IsASCIIString(string const & str) } bool IsASCIIDigit(UniChar c) { return c >= '0' && c <= '9'; } - bool IsASCIILatin(UniChar c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } - bool StartsWith(UniString const & s, UniString const & p) { if (p.size() > s.size()) @@ -253,11 +237,7 @@ bool StartsWith(UniString const & s, UniString const & p) return true; } -bool StartsWith(string const & s1, char const * s2) -{ - return (s1.compare(0, strlen(s2), s2) == 0); -} - +bool StartsWith(string const & s1, char const * s2) { return (s1.compare(0, strlen(s2), s2) == 0); } bool EndsWith(string const & s1, char const * s2) { size_t const n = s1.size(); @@ -344,4 +324,4 @@ bool AlmostEqual(string const & str1, string const & str2, size_t mismatchedCoun return false; } -} // namespace strings +} // namespace strings diff --git a/base/string_utils.hpp b/base/string_utils.hpp index ca5449ae2b..85396b7f19 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -15,18 +15,22 @@ /// All methods work with strings in utf-8 format namespace strings { - typedef uint32_t UniChar; -//typedef buffer_vector UniString; +// typedef buffer_vector UniString; /// Make new type, not typedef. Need to specialize DebugPrint. class UniString : public buffer_vector { typedef buffer_vector BaseT; + public: UniString() {} explicit UniString(size_t n, UniChar c = UniChar()) : BaseT(n, c) {} - template UniString(IterT b, IterT e) : BaseT(b, e) {} + template + UniString(IterT b, IterT e) + : BaseT(b, e) + { + } bool IsEqualAscii(char const * s) const; @@ -83,10 +87,7 @@ bool IsASCIIString(string const & str); bool IsASCIIDigit(UniChar c); bool IsASCIILatin(UniChar c); -inline string DebugPrint(UniString const & s) -{ - return ToUtf8(s); -} +inline string DebugPrint(UniString const & s) { return ToUtf8(s); } template class TokenizeIterator @@ -117,14 +118,14 @@ class TokenizeIterator public: /// @warning string S must be not temporary! TokenizeIterator(string const & s, DelimFuncT const & delimFunc) - : m_beg(s.begin()), m_end(s.begin()), m_finish(s.end()), m_delimFunc(delimFunc) + : m_beg(s.begin()), m_end(s.begin()), m_finish(s.end()), m_delimFunc(delimFunc) { move(); } /// @warning unistring S must be not temporary! TokenizeIterator(UniString const & s, DelimFuncT const & delimFunc) - : m_beg(s.begin()), m_end(s.begin()), m_finish(s.end()), m_delimFunc(delimFunc) + : m_beg(s.begin()), m_end(s.begin()), m_finish(s.end()), m_delimFunc(delimFunc) { move(); } @@ -137,12 +138,12 @@ public: string operator*() const { - ASSERT( m_beg != m_finish, ("dereferencing of empty iterator") ); + ASSERT(m_beg != m_finish, ("dereferencing of empty iterator")); return string(m_beg.base(), m_end.base()); } operator bool() const { return m_beg != m_finish; } - + TokenizeIterator & operator++() { move(); @@ -159,11 +160,7 @@ public: return !copy; } - UniString GetUniString() const - { - return UniString(m_beg, m_end); - } - + UniString GetUniString() const { return UniString(m_beg, m_end); } /// Same as operator bool() in expression it == end(...) bool operator==(TokenizeIterator const &) { return !(*this); } /// Same as operator bool() in expression it != end(...) @@ -173,6 +170,7 @@ public: class SimpleDelimiter { UniString m_delims; + public: SimpleDelimiter(char const * delimChars); // Used in TokenizeIterator to allow past the end iterator construction. @@ -181,8 +179,8 @@ public: bool operator()(UniChar c) const; }; -typedef TokenizeIterator > SimpleTokenizer; +typedef TokenizeIterator> + SimpleTokenizer; template void Tokenize(string const & str, char const * delims, TFunctor && f) @@ -198,7 +196,8 @@ void Tokenize(string const & str, char const * delims, TFunctor && f) /// @return code of last symbol in string or 0 if s is empty UniChar LastUniChar(string const & s); -template bool IsInArray(T (&arr) [N], TT const & t) +template +bool IsInArray(T(&arr)[N], TT const & t) { for (size_t i = 0; i < N; ++i) if (arr[i] == t) @@ -214,10 +213,17 @@ bool to_uint64(char const * s, uint64_t & i); bool to_int64(char const * s, int64_t & i); bool to_double(char const * s, double & d); -inline bool is_number(string const & s) { int64_t dummy; return to_int64(s.c_str(), dummy); } +inline bool is_number(string const & s) +{ + int64_t dummy; + return to_int64(s.c_str(), dummy); +} inline bool to_int(string const & s, int & i, int base = 10) { return to_int(s.c_str(), i, base); } -inline bool to_uint(string const & s, unsigned int & i, int base = 10) { return to_uint(s.c_str(), i, base); } +inline bool to_uint(string const & s, unsigned int & i, int base = 10) +{ + return to_uint(s.c_str(), i, base); +} inline bool to_uint64(string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); } inline bool to_int64(string const & s, int64_t & i) { return to_int64(s.c_str(), i); } inline bool to_double(string const & s, double & d) { return to_double(s.c_str(), d); } @@ -225,17 +231,10 @@ inline bool to_double(string const & s, double & d) { return to_double(s.c_str() /// @name From numeric to string. //@{ -inline string to_string(string const & s) -{ - return s; -} - -inline string to_string(char const * s) -{ - return s; -} - -template string to_string(T t) +inline string to_string(string const & s) { return s; } +inline string to_string(char const * s) { return s; } +template +string to_string(T t) { ostringstream ss; ss << t; @@ -261,7 +260,8 @@ int UpperBoundOnChars() return numeric_limits::digits10 + is_signed::value + 1; } -template char * to_string_digits(char * buf, T i) +template +char * to_string_digits(char * buf, T i) { do { @@ -272,7 +272,8 @@ template char * to_string_digits(char * buf, T i) return buf; } -template string to_string_signed(T i) +template +string to_string_signed(T i) { bool const negative = i < 0; int const sz = UpperBoundOnChars(); @@ -287,7 +288,8 @@ template string to_string_signed(T i) return string(beg, end - beg); } -template string to_string_unsigned(T i) +template +string to_string_unsigned(T i) { int const sz = UpperBoundOnChars(); char buf[sz]; @@ -295,19 +297,10 @@ template string to_string_unsigned(T i) char * beg = to_string_digits(end, i); return string(beg, end - beg); } - -} - -inline string to_string(int64_t i) -{ - return impl::to_string_signed(i); -} - -inline string to_string(uint64_t i) -{ - return impl::to_string_unsigned(i); } +inline string to_string(int64_t i) { return impl::to_string_signed(i); } +inline string to_string(uint64_t i) { return impl::to_string_unsigned(i); } /// Use this function to get string with fixed count of /// "Digits after comma". string to_string_dac(double d, int dac); @@ -399,7 +392,7 @@ size_t EditDistance(TIter const & b1, TIter const & e1, TIter const & b2, TIter namespace std { -template +template struct iterator_traits> { using difference_type = std::ptrdiff_t; @@ -408,4 +401,4 @@ struct iterator_traits> using reference = string; using iterator_category = std::input_iterator_tag; }; -} // namespace std +} // namespace std -- cgit v1.2.3