| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 #pragma once | 1 #pragma once |
| 2 | 2 |
| 3 #include <cstddef> | 3 #include <cstddef> |
| 4 #include <cstring> | 4 #include <cstring> |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include <emscripten.h> | 7 #include <emscripten.h> |
| 8 | 8 |
| 9 #include "debug.h" | 9 #include "debug.h" |
| 10 | 10 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 explicit DependentString(value_type* buf, size_type len) | 181 explicit DependentString(value_type* buf, size_type len) |
| 182 : String(buf, len, READ_WRITE) | 182 : String(buf, len, READ_WRITE) |
| 183 { | 183 { |
| 184 } | 184 } |
| 185 | 185 |
| 186 explicit DependentString(const value_type* buf, size_type len) | 186 explicit DependentString(const value_type* buf, size_type len) |
| 187 : String(const_cast<value_type*>(buf), len, READ_ONLY) | 187 : String(const_cast<value_type*>(buf), len, READ_ONLY) |
| 188 { | 188 { |
| 189 } | 189 } |
| 190 | 190 |
| 191 DependentString(String& str, size_type pos = 0, size_type len = npos) | 191 explicit DependentString(String& str, size_type pos = 0, size_type len = npos) |
|
sergei
2017/03/20 17:07:06
Why have explicit keywords been removed here?
Wladimir Palant
2017/03/21 10:10:04
Done.
| |
| 192 : String( | 192 : String( |
| 193 str.mBuf + std::min(pos, str.length()), | 193 str.mBuf + std::min(pos, str.length()), |
| 194 std::min(len, str.length() - std::min(pos, str.length())), | 194 std::min(len, str.length() - std::min(pos, str.length())), |
| 195 str.is_readOnly() ? READ_ONLY : READ_WRITE | 195 str.is_readOnly() ? READ_ONLY : READ_WRITE |
| 196 ) | 196 ) |
| 197 { | 197 { |
| 198 } | 198 } |
| 199 | 199 |
| 200 DependentString(const String& str, size_type pos = 0, | 200 explicit DependentString(const String& str, size_type pos = 0, |
| 201 size_type len = npos) | 201 size_type len = npos) |
| 202 : String( | 202 : String( |
| 203 str.mBuf + std::min(pos, str.length()), | 203 str.mBuf + std::min(pos, str.length()), |
| 204 std::min(len, str.length() - std::min(pos, str.length())), | 204 std::min(len, str.length() - std::min(pos, str.length())), |
| 205 READ_ONLY | 205 READ_ONLY |
| 206 ) | 206 ) |
| 207 { | 207 { |
| 208 } | 208 } |
| 209 | 209 |
| 210 void reset(value_type* buf, size_type len) | 210 void reset(value_type* buf, size_type len) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 inline void String_assert_readonly(bool readOnly) | 243 inline void String_assert_readonly(bool readOnly) |
| 244 { | 244 { |
| 245 assert(!readOnly, u"Writing access to a read-only string"_str); | 245 assert(!readOnly, u"Writing access to a read-only string"_str); |
| 246 } | 246 } |
| 247 | 247 |
| 248 class OwnedString : public String | 248 class OwnedString : public String |
| 249 { | 249 { |
| 250 private: | 250 private: |
| 251 void grow(size_type additionalSize) | 251 void grow(size_type additionalSize) |
| 252 { | 252 { |
| 253 auto newValue = OwnedString(length() + additionalSize); | 253 OwnedString newValue(length() + additionalSize); |
|
sergei
2017/03/20 17:07:04
I know, it's a copy from my code but
OwnedString n
Wladimir Palant
2017/03/21 10:10:01
Done.
| |
| 254 if (length() > 0) | 254 if (length() > 0) |
| 255 std::memcpy(newValue.mBuf, mBuf, sizeof(value_type) * length()); | 255 std::memcpy(newValue.mBuf, mBuf, sizeof(value_type) * length()); |
| 256 *this = std::move(newValue); | 256 *this = std::move(newValue); |
| 257 } | 257 } |
| 258 | 258 |
| 259 public: | 259 public: |
| 260 explicit OwnedString(size_type len = 0) | 260 explicit OwnedString(size_type len = 0) |
| 261 : String(nullptr, len, READ_WRITE) | 261 : String(nullptr, len, READ_WRITE) |
| 262 { | 262 { |
| 263 if (len) | 263 if (len) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 void append(const String& str) | 334 void append(const String& str) |
| 335 { | 335 { |
| 336 append(str.mBuf, str.length()); | 336 append(str.mBuf, str.length()); |
| 337 } | 337 } |
| 338 | 338 |
| 339 void append(value_type c) | 339 void append(value_type c) |
| 340 { | 340 { |
| 341 append(&c, 1); | 341 append(&c, 1); |
| 342 } | 342 } |
| 343 }; | 343 }; |
| LEFT | RIGHT |