Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/String.h

Issue 29685634: Noissue - Allow displaying String in tests (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add utf8 conversion Created Feb. 1, 2018, 7:16 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | meson.build » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #pragma once 18 #pragma once
19 19
20 #include <algorithm> 20 #include <algorithm>
21 #include <cstddef> 21 #include <cstddef>
22 #include <cstring> 22 #include <cstring>
23 #include <type_traits> 23 #include <type_traits>
24 #ifdef INSIDE_TESTS
25 #include <iostream>
26 #include <codecvt>
27 #endif
24 28
25 #include "debug.h" 29 #include "debug.h"
26 #include "library.h" 30 #include "library.h"
27 31
28 inline void String_assert_writable(bool isWritable); 32 inline void String_assert_writable(bool isWritable);
29 33
30 class String 34 class String
31 { 35 {
32 friend class DependentString; 36 friend class DependentString;
33 friend class OwnedString; 37 friend class OwnedString;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if (currChar >= u'A' && currChar <= u'Z') 190 if (currChar >= u'A' && currChar <= u'Z')
187 mBuf[i] = currChar + u'a' - u'A'; 191 mBuf[i] = currChar + u'a' - u'A';
188 else if (currChar >= 128) 192 else if (currChar >= 128)
189 { 193 {
190 mBuf[i] = CharToLower(currChar); 194 mBuf[i] = CharToLower(currChar);
191 } 195 }
192 } 196 }
193 } 197 }
194 }; 198 };
195 199
200 #ifdef INSIDE_TESTS
201 inline std::ostream& operator<<(std::ostream& os, const String& str)
202 {
203 std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
204 os << converter.to_bytes(str.data(), str.data() + str.length());
205 return os;
206 }
207 #endif
208
196 class DependentString : public String 209 class DependentString : public String
197 { 210 {
198 public: 211 public:
199 explicit DependentString() 212 explicit DependentString()
200 : String(nullptr, 0, INVALID) 213 : String(nullptr, 0, INVALID)
201 { 214 {
202 } 215 }
203 216
204 explicit DependentString(value_type* buf, size_type len) 217 explicit DependentString(value_type* buf, size_type len)
205 : String(buf, len, READ_WRITE) 218 : String(buf, len, READ_WRITE)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 *this = DependentString(str, pos, len); 263 *this = DependentString(str, pos, len);
251 } 264 }
252 265
253 void erase() 266 void erase()
254 { 267 {
255 *this = DependentString(); 268 *this = DependentString();
256 mLen = DELETED; 269 mLen = DELETED;
257 } 270 }
258 }; 271 };
259 272
273 #ifdef INSIDE_TESTS
274 inline std::ostream& operator<<(std::ostream& os, const DependentString& str)
275 {
276 return os << static_cast<const String&>(str);
277 }
278 #endif
279
260 inline DependentString operator "" _str(const String::value_type* str, 280 inline DependentString operator "" _str(const String::value_type* str,
261 String::size_type len) 281 String::size_type len)
262 { 282 {
263 return DependentString(str, len); 283 return DependentString(str, len);
264 } 284 }
265 285
266 inline void String_assert_writable(bool isWritable) 286 inline void String_assert_writable(bool isWritable)
267 { 287 {
268 assert2(isWritable, u"Writing access to a read-only string"_str); 288 assert2(isWritable, u"Writing access to a read-only string"_str);
269 } 289 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 if (negative) 433 if (negative)
414 mBuf[pos++] = '-'; 434 mBuf[pos++] = '-';
415 435
416 for (int i = size - 1; i >= 0; i--) 436 for (int i = size - 1; i >= 0; i--)
417 { 437 {
418 mBuf[pos + i] = '0' + (num % 10); 438 mBuf[pos + i] = '0' + (num % 10);
419 num /= 10; 439 num /= 10;
420 } 440 }
421 } 441 }
422 }; 442 };
443
444 #ifdef INSIDE_TESTS
445 inline std::ostream& operator<<(std::ostream& os, const OwnedString& str)
446 {
447 return os << static_cast<const String&>(str);
448 }
449 #endif
OLDNEW
« no previous file with comments | « no previous file | meson.build » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld