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

Delta Between Two Patch Sets: compiled/String.h

Issue 29685634: Noissue - Allow displaying String in tests (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Jan. 31, 2018, 8:45 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | meson.build » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
24 #include <iostream> 25 #include <iostream>
sergei 2018/02/01 16:10:46 Could you please wrap it by #ifdef INSIDE_TESTS to
hub 2018/02/01 19:16:29 Done.
26 #include <codecvt>
27 #endif
25 28
26 #include "debug.h" 29 #include "debug.h"
27 #include "library.h" 30 #include "library.h"
28 31
29 inline void String_assert_writable(bool isWritable); 32 inline void String_assert_writable(bool isWritable);
30 33
31 class String 34 class String
32 { 35 {
33 friend class DependentString; 36 friend class DependentString;
34 friend class OwnedString; 37 friend class OwnedString;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 { 193 {
191 mBuf[i] = CharToLower(currChar); 194 mBuf[i] = CharToLower(currChar);
192 } 195 }
193 } 196 }
194 } 197 }
195 }; 198 };
196 199
197 #ifdef INSIDE_TESTS 200 #ifdef INSIDE_TESTS
198 inline std::ostream& operator<<(std::ostream& os, const String& str) 201 inline std::ostream& operator<<(std::ostream& os, const String& str)
199 { 202 {
200 for (String::size_type i = 0; i < str.length(); i++) 203 std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
201 os << static_cast<char>(str[i]); 204 os << converter.to_bytes(str.data(), str.data() + str.length());
sergei 2018/02/01 16:10:46 Even for tests I would like to have a helper funct
hub 2018/02/01 19:16:30 Done
202 return os; 205 return os;
203 } 206 }
204 #endif 207 #endif
205 208
206 class DependentString : public String 209 class DependentString : public String
207 { 210 {
208 public: 211 public:
209 explicit DependentString() 212 explicit DependentString()
210 : String(nullptr, 0, INVALID) 213 : String(nullptr, 0, INVALID)
211 { 214 {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 264 }
262 265
263 void erase() 266 void erase()
264 { 267 {
265 *this = DependentString(); 268 *this = DependentString();
266 mLen = DELETED; 269 mLen = DELETED;
267 } 270 }
268 }; 271 };
269 272
270 #ifdef INSIDE_TESTS 273 #ifdef INSIDE_TESTS
271 inline std::ostream& operator<<(std::ostream& os, const DependentString& str) 274 inline std::ostream& operator<<(std::ostream& os, const DependentString& str)
sergei 2018/02/01 16:10:46 It should not be required.
hub 2018/02/01 19:16:30 Without this it operator<< doesn't get called, unl
sergei 2018/02/02 15:03:32 Acknowledged. I think it is worth investigation, b
272 { 275 {
273 return os << static_cast<const String&>(str); 276 return os << static_cast<const String&>(str);
274 } 277 }
275 #endif 278 #endif
276 279
277 inline DependentString operator "" _str(const String::value_type* str, 280 inline DependentString operator "" _str(const String::value_type* str,
278 String::size_type len) 281 String::size_type len)
279 { 282 {
280 return DependentString(str, len); 283 return DependentString(str, len);
281 } 284 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 if (negative) 433 if (negative)
431 mBuf[pos++] = '-'; 434 mBuf[pos++] = '-';
432 435
433 for (int i = size - 1; i >= 0; i--) 436 for (int i = size - 1; i >= 0; i--)
434 { 437 {
435 mBuf[pos + i] = '0' + (num % 10); 438 mBuf[pos + i] = '0' + (num % 10);
436 num /= 10; 439 num /= 10;
437 } 440 }
438 } 441 }
439 }; 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
LEFTRIGHT
« no previous file | meson.build » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld