5#include "core/fxcrt/widestring.h"
11#include "build/build_config.h"
12#include "core/fxcrt/fx_string.h"
13#include "core/fxcrt/utf16.h"
14#include "testing/gtest/include/gtest/gtest.h"
15#include "third_party/base/containers/contains.h"
16#include "third_party/base/containers/span.h"
22 EXPECT_EQ(L'a', abc
[0
]);
23 EXPECT_EQ(L'b', abc
[1
]);
24 EXPECT_EQ(L'c', abc
[2
]);
26 EXPECT_DEATH({ abc
[4
]; },
"");
29 pdfium::span<
const wchar_t> abc_span = abc.span();
30 EXPECT_EQ(3u, abc_span.size());
31 EXPECT_EQ(0, wmemcmp(abc_span.data(), L"abc", 3));
35 EXPECT_EQ(L'a', mutable_abc
[0
]);
36 EXPECT_EQ(L'b', mutable_abc
[1
]);
37 EXPECT_EQ(L'c', mutable_abc
[2
]);
39 EXPECT_EQ(L"abc", abc);
42 mutable_abc.SetAt(0, L'd');
44 EXPECT_NE(c_str, mutable_abc
.c_str());
45 EXPECT_EQ(L"abc", abc);
46 EXPECT_EQ(L"dbc", mutable_abc);
48 mutable_abc.SetAt(1, L'e');
49 EXPECT_EQ(L"abc", abc);
50 EXPECT_EQ(L"dec", mutable_abc);
52 mutable_abc.SetAt(2, L'f');
53 EXPECT_EQ(L"abc", abc);
54 EXPECT_EQ(L"def", mutable_abc);
56 EXPECT_DEATH({ mutable_abc.SetAt(3, L'g'); },
"");
57 EXPECT_EQ(L"abc", abc);
66 EXPECT_EQ(L"abc", string1);
67 EXPECT_EQ(L"abc", string2);
76 EXPECT_EQ(L"abc", string2);
105 string1 =
std::move(string2);
106 EXPECT_EQ(L"abc", string1);
116 EXPECT_EQ(L"abc", string1);
120 EXPECT_EQ(L"def", string1);
127 EXPECT_EQ(L"abc", string1);
128 string1 = WideStringView(L"");
130 string1 = WideStringView(L"def");
131 EXPECT_EQ(L"def", string1);
141 WideStringView v_empty;
142 WideStringView v_a(L"a");
143 WideStringView v_ab(L"ab");
144 WideStringView v_abc(L"\x0110qq");
145 WideStringView v_def(L"\x1001qq");
146 const wchar_t*
const c_null =
nullptr;
147 const wchar_t*
const c_empty = L"";
148 const wchar_t*
const c_a = L"a";
149 const wchar_t*
const c_ab = L"ab";
150 const wchar_t*
const c_abc = L"\x0110qq";
151 const wchar_t*
const c_def = L"\x1001qq";
153 EXPECT_FALSE(empty
< empty);
155 EXPECT_FALSE(abc
< abc);
156 EXPECT_FALSE(def
< def);
157 EXPECT_FALSE(c_null
< empty);
158 EXPECT_FALSE(c_empty
< empty);
159 EXPECT_FALSE(c_a
< a);
160 EXPECT_FALSE(c_abc
< abc);
161 EXPECT_FALSE(c_def
< def);
162 EXPECT_FALSE(empty
< c_null);
163 EXPECT_FALSE(empty
< c_empty);
164 EXPECT_FALSE(a
< c_a);
165 EXPECT_FALSE(abc
< c_abc);
166 EXPECT_FALSE(def
< c_def);
167 EXPECT_FALSE(empty < v_empty);
168 EXPECT_FALSE(a < v_a);
169 EXPECT_FALSE(abc < v_abc);
170 EXPECT_FALSE(def < v_def);
172 EXPECT_TRUE(empty
< a);
173 EXPECT_FALSE(a
< empty);
174 EXPECT_TRUE(c_null
< a);
175 EXPECT_TRUE(c_empty
< a);
176 EXPECT_FALSE(c_a
< empty);
177 EXPECT_TRUE(empty
< c_a);
178 EXPECT_FALSE(a
< c_null);
179 EXPECT_FALSE(a
< c_empty);
180 EXPECT_TRUE(empty < v_a);
181 EXPECT_FALSE(a < v_empty);
183 EXPECT_TRUE(empty
< abc);
184 EXPECT_FALSE(abc
< empty);
185 EXPECT_TRUE(c_null
< abc);
186 EXPECT_TRUE(c_empty
< abc);
187 EXPECT_FALSE(c_abc
< empty);
188 EXPECT_TRUE(empty
< c_abc);
189 EXPECT_FALSE(abc
< c_null);
190 EXPECT_FALSE(abc
< c_empty);
191 EXPECT_TRUE(empty < v_abc);
192 EXPECT_FALSE(abc < v_empty);
194 EXPECT_TRUE(empty
< def);
195 EXPECT_FALSE(def
< empty);
196 EXPECT_TRUE(c_null
< def);
197 EXPECT_TRUE(c_empty
< def);
198 EXPECT_FALSE(c_def
< empty);
199 EXPECT_TRUE(empty
< c_def);
200 EXPECT_FALSE(def
< c_null);
201 EXPECT_FALSE(def
< c_empty);
202 EXPECT_TRUE(empty < v_def);
203 EXPECT_FALSE(def < v_empty);
205 EXPECT_TRUE(a
< abc);
206 EXPECT_FALSE(abc
< a);
207 EXPECT_TRUE(c_a
< abc);
208 EXPECT_FALSE(c_abc
< a);
209 EXPECT_TRUE(a
< c_abc);
210 EXPECT_FALSE(abc
< c_a);
211 EXPECT_TRUE(a < v_abc);
212 EXPECT_FALSE(abc < v_a);
214 EXPECT_TRUE(a
< def);
215 EXPECT_FALSE(def
< a);
216 EXPECT_TRUE(c_a
< def);
217 EXPECT_FALSE(c_def
< a);
218 EXPECT_TRUE(a
< c_def);
219 EXPECT_FALSE(def
< c_a);
220 EXPECT_TRUE(a < v_def);
221 EXPECT_FALSE(def < v_a);
223 EXPECT_TRUE(abc
< def);
224 EXPECT_FALSE(def
< abc);
225 EXPECT_TRUE(c_abc
< def);
226 EXPECT_FALSE(c_def
< abc);
227 EXPECT_TRUE(abc
< c_def);
228 EXPECT_FALSE(def
< c_abc);
229 EXPECT_TRUE(abc < v_def);
230 EXPECT_FALSE(def < v_abc);
233 EXPECT_TRUE(a
< c_ab);
234 EXPECT_TRUE(a < v_ab);
235 EXPECT_TRUE(c_a
< ab);
236 EXPECT_TRUE(c_a < v_ab);
237 EXPECT_TRUE(v_a < c_ab);
238 EXPECT_TRUE(v_a < v_ab);
243 EXPECT_TRUE(null_string
== null_string);
246 EXPECT_TRUE(empty_string
== empty_string);
247 EXPECT_TRUE(empty_string
== null_string);
248 EXPECT_TRUE(null_string
== empty_string);
251 deleted_string.Delete(0, 5);
252 EXPECT_TRUE(deleted_string
== deleted_string);
253 EXPECT_TRUE(deleted_string
== null_string);
254 EXPECT_TRUE(deleted_string
== empty_string);
255 EXPECT_TRUE(null_string
== deleted_string);
256 EXPECT_TRUE(null_string
== empty_string);
259 EXPECT_TRUE(wide_string
== wide_string);
260 EXPECT_FALSE(wide_string
== null_string);
261 EXPECT_FALSE(wide_string
== empty_string);
262 EXPECT_FALSE(wide_string
== deleted_string);
263 EXPECT_FALSE(null_string
== wide_string);
264 EXPECT_FALSE(empty_string
== wide_string);
265 EXPECT_FALSE(deleted_string
== wide_string);
268 EXPECT_TRUE(wide_string
== wide_string_same1);
269 EXPECT_TRUE(wide_string_same1
== wide_string);
272 EXPECT_TRUE(wide_string
== wide_string_same2);
273 EXPECT_TRUE(wide_string_same2
== wide_string);
278 EXPECT_FALSE(wide_string
== wide_string1);
279 EXPECT_FALSE(wide_string
== wide_string2);
280 EXPECT_FALSE(wide_string
== wide_string3);
281 EXPECT_FALSE(wide_string1
== wide_string);
282 EXPECT_FALSE(wide_string2
== wide_string);
283 EXPECT_FALSE(wide_string3
== wide_string);
285 WideStringView null_string_c;
286 WideStringView empty_string_c(L"");
287 EXPECT_TRUE(null_string == null_string_c);
288 EXPECT_TRUE(null_string == empty_string_c);
289 EXPECT_TRUE(empty_string == null_string_c);
290 EXPECT_TRUE(empty_string == empty_string_c);
291 EXPECT_TRUE(deleted_string == null_string_c);
292 EXPECT_TRUE(deleted_string == empty_string_c);
293 EXPECT_TRUE(null_string_c == null_string);
294 EXPECT_TRUE(empty_string_c == null_string);
295 EXPECT_TRUE(null_string_c == empty_string);
296 EXPECT_TRUE(empty_string_c == empty_string);
297 EXPECT_TRUE(null_string_c == deleted_string);
298 EXPECT_TRUE(empty_string_c == deleted_string);
300 WideStringView wide_string_c_same1(L"hello");
301 EXPECT_TRUE(wide_string == wide_string_c_same1);
302 EXPECT_TRUE(wide_string_c_same1 == wide_string);
304 WideStringView wide_string_c1(L"he");
305 WideStringView wide_string_c2(L"hellp");
306 WideStringView wide_string_c3(L"hellod");
307 EXPECT_FALSE(wide_string == wide_string_c1);
308 EXPECT_FALSE(wide_string == wide_string_c2);
309 EXPECT_FALSE(wide_string == wide_string_c3);
310 EXPECT_FALSE(wide_string_c1 == wide_string);
311 EXPECT_FALSE(wide_string_c2 == wide_string);
312 EXPECT_FALSE(wide_string_c3 == wide_string);
314 const wchar_t*
const c_null_string =
nullptr;
315 const wchar_t*
const c_empty_string = L"";
316 EXPECT_TRUE(null_string
== c_null_string);
317 EXPECT_TRUE(null_string
== c_empty_string);
318 EXPECT_TRUE(empty_string
== c_null_string);
319 EXPECT_TRUE(empty_string
== c_empty_string);
320 EXPECT_TRUE(deleted_string
== c_null_string);
321 EXPECT_TRUE(deleted_string
== c_empty_string);
322 EXPECT_TRUE(c_null_string
== null_string);
323 EXPECT_TRUE(c_empty_string
== null_string);
324 EXPECT_TRUE(c_null_string
== empty_string);
325 EXPECT_TRUE(c_empty_string
== empty_string);
326 EXPECT_TRUE(c_null_string
== deleted_string);
327 EXPECT_TRUE(c_empty_string
== deleted_string);
329 const wchar_t*
const c_string_same1 = L"hello";
330 EXPECT_TRUE(wide_string
== c_string_same1);
331 EXPECT_TRUE(c_string_same1
== wide_string);
333 const wchar_t*
const c_string1 = L"he";
334 const wchar_t*
const c_string2 = L"hellp";
335 const wchar_t*
const c_string3 = L"hellod";
336 EXPECT_FALSE(wide_string
== c_string1);
337 EXPECT_FALSE(wide_string
== c_string2);
338 EXPECT_FALSE(wide_string
== c_string3);
339 EXPECT_FALSE(c_string1
== wide_string);
340 EXPECT_FALSE(c_string2
== wide_string);
341 EXPECT_FALSE(c_string3
== wide_string);
346 EXPECT_FALSE(null_string
!= null_string);
349 EXPECT_FALSE(empty_string
!= empty_string);
350 EXPECT_FALSE(empty_string
!= null_string);
351 EXPECT_FALSE(null_string
!= empty_string);
354 deleted_string.Delete(0, 5);
355 EXPECT_FALSE(deleted_string
!= deleted_string);
356 EXPECT_FALSE(deleted_string
!= null_string);
357 EXPECT_FALSE(deleted_string
!= empty_string);
358 EXPECT_FALSE(null_string
!= deleted_string);
359 EXPECT_FALSE(null_string
!= empty_string);
362 EXPECT_FALSE(wide_string
!= wide_string);
363 EXPECT_TRUE(wide_string
!= null_string);
364 EXPECT_TRUE(wide_string
!= empty_string);
365 EXPECT_TRUE(wide_string
!= deleted_string);
366 EXPECT_TRUE(null_string
!= wide_string);
367 EXPECT_TRUE(empty_string
!= wide_string);
368 EXPECT_TRUE(deleted_string
!= wide_string);
371 EXPECT_FALSE(wide_string
!= wide_string_same1);
372 EXPECT_FALSE(wide_string_same1
!= wide_string);
375 EXPECT_FALSE(wide_string
!= wide_string_same2);
376 EXPECT_FALSE(wide_string_same2
!= wide_string);
381 EXPECT_TRUE(wide_string
!= wide_string1);
382 EXPECT_TRUE(wide_string
!= wide_string2);
383 EXPECT_TRUE(wide_string
!= wide_string3);
384 EXPECT_TRUE(wide_string1
!= wide_string);
385 EXPECT_TRUE(wide_string2
!= wide_string);
386 EXPECT_TRUE(wide_string3
!= wide_string);
388 WideStringView null_string_c;
389 WideStringView empty_string_c(L"");
390 EXPECT_FALSE(null_string != null_string_c);
391 EXPECT_FALSE(null_string != empty_string_c);
392 EXPECT_FALSE(empty_string != null_string_c);
393 EXPECT_FALSE(empty_string != empty_string_c);
394 EXPECT_FALSE(deleted_string != null_string_c);
395 EXPECT_FALSE(deleted_string != empty_string_c);
396 EXPECT_FALSE(null_string_c != null_string);
397 EXPECT_FALSE(empty_string_c != null_string);
398 EXPECT_FALSE(null_string_c != empty_string);
399 EXPECT_FALSE(empty_string_c != empty_string);
401 WideStringView wide_string_c_same1(L"hello");
402 EXPECT_FALSE(wide_string != wide_string_c_same1);
403 EXPECT_FALSE(wide_string_c_same1 != wide_string);
405 WideStringView wide_string_c1(L"he");
406 WideStringView wide_string_c2(L"hellp");
407 WideStringView wide_string_c3(L"hellod");
408 EXPECT_TRUE(wide_string != wide_string_c1);
409 EXPECT_TRUE(wide_string != wide_string_c2);
410 EXPECT_TRUE(wide_string != wide_string_c3);
411 EXPECT_TRUE(wide_string_c1 != wide_string);
412 EXPECT_TRUE(wide_string_c2 != wide_string);
413 EXPECT_TRUE(wide_string_c3 != wide_string);
415 const wchar_t*
const c_null_string =
nullptr;
416 const wchar_t*
const c_empty_string = L"";
417 EXPECT_FALSE(null_string
!= c_null_string);
418 EXPECT_FALSE(null_string
!= c_empty_string);
419 EXPECT_FALSE(empty_string
!= c_null_string);
420 EXPECT_FALSE(empty_string
!= c_empty_string);
421 EXPECT_FALSE(deleted_string
!= c_null_string);
422 EXPECT_FALSE(deleted_string
!= c_empty_string);
423 EXPECT_FALSE(c_null_string
!= null_string);
424 EXPECT_FALSE(c_empty_string
!= null_string);
425 EXPECT_FALSE(c_null_string
!= empty_string);
426 EXPECT_FALSE(c_empty_string
!= empty_string);
427 EXPECT_FALSE(c_null_string
!= deleted_string);
428 EXPECT_FALSE(c_empty_string
!= deleted_string);
430 const wchar_t*
const c_string_same1 = L"hello";
431 EXPECT_FALSE(wide_string
!= c_string_same1);
432 EXPECT_FALSE(c_string_same1
!= wide_string);
434 const wchar_t*
const c_string1 = L"he";
435 const wchar_t*
const c_string2 = L"hellp";
436 const wchar_t*
const c_string3 = L"hellod";
437 EXPECT_TRUE(wide_string
!= c_string1);
438 EXPECT_TRUE(wide_string
!= c_string2);
439 EXPECT_TRUE(wide_string
!= c_string3);
440 EXPECT_TRUE(c_string1
!= wide_string);
441 EXPECT_TRUE(c_string2
!= wide_string);
442 EXPECT_TRUE(c_string3
!= wide_string);
447 EXPECT_EQ(L"Dogs like me",
WideString(L"Dogs"
) + L" like me");
448 EXPECT_EQ(L"Oh no, error number 42",
456 const wchar_t* buffer = str
.c_str();
457 for (size_t i = 0; i < 10000; ++i) {
459 const wchar_t* new_buffer = str
.c_str();
460 if (new_buffer != buffer) {
465 EXPECT_LT(allocations, 25);
466 EXPECT_GT(allocations, 10);
472 fred.Concat(L"FRED", 4);
473 EXPECT_EQ(L"FRED", fred);
475 fred.Concat(L"DY", 2);
476 EXPECT_EQ(L"FREDDY", fred);
479 EXPECT_EQ(L"FRE", fred);
481 fred.Concat(L"D", 1);
482 EXPECT_EQ(L"FRED", fred);
485 fred.Concat(L"DY", 2);
486 EXPECT_EQ(L"FREDDY", fred);
487 EXPECT_EQ(L"FRED", copy);
493 EXPECT_EQ(L"FRD", freed);
495 EXPECT_EQ(L"RD", freed);
497 EXPECT_EQ(L"R", freed);
499 EXPECT_EQ(L"R", freed);
501 EXPECT_EQ(L"", freed);
505 EXPECT_EQ(L"", empty);
510 const wchar_t* old_buffer = freed
.c_str();
514 EXPECT_EQ(L"FREED", freed);
515 EXPECT_EQ(old_buffer, freed
.c_str());
519 EXPECT_EQ(L"FRD", freed);
520 EXPECT_EQ(old_buffer, freed
.c_str());
525 EXPECT_EQ(L"FRD", freed);
526 EXPECT_EQ(old_buffer, freed
.c_str());
527 EXPECT_EQ(old_buffer, shared
.c_str());
531 EXPECT_EQ(L"FR", freed);
532 EXPECT_NE(old_buffer, freed
.c_str());
533 EXPECT_EQ(L"FRD", shared);
534 EXPECT_EQ(old_buffer, shared
.c_str());
539 empty.Replace(L"", L"CLAMS");
540 empty.Replace(L"xx", L"CLAMS");
541 EXPECT_EQ(L"", empty);
544 fred.Replace(L"", L"");
545 EXPECT_EQ(L"FRED", fred);
546 fred.Replace(L"", L"CLAMS");
547 EXPECT_EQ(L"FRED", fred);
548 fred.Replace(L"FR", L"BL");
549 EXPECT_EQ(L"BLED", fred);
550 fred.Replace(L"D", L"DDY");
551 EXPECT_EQ(L"BLEDDY", fred);
552 fred.Replace(L"LEDD", L"");
553 EXPECT_EQ(L"BY", fred);
554 fred.Replace(L"X", L"CLAMS");
555 EXPECT_EQ(L"BY", fred);
556 fred.Replace(L"BY", L"HI");
557 EXPECT_EQ(L"HI", fred);
558 fred.Replace(L"I", L"IHIHI");
559 EXPECT_EQ(L"HIHIHI", fred);
560 fred.Replace(L"HI", L"HO");
561 EXPECT_EQ(L"HOHOHO", fred);
562 fred.Replace(L"HO", L"");
563 EXPECT_EQ(L"", fred);
566 five_xs.Replace(L"xx", L"xxx");
567 EXPECT_EQ(L"xxxxxxx", five_xs);
570 five_ys.Replace(L"yy", L"y");
571 EXPECT_EQ(L"yyy", five_ys);
576 EXPECT_EQ(5u, fred.Insert(0,
'S'));
577 EXPECT_EQ(L"SFRED", fred);
578 EXPECT_EQ(6u, fred.Insert(1,
'T'));
579 EXPECT_EQ(L"STFRED", fred);
580 EXPECT_EQ(7u, fred.Insert(4,
'U'));
581 EXPECT_EQ(L"STFRUED", fred);
582 EXPECT_EQ(8u, fred.Insert(7,
'V'));
583 EXPECT_EQ(L"STFRUEDV", fred);
584 EXPECT_EQ(8u, fred.Insert(12,
'P'));
585 EXPECT_EQ(L"STFRUEDV", fred);
588 EXPECT_EQ(1u, empty.Insert(0,
'X'));
589 EXPECT_EQ(L"X", empty);
593 EXPECT_EQ(0u, empty.Insert(5,
'X'));
594 EXPECT_NE(L"X", empty);
601 EXPECT_EQ(1u, empty.InsertAtFront(
'D'));
602 EXPECT_EQ(L"D", empty);
603 EXPECT_EQ(2u, empty.InsertAtFront(
'E'));
604 EXPECT_EQ(L"ED", empty);
605 EXPECT_EQ(3u, empty.InsertAtFront(
'R'));
606 EXPECT_EQ(L"RED", empty);
607 EXPECT_EQ(4u, empty.InsertAtFront(
'F'));
608 EXPECT_EQ(L"FRED", empty);
612 EXPECT_EQ(1u, empty.InsertAtBack(
'F'));
613 EXPECT_EQ(L"F", empty);
614 EXPECT_EQ(2u, empty.InsertAtBack(
'R'));
615 EXPECT_EQ(L"FR", empty);
616 EXPECT_EQ(3u, empty.InsertAtBack(
'E'));
617 EXPECT_EQ(L"FRE", empty);
618 EXPECT_EQ(4u, empty.InsertAtBack(
'D'));
619 EXPECT_EQ(L"FRED", empty);
623 EXPECT_EQ(1u, empty.InsertAtBack(
'E'));
624 EXPECT_EQ(L"E", empty);
625 EXPECT_EQ(2u, empty.InsertAtFront(
'R'));
626 EXPECT_EQ(L"RE", empty);
627 EXPECT_EQ(3u, empty.InsertAtBack(
'D'));
628 EXPECT_EQ(L"RED", empty);
629 EXPECT_EQ(4u, empty.InsertAtFront(
'F'));
630 EXPECT_EQ(L"FRED", empty);
636 EXPECT_EQ(4u, fred.Delete(0, 0));
637 EXPECT_EQ(L"FRED", fred);
638 EXPECT_EQ(2u, fred.Delete(0, 2));
639 EXPECT_EQ(L"ED", fred);
640 EXPECT_EQ(1u, fred.Delete(1));
641 EXPECT_EQ(L"E", fred);
642 EXPECT_EQ(0u, fred.Delete(0));
643 EXPECT_EQ(L"", fred);
644 EXPECT_EQ(0u, fred.Delete(0));
645 EXPECT_EQ(L"", fred);
648 EXPECT_EQ(0u, empty.Delete(0));
649 EXPECT_EQ(L"", empty);
650 EXPECT_EQ(0u, empty.Delete(1));
651 EXPECT_EQ(L"", empty);
656 EXPECT_EQ(L"FRED", fred.Substr(0));
657 EXPECT_EQ(L"RED", fred.Substr(1));
658 EXPECT_EQ(L"ED", fred.Substr(2));
659 EXPECT_EQ(L"D", fred.Substr(3));
660 EXPECT_EQ(L"", fred.Substr(4));
663 EXPECT_EQ(L"", empty.Substr(0));
664 EXPECT_EQ(L"", empty.Substr(1));
669 EXPECT_EQ(L"", fred.Substr(0, 0));
670 EXPECT_EQ(L"", fred.Substr(3, 0));
671 EXPECT_EQ(L"FRED", fred.Substr(0, 4));
672 EXPECT_EQ(L"RED", fred.Substr(1, 3));
673 EXPECT_EQ(L"ED", fred.Substr(2, 2));
674 EXPECT_EQ(L"D", fred.Substr(3, 1));
675 EXPECT_EQ(L"F", fred.Substr(0, 1));
676 EXPECT_EQ(L"R", fred.Substr(1, 1));
677 EXPECT_EQ(L"E", fred.Substr(2, 1));
678 EXPECT_EQ(L"D", fred.Substr(3, 1));
679 EXPECT_EQ(L"FR", fred.Substr(0, 2));
680 EXPECT_EQ(L"FRED", fred.Substr(0, 4));
681 EXPECT_EQ(L"", fred.Substr(0, 10));
683 EXPECT_EQ(L"", fred.Substr(1, 4));
684 EXPECT_EQ(L"", fred.Substr(4, 1));
687 EXPECT_EQ(L"", empty.Substr(0, 0));
692 EXPECT_EQ(L"", fred.First(0));
693 EXPECT_EQ(L"F", fred.First(1));
694 EXPECT_EQ(L"FR", fred.First(2));
695 EXPECT_EQ(L"FRE", fred.First(3));
696 EXPECT_EQ(L"FRED", fred.First(4));
698 EXPECT_EQ(L"", fred.First(5));
701 EXPECT_EQ(L"", empty.First(0));
702 EXPECT_EQ(L"", empty.First(1));
707 EXPECT_EQ(L"", fred.Last(0));
708 EXPECT_EQ(L"D", fred.Last(1));
709 EXPECT_EQ(L"ED", fred.Last(2));
710 EXPECT_EQ(L"RED", fred.Last(3));
711 EXPECT_EQ(L"FRED", fred.Last(4));
713 EXPECT_EQ(L"", fred.Last(5));
716 EXPECT_EQ(L"", empty.Last(0));
717 EXPECT_EQ(L"", empty.Last(1));
722 EXPECT_FALSE(null_string.Find(L'a').has_value());
723 EXPECT_FALSE(null_string.Find(L'\0').has_value());
726 EXPECT_FALSE(empty_string.Find(L'a').has_value());
727 EXPECT_FALSE(empty_string.Find(L'\0').has_value());
730 absl::optional<size_t> result = single_string.Find(L'a');
731 ASSERT_TRUE(result.has_value());
732 EXPECT_EQ(0u, result.value());
733 EXPECT_FALSE(single_string.Find(L'b').has_value());
734 EXPECT_FALSE(single_string.Find(L'\0').has_value());
737 result = longer_string.Find(L'a');
738 ASSERT_TRUE(result.has_value());
739 EXPECT_EQ(0u, result.value());
740 result = longer_string.Find(L'c');
741 ASSERT_TRUE(result.has_value());
742 EXPECT_EQ(2u, result.value());
743 result = longer_string.Find(L'c', 3);
744 ASSERT_TRUE(result.has_value());
745 EXPECT_EQ(3u, result.value());
746 EXPECT_FALSE(longer_string.Find(L'\0').has_value());
748 result = longer_string.Find(L"ab");
749 ASSERT_TRUE(result.has_value());
750 EXPECT_EQ(0u, result.value());
751 result = longer_string.Find(L"ccc");
752 ASSERT_TRUE(result.has_value());
753 EXPECT_EQ(2u, result.value());
754 result = longer_string.Find(L"cc", 3);
755 ASSERT_TRUE(result.has_value());
756 EXPECT_EQ(3u, result.value());
757 EXPECT_FALSE(longer_string.Find(L"d").has_value());
762 result = hibyte_string.Find(L'\xff8c');
763 ASSERT_TRUE(result.has_value());
764 EXPECT_EQ(2u, result.value());
769 EXPECT_FALSE(null_string.ReverseFind(L'a').has_value());
770 EXPECT_FALSE(null_string.ReverseFind(L'\0').has_value());
773 EXPECT_FALSE(empty_string.ReverseFind(L'a').has_value());
774 EXPECT_FALSE(empty_string.ReverseFind(L'\0').has_value());
777 absl::optional<size_t> result = single_string.ReverseFind(L'a');
778 ASSERT_TRUE(result.has_value());
779 EXPECT_EQ(0u, result.value());
780 EXPECT_FALSE(single_string.ReverseFind(L'b').has_value());
781 EXPECT_FALSE(single_string.ReverseFind(L'\0').has_value());
784 result = longer_string.ReverseFind(L'a');
785 ASSERT_TRUE(result.has_value());
786 EXPECT_EQ(0u, result.value());
787 result = longer_string.ReverseFind(L'c');
788 ASSERT_TRUE(result.has_value());
789 EXPECT_EQ(4u, result.value());
790 EXPECT_FALSE(longer_string.ReverseFind(L'\0').has_value());
795 result = hibyte_string.ReverseFind(L'\xff8c');
796 ASSERT_TRUE(result.has_value());
797 EXPECT_EQ(2u, result.value());
803 EXPECT_EQ(L"f-re.42d", fred);
805 EXPECT_EQ(L"F-RE.42D", fred);
809 EXPECT_EQ(L"", empty);
811 EXPECT_EQ(L"", empty);
814 empty_with_buffer.Delete(0);
816 WideString additional_empty_with_buffer_ref = empty_with_buffer;
818 EXPECT_EQ(L"", additional_empty_with_buffer_ref);
820 additional_empty_with_buffer_ref
= empty_with_buffer;
822 EXPECT_EQ(L"", additional_empty_with_buffer_ref);
828 EXPECT_EQ(L"FRED", fred);
830 EXPECT_EQ(L"FRED", fred);
832 EXPECT_EQ(L"RED", fred);
834 EXPECT_EQ(L"D", fred);
838 EXPECT_EQ(L" ", blank);
840 EXPECT_EQ(L" ", blank);
842 EXPECT_EQ(L"", blank);
846 EXPECT_EQ(L"", empty);
848 EXPECT_EQ(L"", empty);
850 EXPECT_EQ(L"", empty);
854 EXPECT_EQ(L" ABCCBA ", abc);
856 EXPECT_EQ(L"BCCB", abc);
862 EXPECT_EQ(L"FRED ", fred);
864 EXPECT_EQ(L"FRED ", fred);
866 EXPECT_EQ(L"RED ", fred);
867 fred.TrimLeft(L"ERP");
868 EXPECT_EQ(L"D ", fred);
871 blank.TrimLeft(L"ERP");
872 EXPECT_EQ(L" ", blank);
874 EXPECT_EQ(L" ", blank);
876 EXPECT_EQ(L"", blank);
879 empty.TrimLeft(L"ERP");
880 EXPECT_EQ(L"", empty);
882 EXPECT_EQ(L"", empty);
884 EXPECT_EQ(L"", empty);
891 const wchar_t* old_buffer = fred
.c_str();
893 EXPECT_EQ(L"FRED ", fred);
894 EXPECT_EQ(old_buffer, fred
.c_str());
900 const wchar_t* old_buffer = fred
.c_str();
902 EXPECT_EQ(L"FRED ", fred);
903 EXPECT_EQ(L" FRED ", other_fred);
904 EXPECT_NE(old_buffer, fred
.c_str());
910 const wchar_t* old_buffer = fred
.c_str();
912 EXPECT_EQ(L"FRED", fred);
913 EXPECT_EQ(L"FRED", other_fred);
914 EXPECT_EQ(old_buffer, fred
.c_str());
921 EXPECT_EQ(L" FRED", fred);
923 EXPECT_EQ(L" FRED", fred);
925 EXPECT_EQ(L" FRE", fred);
926 fred.TrimRight(L"ERP");
927 EXPECT_EQ(L" F", fred);
930 blank.TrimRight(L"ERP");
931 EXPECT_EQ(L" ", blank);
933 EXPECT_EQ(L" ", blank);
935 EXPECT_EQ(L"", blank);
938 empty.TrimRight(L"ERP");
939 EXPECT_EQ(L"", empty);
941 EXPECT_EQ(L"", empty);
943 EXPECT_EQ(L"", empty);
950 const wchar_t* old_buffer = fred
.c_str();
952 EXPECT_EQ(L" FRED", fred);
953 EXPECT_EQ(old_buffer, fred
.c_str());
959 const wchar_t* old_buffer = fred
.c_str();
961 EXPECT_EQ(L" FRED", fred);
962 EXPECT_EQ(L" FRED ", other_fred);
963 EXPECT_NE(old_buffer, fred
.c_str());
969 const wchar_t* old_buffer = fred
.c_str();
971 EXPECT_EQ(L"FRED", fred);
972 EXPECT_EQ(L"FRED", other_fred);
973 EXPECT_EQ(old_buffer, fred
.c_str());
981 const wchar_t* old_buffer = str
.c_str();
984 str
+= L"Blah Blah Blah Blah Blah Blah";
990 const wchar_t* old_buffer = str
.c_str();
993 str
+= L"Blah Blah Blah Blah Blah Blah";
1001 pdfium::span<
wchar_t> buffer = str1.GetBuffer(12);
1002 wcscpy(buffer.data(), L"clams");
1004 str1.ReleaseBuffer(str1.GetStringLength());
1005 EXPECT_EQ(L"clams", str1);
1009 pdfium::span<
wchar_t> buffer = str2.GetBuffer(12);
1010 wcscpy(buffer.data() + 2, L"ams");
1012 str2.ReleaseBuffer(str2.GetStringLength());
1013 EXPECT_EQ(L"clams", str2);
1021 const wchar_t* old_buffer = str
.c_str();
1022 str.ReleaseBuffer(4);
1023 EXPECT_EQ(old_buffer, str
.c_str());
1024 EXPECT_EQ(L"clam", str);
1030 const wchar_t* old_buffer = str
.c_str();
1031 str.ReleaseBuffer(4);
1032 EXPECT_EQ(old_buffer, str
.c_str());
1033 EXPECT_EQ(L"clam", str);
1039 const wchar_t* old_buffer = str
.c_str();
1040 str.ReleaseBuffer(4);
1041 EXPECT_NE(old_buffer, str
.c_str());
1042 EXPECT_EQ(L"clam", str);
1048 const wchar_t* old_buffer = str
.c_str();
1049 str.ReleaseBuffer(4);
1050 EXPECT_NE(old_buffer, str
.c_str());
1051 EXPECT_EQ(L"clam", str);
1057 auto iter = empty.rbegin();
1058 EXPECT_TRUE(iter == empty.rend());
1059 EXPECT_FALSE(iter != empty.rend());
1060 EXPECT_FALSE(iter < empty.rend());
1065 auto iter = one_str.rbegin();
1066 EXPECT_FALSE(iter == one_str.rend());
1067 EXPECT_TRUE(iter != one_str.rend());
1068 EXPECT_TRUE(iter < one_str.rend());
1072 EXPECT_TRUE(iter == one_str.rend());
1073 EXPECT_FALSE(iter != one_str.rend());
1074 EXPECT_FALSE(iter < one_str.rend());
1079 auto iter = multi_str.rbegin();
1080 EXPECT_NE(iter, multi_str.rend());
1081 EXPECT_EQ(4, multi_str.rend() - iter);
1082 EXPECT_EQ(0, iter - multi_str.rbegin());
1086 EXPECT_EQ(
'c', *iter);
1087 EXPECT_NE(iter, multi_str.rend());
1088 EXPECT_EQ(3, multi_str.rend() - iter);
1089 EXPECT_EQ(1, iter - multi_str.rbegin());
1093 EXPECT_EQ(
'b', *iter);
1094 EXPECT_NE(iter, multi_str.rend());
1095 EXPECT_EQ(2, multi_str.rend() - iter);
1096 EXPECT_EQ(2, iter - multi_str.rbegin());
1100 EXPECT_EQ(
'a', *iter);
1101 EXPECT_NE(iter, multi_str.rend());
1102 EXPECT_EQ(1, multi_str.rend() - iter);
1103 EXPECT_EQ(3, iter - multi_str.rbegin());
1107 EXPECT_EQ(iter, multi_str.rend());
1108 EXPECT_EQ(0, multi_str.rend() - iter);
1109 EXPECT_EQ(4, iter - multi_str.rbegin());
1113 EXPECT_EQ(
'a', *iter);
1114 EXPECT_NE(iter, multi_str.rend());
1115 EXPECT_EQ(1, multi_str.rend() - iter);
1116 EXPECT_EQ(3, iter - multi_str.rbegin());
1120 EXPECT_EQ(
'b', *iter);
1121 EXPECT_NE(iter, multi_str.rend());
1122 EXPECT_EQ(2, multi_str.rend() - iter);
1123 EXPECT_EQ(2, iter - multi_str.rbegin());
1127 EXPECT_EQ(
'c', *iter);
1128 EXPECT_NE(iter, multi_str.rend());
1129 EXPECT_EQ(3, multi_str.rend() - iter);
1130 EXPECT_EQ(1, iter - multi_str.rbegin());
1134 EXPECT_EQ(
'd', *iter);
1135 EXPECT_EQ(iter, multi_str.rbegin());
1136 EXPECT_EQ(4, multi_str.rend() - iter);
1137 EXPECT_EQ(0, iter - multi_str.rbegin());
1173 <<
"Invalid continuation";
1175 <<
"Invalid continuation";
1177 <<
"Invalid continuation";
1181 <<
"Invalid leading";
1183 <<
"Invalid leading";
1185 <<
"Code point greater than U+10FFFF";
1190 wstr.Reserve(0x10000);
1196 wstr
+= static_cast<
wchar_t>(w);
1198 ASSERT_EQ(0xf800u, wstr.GetLength());
1200 ByteString bstr = FX_UTF8Encode(wstr.AsStringView());
1202 EXPECT_EQ(wstr, wstr2);
1207 wstr.Reserve(0x400);
1212 ASSERT_EQ(0x400u, wstr.GetLength());
1214 ByteString bstr = FX_UTF8Encode(wstr.AsStringView());
1216 EXPECT_EQ(wstr, wstr2);
1221 wstr.Reserve(0x400);
1226 ASSERT_EQ(0x400u, wstr.GetLength());
1228 ByteString bstr = FX_UTF8Encode(wstr.AsStringView());
1230 EXPECT_EQ(wstr, wstr2);
1234 struct UTF16BEDecodeCase {
1237 }
const utf16be_decode_cases[] = {
1239 {ByteString(
"\0a\0b\0c", 6), L"abc"},
1240 {ByteString(
"\0a\0b\0c\0\0\0d\0e\0f", 14), WideString(L"abc\0def", 7)},
1241 {ByteString(
" &", 2), L"…"},
1242 {ByteString(
"\xD8\x3C\xDF\xA8", 4), L"🎨"},
1245 for (size_t i = 0; i <
std::size(utf16be_decode_cases); ++i) {
1247 utf16be_decode_cases[i].out)
1248 <<
" for case number " << i;
1253 struct UTF16LEDecodeCase {
1256 }
const utf16le_decode_cases[] = {
1258 {ByteString(
"a\0b\0c\0", 6), L"abc"},
1259 {ByteString(
"a\0b\0c\0\0\0d\0e\0f\0", 14), WideString(L"abc\0def", 7)},
1260 {ByteString(
"& ", 2), L"…"},
1261 {ByteString(
"\x3C\xD8\xA8\xDF", 4), L"🎨"},
1264 for (size_t i = 0; i <
std::size(utf16le_decode_cases); ++i) {
1266 utf16le_decode_cases[i].out)
1267 <<
" for case number " << i;
1272 struct UTF16LEEncodeCase {
1275 }
const utf16le_encode_cases[] = {
1276 {L"", ByteString(
"\0\0", 2)},
1277 {L"abc", ByteString(
"a\0b\0c\0\0\0", 8)},
1278 {L"abcdef", ByteString(
"a\0b\0c\0d\0e\0f\0\0\0", 14)},
1279 {L"abc\0def", ByteString(
"a\0b\0c\0\0\0", 8)},
1280 {L"\xaabb\xccdd", ByteString(
"\xbb\xaa\xdd\xcc\0\0", 6)},
1281 {L"\x3132\x6162", ByteString(
"\x32\x31\x62\x61\0\0", 6)},
1282 {L"🎨", ByteString(
"\x3C\xD8\xA8\xDF\0\0", 6)},
1285 for (size_t i = 0; i <
std::size(utf16le_encode_cases); ++i) {
1286 EXPECT_EQ(utf16le_encode_cases[i].bs,
1287 utf16le_encode_cases[i].ws.ToUTF16LE())
1288 <<
" for case number " << i;
1294 L"Symbols &<>'".");
1324 const char* kResult =
1341 const char* kResult =
1359#if BUILDFLAG(IS_WIN)
1360 const char* kResult =
1368 const char* kResult =
1385 const wchar_t* kResult =
1398 const wchar_t* kResult =
1411#if BUILDFLAG(IS_WIN)
1412 const wchar_t* kResult =
1418 const wchar_t* kResult =
1431 std::vector<WideStringView::UnsignedType> null_vec;
1432 WideStringView null_string(null_vec);
1433 EXPECT_EQ(0u, null_string.GetLength());
1435 std::vector<WideStringView::UnsignedType> lower_a_vec(
1436 10,
static_cast<WideStringView::UnsignedType>(L'a'));
1437 WideStringView lower_a_string(lower_a_vec);
1438 EXPECT_EQ(10u, lower_a_string.GetLength());
1439 EXPECT_EQ(L"aaaaaaaaaa", lower_a_string);
1441 std::vector<WideStringView::UnsignedType> cleared_vec;
1442 cleared_vec.push_back(42);
1443 cleared_vec.pop_back();
1444 WideStringView cleared_string(cleared_vec);
1445 EXPECT_EQ(0u, cleared_string.GetLength());
1446 EXPECT_FALSE(cleared_string.raw_str());
1450 WideStringView abc(L"abc");
1451 EXPECT_EQ(L'a',
static_cast<
wchar_t>(abc[0]));
1452 EXPECT_EQ(L'b',
static_cast<
wchar_t>(abc[1]));
1453 EXPECT_EQ(L'c',
static_cast<
wchar_t>(abc[2]));
1455 EXPECT_DEATH({ abc[4]; },
"");
1460 WideStringView empty;
1461 WideStringView a(L"a");
1462 WideStringView abc(L"\x0110qq");
1463 WideStringView def(L"\x1001qq");
1464 const wchar_t*
const c_null =
nullptr;
1465 const wchar_t*
const c_empty = L"";
1466 const wchar_t*
const c_a = L"a";
1467 const wchar_t*
const c_abc = L"\x0110qq";
1468 const wchar_t*
const c_def = L"\x1001qq";
1470 EXPECT_FALSE(empty < empty);
1471 EXPECT_FALSE(a < a);
1472 EXPECT_FALSE(abc < abc);
1473 EXPECT_FALSE(def < def);
1474 EXPECT_FALSE(c_null < empty);
1475 EXPECT_FALSE(c_empty < empty);
1476 EXPECT_FALSE(c_a < a);
1477 EXPECT_FALSE(c_abc < abc);
1478 EXPECT_FALSE(c_def < def);
1479 EXPECT_FALSE(empty < c_null);
1480 EXPECT_FALSE(empty < c_empty);
1481 EXPECT_FALSE(a < c_a);
1482 EXPECT_FALSE(abc < c_abc);
1483 EXPECT_FALSE(def < c_def);
1485 EXPECT_TRUE(empty < a);
1486 EXPECT_FALSE(a < empty);
1487 EXPECT_TRUE(empty < c_a);
1488 EXPECT_FALSE(a < c_null);
1489 EXPECT_FALSE(a < c_empty);
1491 EXPECT_TRUE(empty < abc);
1492 EXPECT_FALSE(abc < empty);
1493 EXPECT_TRUE(empty < c_abc);
1494 EXPECT_FALSE(abc < c_null);
1495 EXPECT_FALSE(abc < c_empty);
1497 EXPECT_TRUE(empty < def);
1498 EXPECT_FALSE(def < empty);
1499 EXPECT_TRUE(empty < c_def);
1500 EXPECT_FALSE(def < c_null);
1501 EXPECT_FALSE(def < c_empty);
1503 EXPECT_TRUE(a < abc);
1504 EXPECT_FALSE(abc < a);
1505 EXPECT_TRUE(a < c_abc);
1506 EXPECT_FALSE(abc < c_a);
1508 EXPECT_TRUE(a < def);
1509 EXPECT_FALSE(def < a);
1510 EXPECT_TRUE(a < c_def);
1511 EXPECT_FALSE(def < c_a);
1513 EXPECT_TRUE(abc < def);
1514 EXPECT_FALSE(def < abc);
1515 EXPECT_TRUE(abc < c_def);
1516 EXPECT_FALSE(def < c_abc);
1520 WideStringView wide_string_c(L"hello");
1521 EXPECT_TRUE(wide_string_c == wide_string_c);
1523 WideStringView wide_string_c_same1(L"hello");
1524 EXPECT_TRUE(wide_string_c == wide_string_c_same1);
1525 EXPECT_TRUE(wide_string_c_same1 == wide_string_c);
1527 WideStringView wide_string_c_same2(wide_string_c);
1528 EXPECT_TRUE(wide_string_c == wide_string_c_same2);
1529 EXPECT_TRUE(wide_string_c_same2 == wide_string_c);
1531 WideStringView wide_string_c1(L"he");
1532 WideStringView wide_string_c2(L"hellp");
1533 WideStringView wide_string_c3(L"hellod");
1534 EXPECT_FALSE(wide_string_c == wide_string_c1);
1535 EXPECT_FALSE(wide_string_c == wide_string_c2);
1536 EXPECT_FALSE(wide_string_c == wide_string_c3);
1537 EXPECT_FALSE(wide_string_c1 == wide_string_c);
1538 EXPECT_FALSE(wide_string_c2 == wide_string_c);
1539 EXPECT_FALSE(wide_string_c3 == wide_string_c);
1542 EXPECT_TRUE(wide_string_c == wide_string_same1);
1543 EXPECT_TRUE(wide_string_same1 == wide_string_c);
1548 EXPECT_FALSE(wide_string_c == wide_string1);
1549 EXPECT_FALSE(wide_string_c == wide_string2);
1550 EXPECT_FALSE(wide_string_c == wide_string3);
1551 EXPECT_FALSE(wide_string1 == wide_string_c);
1552 EXPECT_FALSE(wide_string2 == wide_string_c);
1553 EXPECT_FALSE(wide_string3 == wide_string_c);
1555 const wchar_t*
const c_string_same1 = L"hello";
1556 EXPECT_TRUE(wide_string_c == c_string_same1);
1557 EXPECT_TRUE(c_string_same1 == wide_string_c);
1559 const wchar_t*
const c_string1 = L"he";
1560 const wchar_t*
const c_string2 = L"hellp";
1561 const wchar_t*
const c_string3 = L"hellod";
1562 EXPECT_FALSE(wide_string_c == c_string1);
1563 EXPECT_FALSE(wide_string_c == c_string2);
1564 EXPECT_FALSE(wide_string_c == c_string3);
1566 EXPECT_FALSE(c_string1 == wide_string_c);
1567 EXPECT_FALSE(c_string2 == wide_string_c);
1568 EXPECT_FALSE(c_string3 == wide_string_c);
1572 WideStringView wide_string_c(L"hello");
1573 EXPECT_FALSE(wide_string_c != wide_string_c);
1575 WideStringView wide_string_c_same1(L"hello");
1576 EXPECT_FALSE(wide_string_c != wide_string_c_same1);
1577 EXPECT_FALSE(wide_string_c_same1 != wide_string_c);
1579 WideStringView wide_string_c_same2(wide_string_c);
1580 EXPECT_FALSE(wide_string_c != wide_string_c_same2);
1581 EXPECT_FALSE(wide_string_c_same2 != wide_string_c);
1583 WideStringView wide_string_c1(L"he");
1584 WideStringView wide_string_c2(L"hellp");
1585 WideStringView wide_string_c3(L"hellod");
1586 EXPECT_TRUE(wide_string_c != wide_string_c1);
1587 EXPECT_TRUE(wide_string_c != wide_string_c2);
1588 EXPECT_TRUE(wide_string_c != wide_string_c3);
1589 EXPECT_TRUE(wide_string_c1 != wide_string_c);
1590 EXPECT_TRUE(wide_string_c2 != wide_string_c);
1591 EXPECT_TRUE(wide_string_c3 != wide_string_c);
1594 EXPECT_FALSE(wide_string_c != wide_string_same1);
1595 EXPECT_FALSE(wide_string_same1 != wide_string_c);
1600 EXPECT_TRUE(wide_string_c != wide_string1);
1601 EXPECT_TRUE(wide_string_c != wide_string2);
1602 EXPECT_TRUE(wide_string_c != wide_string3);
1603 EXPECT_TRUE(wide_string1 != wide_string_c);
1604 EXPECT_TRUE(wide_string2 != wide_string_c);
1605 EXPECT_TRUE(wide_string3 != wide_string_c);
1607 const wchar_t*
const c_string_same1 = L"hello";
1608 EXPECT_FALSE(wide_string_c != c_string_same1);
1609 EXPECT_FALSE(c_string_same1 != wide_string_c);
1611 const wchar_t*
const c_string1 = L"he";
1612 const wchar_t*
const c_string2 = L"hellp";
1613 const wchar_t*
const c_string3 = L"hellod";
1614 EXPECT_TRUE(wide_string_c != c_string1);
1615 EXPECT_TRUE(wide_string_c != c_string2);
1616 EXPECT_TRUE(wide_string_c != c_string3);
1618 EXPECT_TRUE(c_string1 != wide_string_c);
1619 EXPECT_TRUE(c_string2 != wide_string_c);
1620 EXPECT_TRUE(c_string3 != wide_string_c);
1624 WideStringView null_string;
1625 EXPECT_FALSE(null_string.Find(L'a').has_value());
1626 EXPECT_FALSE(null_string.Find(L'\0').has_value());
1628 WideStringView empty_string(L"");
1629 EXPECT_FALSE(empty_string.Find(L'a').has_value());
1630 EXPECT_FALSE(empty_string.Find(L'\0').has_value());
1632 WideStringView single_string(L"a");
1633 absl::optional<size_t> result = single_string.Find(L'a');
1634 ASSERT_TRUE(result.has_value());
1635 EXPECT_EQ(0u, result.value());
1636 EXPECT_FALSE(single_string.Find(L'b').has_value());
1637 EXPECT_FALSE(single_string.Find(L'\0').has_value());
1639 WideStringView longer_string(L"abccc");
1640 result = longer_string.Find(L'a');
1641 ASSERT_TRUE(result.has_value());
1642 EXPECT_EQ(0u, result.value());
1643 result = longer_string.Find(L'c');
1644 ASSERT_TRUE(result.has_value());
1645 EXPECT_EQ(2u, result.value());
1646 EXPECT_FALSE(longer_string.Find(L'd').has_value());
1647 EXPECT_FALSE(longer_string.Find(L'\0').has_value());
1649 WideStringView hibyte_string(
1652 result = hibyte_string.Find(L'\xFF8c');
1653 ASSERT_TRUE(result.has_value());
1654 EXPECT_EQ(2u, result.value());
1658 WideStringView null_str;
1660 bool any_present =
false;
1661 for (
const auto& c : null_str) {
1665 EXPECT_FALSE(any_present);
1670 WideStringView empty_str(L"");
1672 bool any_present =
false;
1673 for (
const auto& c : empty_str) {
1677 EXPECT_FALSE(any_present);
1682 WideStringView one_str(L"a");
1684 bool any_present =
false;
1685 for (
const auto& c : one_str) {
1689 EXPECT_TRUE(any_present);
1690 EXPECT_EQ(
static_cast<int32_t>(L'a'), sum);
1694 WideStringView one_str(L"abc");
1696 bool any_present =
false;
1697 for (
const auto& c : one_str) {
1701 EXPECT_TRUE(any_present);
1702 EXPECT_EQ(
static_cast<int32_t>(L'a' + L'b' + L'c'), sum);
1706 WideStringView empty;
1707 auto iter = empty.rbegin();
1708 EXPECT_TRUE(iter == empty.rend());
1709 EXPECT_FALSE(iter != empty.rend());
1710 EXPECT_FALSE(iter < empty.rend());
1714 WideStringView one_str(L"a");
1715 auto iter = one_str.rbegin();
1716 EXPECT_FALSE(iter == one_str.rend());
1717 EXPECT_TRUE(iter != one_str.rend());
1718 EXPECT_TRUE(iter < one_str.rend());
1722 EXPECT_TRUE(iter == one_str.rend());
1723 EXPECT_FALSE(iter != one_str.rend());
1724 EXPECT_FALSE(iter < one_str.rend());
1728 WideStringView multi_str(L"abcd");
1729 auto iter = multi_str.rbegin();
1730 EXPECT_FALSE(iter == multi_str.rend());
1734 EXPECT_EQ(
'c', *iter);
1735 EXPECT_FALSE(iter == multi_str.rend());
1739 EXPECT_EQ(
'b', *iter);
1740 EXPECT_FALSE(iter == multi_str.rend());
1744 EXPECT_EQ(
'a', *iter);
1745 EXPECT_FALSE(iter == multi_str.rend());
1749 EXPECT_TRUE(iter == multi_str.rend());
1753 EXPECT_EQ(
'a', *iter);
1754 EXPECT_FALSE(iter == multi_str.rend());
1758 EXPECT_EQ(
'b', *iter);
1759 EXPECT_FALSE(iter == multi_str.rend());
1763 EXPECT_EQ(
'c', *iter);
1764 EXPECT_FALSE(iter == multi_str.rend());
1768 EXPECT_EQ(
'd', *iter);
1769 EXPECT_TRUE(iter == multi_str.rbegin());
1773 WideStringView str(L"aaaaaaaaaaaaaaaaab");
1774 EXPECT_FALSE(
std::all_of(str.begin(), str.end(),
1775 [](
const wchar_t& c) {
return c == L'a'; }));
1777 EXPECT_FALSE(
std::none_of(str.begin(), str.end(),
1778 [](
const wchar_t& c) {
return c == L'a'; }));
1780 EXPECT_TRUE(
std::any_of(str.begin(), str.end(),
1781 [](
const wchar_t& c) {
return c == L'a'; }));
1783 EXPECT_TRUE(pdfium::Contains(str, L'a'));
1784 EXPECT_TRUE(pdfium::Contains(str, L'b'));
1785 EXPECT_FALSE(pdfium::Contains(str, L'z'));
1789 WideStringView fred(L"FRED");
1790 EXPECT_EQ(L"FRED", fred.TrimmedRight(L'E'));
1791 EXPECT_EQ(L"FRE", fred.TrimmedRight(L'D'));
1792 WideStringView fredd(L"FREDD");
1793 EXPECT_EQ(L"FRE", fred.TrimmedRight(L'D'));
1824 EXPECT_EQ(L"\u043e\u043f",
WideString(L"\u043e\u043f"
));
1826#if !BUILDFLAG(IS_APPLE)
1828 EXPECT_EQ(L"\u043e\u043f", WideString::Format(L"\u043e\u043f"));
1829 EXPECT_EQ(L"\u043e\u043f", WideString::Format(L"%ls", L"\u043e\u043f"));
1830 EXPECT_EQ(L"\u043e", WideString::Format(L"%.1ls", L"\u043e\u043f"));
1837 EXPECT_EQ(0u, empty_str.GetLength());
1839 const wchar_t* cstr = empty_str
.c_str();
1841 EXPECT_EQ(0u, wcslen(cstr));
1843 pdfium::span<
const wchar_t> cspan = empty_str.span();
1844 EXPECT_TRUE(cspan.empty());
1845 EXPECT_FALSE(cspan.data());
1849 WideString many_str({L"clams", L" and ", L"oysters"});
1850 EXPECT_EQ(L"clams and oysters", many_str);
1851 many_str = {L"fish", L" and ", L"chips", L" and ", L"soda"};
1852 EXPECT_EQ(L"fish and chips and soda", many_str);
1858 bool any_present =
false;
1859 for (
const auto& c : null_str) {
1863 EXPECT_FALSE(any_present);
1870 bool any_present =
false;
1871 for (
const auto& c : empty_str) {
1875 EXPECT_FALSE(any_present);
1882 bool any_present =
false;
1883 for (
const auto& c : one_str) {
1887 EXPECT_TRUE(any_present);
1888 EXPECT_EQ(
static_cast<int32_t>(L'a'), sum);
1894 bool any_present =
false;
1895 for (
const auto& c : one_str) {
1899 EXPECT_TRUE(any_present);
1900 EXPECT_EQ(
static_cast<int32_t>(L'a' + L'b' + L'c'), sum);
1905 std::vector<
wchar_t> vec(std::begin(one_str), std::end(one_str));
1906 ASSERT_EQ(3u, vec.size());
1907 EXPECT_EQ(L'a', vec[0]);
1908 EXPECT_EQ(L'b', vec[1]);
1909 EXPECT_EQ(L'c', vec[2]);
1915 [](
const wchar_t& c) {
return c == L'a'; }));
1918 [](
const wchar_t& c) {
return c == L'a'; }));
1921 [](
const wchar_t& c) {
return c == L'a'; }));
1923 EXPECT_TRUE(pdfium::Contains(str, L'a'));
1924 EXPECT_TRUE(pdfium::Contains(str, L'b'));
1925 EXPECT_FALSE(pdfium::Contains(str, L'z'));
1929 std::ostringstream stream;
1934 EXPECT_EQ(
"", stream.str());
1939 EXPECT_EQ(
"\u20AC", stream.str());
1944 stream <<
"abc" << str <<
"ghi";
1945 EXPECT_EQ(
"abcdefghi", stream.str());
1949 EXPECT_EQ(
"abcdefghi", stream.str());
1953 stream <<
"abc" << str <<
"ghi";
1954 EXPECT_EQ(
"abc123ghi", stream.str());
1956 wchar_t stringWithNulls[]{
'x',
'y',
'\0',
'z'};
1961 EXPECT_EQ(2u, str.GetLength());
1964 EXPECT_EQ(2u, stream.tellp());
1968 str
= WideString(stringWithNulls, 4);
1969 EXPECT_EQ(4u, str.GetLength());
1972 EXPECT_EQ(4u, stream.tellp());
1978 stream << str1 << str2;
1979 EXPECT_EQ(
"abcdef", stream.str());
1983 std::wostringstream stream;
1988 EXPECT_EQ(L"", stream.str());
1993 EXPECT_EQ(L"\u20AC", stream.str());
1998 stream << L"abc" << str << L"ghi";
1999 EXPECT_EQ(L"abcdefghi", stream.str());
2003 EXPECT_EQ(L"abcdefghi", stream.str());
2007 stream << L"abc" << str << L"ghi";
2008 EXPECT_EQ(L"abc123ghi", stream.str());
2010 wchar_t stringWithNulls[]{
'x',
'y',
'\0',
'z'};
2015 EXPECT_EQ(2u, str.GetLength());
2018 EXPECT_EQ(2u, stream.tellp());
2022 str
= WideString(stringWithNulls, 4);
2023 EXPECT_EQ(4u, str.GetLength());
2026 EXPECT_EQ(4u, stream.tellp());
2032 stream << str1 << str2;
2033 EXPECT_EQ(L"abcdef", stream.str());
2039 std::ostringstream stream;
2042 EXPECT_EQ(
"", stream.str());
2047 std::ostringstream stream;
2048 WideStringView str(L"def");
2049 stream <<
"abc" << str <<
"ghi";
2050 EXPECT_EQ(
"abcdefghi", stream.str());
2055 std::ostringstream stream;
2056 WideStringView str(L"\u20AC");
2058 EXPECT_EQ(
"\u20AC", stream.str());
2063 std::ostringstream stream;
2064 WideStringView str(L"abc");
2067 EXPECT_EQ(
"abc", stream.str());
2072 std::ostringstream stream;
2073 WideStringView str(L"abc");
2078 EXPECT_EQ(
"123", stream.str());
2084 wchar_t stringWithNulls[]{
'x',
'y',
'\0',
'z'};
2085 std::ostringstream stream;
2086 WideStringView str(stringWithNulls);
2087 EXPECT_EQ(2u, str.GetLength());
2089 EXPECT_EQ(2u, stream.tellp());
2096 wchar_t stringWithNulls[]{
'x',
'y',
'\0',
'z'};
2097 std::ostringstream stream;
2098 WideStringView str(stringWithNulls, 4);
2099 EXPECT_EQ(4u, str.GetLength());
2101 EXPECT_EQ(4u, stream.tellp());
2107 std::ostringstream stream;
2108 WideStringView str1(L"abc");
2109 WideStringView str2(L"def");
2110 stream << str1 << str2;
2111 EXPECT_EQ(
"abcdef", stream.str());
2118 std::wostringstream stream;
2121 EXPECT_EQ(L"", stream.str());
2126 std::wostringstream stream;
2127 WideStringView str(L"def");
2128 stream <<
"abc" << str <<
"ghi";
2129 EXPECT_EQ(L"abcdefghi", stream.str());
2134 std::wostringstream stream;
2135 WideStringView str(L"\u20AC");
2137 EXPECT_EQ(L"\u20AC", stream.str());
2142 std::wostringstream stream;
2143 WideStringView str(L"abc");
2146 EXPECT_EQ(L"abc", stream.str());
2151 std::wostringstream stream;
2152 WideStringView str(L"abc");
2157 EXPECT_EQ(L"123", stream.str());
2163 wchar_t stringWithNulls[]{
'x',
'y',
'\0',
'z'};
2164 std::wostringstream stream;
2165 WideStringView str(stringWithNulls);
2166 EXPECT_EQ(2u, str.GetLength());
2168 EXPECT_EQ(2u, stream.tellp());
2174 wchar_t stringWithNulls[]{
'x',
'y',
'\0',
'z'};
2175 std::wostringstream stream;
2176 WideStringView str(stringWithNulls, 4);
2177 EXPECT_EQ(4u, str.GetLength());
2179 EXPECT_EQ(4u, stream.tellp());
2184 std::wostringstream stream;
2185 WideStringView str1(L"abc");
2186 WideStringView str2(L"def");
2187 stream << str1 << str2;
2188 EXPECT_EQ(L"abcdef", stream.str());
2203 EXPECT_EQ(L"2147483647", WideString::FormatInteger(INT_MAX));
2204 EXPECT_EQ(L"-2147483648", WideString::FormatInteger(INT_MIN));
2208 EXPECT_EQ(0u, FX_HashCode_GetW(L""));
2209 EXPECT_EQ(65u, FX_HashCode_GetW(L"A"));
2210 EXPECT_EQ(97u, FX_HashCode_GetLoweredW(L"A"));
2211 EXPECT_EQ(1313 * 65u + 66u, FX_HashCode_GetW(L"AB"));
2212 EXPECT_EQ(FX_HashCode_GetAsIfW(
"AB\xff"), FX_HashCode_GetW(L"AB\xff"));
2213 EXPECT_EQ(FX_HashCode_GetLoweredAsIfW(
"AB\xff"),
2214 FX_HashCode_GetLoweredW(L"AB\xff"));
bool operator==(const WideString &other) const
static WideString Format(const wchar_t *pFormat,...)
WideString & operator=(WideString &&that) noexcept
static WideString FromUTF8(ByteStringView str)
WideString & operator+=(const wchar_t *str)
bool operator==(const wchar_t *ptr) const
WideString & operator+=(wchar_t ch)
void TrimLeft(wchar_t target)
bool EqualsASCIINoCase(ByteStringView that) const
CharType operator[](const size_t index) const
const wchar_t * c_str() const
static WideString FromDefANSI(ByteStringView str)
WideString(const WideString &other)
WideString(const wchar_t *ptr)
static WideString FromLatin1(ByteStringView str)
bool operator!=(const WideString &other) const
ByteString ToLatin1() const
intptr_t ReferenceCountForTesting() const
static WideString FromUTF16BE(pdfium::span< const uint8_t > data)
bool operator<(const WideString &other) const
WideString & operator=(const WideString &that)
void TrimRight(wchar_t target)
WideString EncodeEntities() const
ByteString ToASCII() const
static WideString FromASCII(ByteStringView str)
const_iterator end() const
static WideString FromUTF16LE(pdfium::span< const uint8_t > data)
WideString & operator=(const wchar_t *str)
const_iterator begin() const
void Trim(wchar_t target)
bool operator!=(const wchar_t *ptr) const
static WideString FormatInteger(int i)
bool EqualsASCII(ByteStringView that) const
ByteString ToDefANSI() const
bool operator<(const wchar_t *ptr) const
bool operator==(const wchar_t *lhs, const WideString &rhs)
TEST(CFX_BytrString, EqualNoCase)
bool operator!=(const wchar_t *lhs, const WideString &rhs)
TEST(WideStringView, FromVector)
TEST(WideString, ElementAccess)
WideString operator+(const wchar_t *str1, const WideString &str2)
bool operator<(const wchar_t *lhs, const WideString &rhs)
WideString operator+(const WideString &str1, const wchar_t *str2)
constexpr char32_t kMinimumSupplementaryCodePoint
constexpr bool IsHighSurrogate(char32_t code_point)
constexpr char16_t kMaximumHighSurrogateCodeUnit
constexpr char16_t kMaximumLowSurrogateCodeUnit
constexpr char16_t kMinimumHighSurrogateCodeUnit
constexpr bool IsLowSurrogate(char32_t code_point)
constexpr char16_t kMinimumLowSurrogateCodeUnit