diff options
-rw-r--r-- | include/char_traits.h | 15 | ||||
-rw-r--r-- | include/streambuf | 2 | ||||
-rw-r--r-- | include/string | 2 | ||||
-rw-r--r-- | src/string.cpp | 2 | ||||
-rw-r--r-- | tests/test_char_traits.cpp | 4 | ||||
-rw-r--r-- | tests/test_streambuf.cpp | 6 |
6 files changed, 18 insertions, 13 deletions
diff --git a/include/char_traits.h b/include/char_traits.h index e320d44..c790ffd 100644 --- a/include/char_traits.h +++ b/include/char_traits.h @@ -37,13 +37,18 @@ namespace std { /** - * Android's char traits is not a template since we support only - * char. The state_type is missing because we don't support multibyte - * strings. - * Basic type and constants (eof) used in string and stream. + * char_traits defines the basic types and constants (eof) used in + * string and stream as well as basic char manipulations. + * Android's support only char. The state_type is missing because we + * don't support multibyte strings. */ -struct char_traits +template<class _CharT> struct char_traits { + // Empty on purpose. You should use char_traits<char> only. +}; + +template<> +struct char_traits<char> { typedef char char_type; typedef int int_type; diff --git a/include/streambuf b/include/streambuf index f83dd2f..f951a86 100644 --- a/include/streambuf +++ b/include/streambuf @@ -48,7 +48,7 @@ namespace std { class streambuf { public: - typedef char_traits traits_type; + typedef char_traits<char> traits_type; typedef traits_type::char_type char_type; typedef traits_type::int_type int_type; typedef streampos pos_type; diff --git a/include/string b/include/string index 9d5632e..8e1ebbe 100644 --- a/include/string +++ b/include/string @@ -55,7 +55,7 @@ namespace std { class string { public: - typedef char_traits traits_type; + typedef char_traits<char> traits_type; typedef traits_type::char_type value_type; typedef size_t size_type; typedef ptrdiff_t difference_type; diff --git a/src/string.cpp b/src/string.cpp index 6eed77d..e1c4cf9 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -383,7 +383,7 @@ bool operator==(const string& left, const string& right) return true; } return (left.size() == right.size() && - !char_traits::compare(left.mData, right.mData, left.size())); + !char_traits<char>::compare(left.mData, right.mData, left.size())); } bool operator==(const string& left, const string::value_type *right) diff --git a/tests/test_char_traits.cpp b/tests/test_char_traits.cpp index 590e934..b12d228 100644 --- a/tests/test_char_traits.cpp +++ b/tests/test_char_traits.cpp @@ -39,8 +39,8 @@ bool testCharToInt() { // Check that to_int_type maps '\xff' to 0xff and NOT 0xffffffff // which is eof(). - EXPECT_TRUE(char_traits::to_int_type('\xff') == 0xff); - EXPECT_TRUE(char_traits::to_int_type('\xff') != char_traits::eof()); + EXPECT_TRUE(char_traits<char>::to_int_type('\xff') == 0xff); + EXPECT_TRUE(char_traits<char>::to_int_type('\xff') != char_traits<char>::eof()); return true; } } // namespace android diff --git a/tests/test_streambuf.cpp b/tests/test_streambuf.cpp index cc58abc..0f019b6 100644 --- a/tests/test_streambuf.cpp +++ b/tests/test_streambuf.cpp @@ -42,7 +42,7 @@ class streambuf: public std::streambuf { public: streambuf() { setp(mBuffer, mBuffer + sizeof(mBuffer)); - char_traits::assign(mBuffer, sizeof(mBuffer), 'X'); + traits_type::assign(mBuffer, sizeof(mBuffer), 'X'); } char mBuffer[5]; @@ -56,8 +56,8 @@ bool testSputc() { EXPECT_TRUE(buf.sputc('C') == 67); EXPECT_TRUE(buf.sputc('D') == 68); EXPECT_TRUE(buf.sputc('E') == 69); - EXPECT_TRUE(buf.sputc('F') == char_traits::eof()); - EXPECT_TRUE(buf.sputc('G') == char_traits::eof()); + EXPECT_TRUE(buf.sputc('F') == char_traits<char>::eof()); + EXPECT_TRUE(buf.sputc('G') == char_traits<char>::eof()); return true; } |