| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef String16STL_h | 5 #ifndef String16STL_h |
| 6 #define String16STL_h | 6 #define String16STL_h |
| 7 | 7 |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 String16(const wstring& impl) : m_impl(impl) { } | 27 String16(const wstring& impl) : m_impl(impl) { } |
| 28 String16(const UChar* characters) : m_impl(characters) { } | 28 String16(const UChar* characters) : m_impl(characters) { } |
| 29 String16(const char* characters) : String16(characters, std::strlen(characte
rs)) { } | 29 String16(const char* characters) : String16(characters, std::strlen(characte
rs)) { } |
| 30 String16(const char* characters, size_t size) | 30 String16(const char* characters, size_t size) |
| 31 { | 31 { |
| 32 m_impl.resize(size); | 32 m_impl.resize(size); |
| 33 for (size_t i = 0; i < size; ++i) | 33 for (size_t i = 0; i < size; ++i) |
| 34 m_impl[i] = characters[i]; | 34 m_impl[i] = characters[i]; |
| 35 } | 35 } |
| 36 String16(const UChar* characters, size_t size) : m_impl(characters, size) {
} | 36 String16(const UChar* characters, size_t size) : m_impl(characters, size) {
} |
| 37 String16 isolatedCopy() const { return String16(m_impl); } |
| 37 ~String16() { } | 38 ~String16() { } |
| 38 | 39 |
| 39 unsigned sizeInBytes() const { return m_impl.size() * sizeof(UChar); } | 40 unsigned sizeInBytes() const { return m_impl.size() * sizeof(UChar); } |
| 40 const UChar* characters16() const { return m_impl.c_str(); } | 41 const UChar* characters16() const { return m_impl.c_str(); } |
| 41 std::string utf8() const; | 42 std::string utf8() const; |
| 42 static String16 number(int i) { return String16(std::to_string(i).c_str());
} | 43 static String16 number(int i) { return String16(std::to_string(i).c_str());
} |
| 43 static String16 fromDouble(double d) { return String16(std::to_string(d).c_s
tr()); } | 44 static String16 fromDouble(double d) { return String16(std::to_string(d).c_s
tr()); } |
| 44 static String16 fromDoubleFixedPrecision(double d, int len) { return String1
6(std::to_string(d).c_str()); } | 45 static String16 fromDoubleFixedPrecision(double d, int len) { return String1
6(std::to_string(d).c_str()); } |
| 45 | 46 |
| 46 static double charactersToDouble(const UChar* characters, size_t length, boo
l* ok = 0) | 47 static double charactersToDouble(const UChar* characters, size_t length, boo
l* ok = 0) |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 template<> | 228 template<> |
| 228 struct hash<String16> { | 229 struct hash<String16> { |
| 229 std::size_t operator()(const String16& k) const | 230 std::size_t operator()(const String16& k) const |
| 230 { | 231 { |
| 231 return k.hash(); | 232 return k.hash(); |
| 232 } | 233 } |
| 233 }; | 234 }; |
| 234 } | 235 } |
| 235 | 236 |
| 236 #endif // !defined(String16STL_h) | 237 #endif // !defined(String16STL_h) |
| OLD | NEW |