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

Delta Between Two Patch Sets: compiled/String.h

Issue 29721753: Issue 6180 - use ABP_TEXT everywhere in order to let String be a UTF-8 string (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git@adb2678354813ce5b6de095072954c5a784a7bc4
Left Patch Set: Created March 13, 2018, 6:20 p.m.
Right Patch Set: rebase Created March 15, 2018, 1:53 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 | « compiled/Map.h ('k') | compiled/String.cpp » ('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
(...skipping 21 matching lines...) Expand all
32 #include "base.h" 32 #include "base.h"
33 #include "debug.h" 33 #include "debug.h"
34 #include "library.h" 34 #include "library.h"
35 35
36 ABP_NS_BEGIN 36 ABP_NS_BEGIN
37 37
38 inline void String_assert_writable(bool isWritable); 38 inline void String_assert_writable(bool isWritable);
39 39
40 // hacky because without templates 40 // hacky because without templates
41 #ifdef ABP_UTF8_STRING 41 #ifdef ABP_UTF8_STRING
42 #define ABP_TEXT(val) val 42 #define ABP_TEXT(val) val
hub 2018/03/13 21:29:16 Can't we make this macro shorter? Things are getti
sergei 2018/03/14 10:17:10 I'm afraid it can clash with some another macro, s
43 struct StringTraits 43 struct StringTraits
44 { 44 {
45 typedef char char_type; 45 typedef char char_type;
46 }; 46 };
47 #else 47 #else
48 #define ABP_TEXT(val) u##val 48 #define ABP_TEXT(val) u##val
49 struct StringTraits 49 struct StringTraits
50 { 50 {
51 typedef char16_t char_type; 51 typedef char16_t char_type;
52 }; 52 };
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 222 }
223 } 223 }
224 }; 224 };
225 225
226 #ifdef INSIDE_TESTS 226 #ifdef INSIDE_TESTS
227 inline std::ostream& operator<<(std::ostream& os, const String& str) 227 inline std::ostream& operator<<(std::ostream& os, const String& str)
228 { 228 {
229 #ifdef ABP_UTF8_STRING 229 #ifdef ABP_UTF8_STRING
230 os.write(str.data(), str.length()); 230 os.write(str.data(), str.length());
231 #else 231 #else
232 #if _MSC_VER >= 1900
233 std::wstring_convert<std::codecvt_utf8_utf16<int16_t>, int16_t> converter;
234 auto p = reinterpret_cast<const int16_t *>(str.data());
235 os << converter.to_bytes(p, p + str.length());
236 #else
232 std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter; 237 std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
233 os << converter.to_bytes(str.data(), str.data() + str.length()); 238 os << converter.to_bytes(str.data(), str.data() + str.length());
234 #endif 239 #endif // _MSC_VER >= 1900
240 #endif // ABP_UTF8_STRING
235 return os; 241 return os;
236 } 242 }
237 #endif 243 #endif // INSIDE_TESTS
238 244
239 class DependentString : public String 245 class DependentString : public String
240 { 246 {
241 public: 247 public:
242 explicit DependentString() 248 explicit DependentString()
243 : String(nullptr, 0, INVALID) 249 : String(nullptr, 0, INVALID)
244 { 250 {
245 } 251 }
246 252
247 explicit DependentString(value_type* buf, size_type len) 253 explicit DependentString(value_type* buf, size_type len)
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 return OwnedString{value}; 558 return OwnedString{value};
553 } 559 }
554 560
555 DependentString TrimSpaces(const String& value); 561 DependentString TrimSpaces(const String& value);
556 562
557 // Splits the `value` string into two `DependentString`s excluding the character staying at `separatorPos`. 563 // Splits the `value` string into two `DependentString`s excluding the character staying at `separatorPos`.
558 // Useful for parsing. 564 // Useful for parsing.
559 std::pair<DependentString, DependentString> SplitString(const String& value, Str ing::size_type separatorPos); 565 std::pair<DependentString, DependentString> SplitString(const String& value, Str ing::size_type separatorPos);
560 566
561 ABP_NS_END 567 ABP_NS_END
LEFTRIGHT

Powered by Google App Engine
This is Rietveld