Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringView.cpp

Issue 2764243002: Move files in wtf/ to platform/wtf/ (Part 9). (Closed)
Patch Set: Rebase. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "wtf/text/StringView.h"
6
7 #include "wtf/text/AtomicString.h"
8 #include "wtf/text/StringImpl.h"
9 #include "wtf/text/WTFString.h"
10
11 namespace WTF {
12
13 StringView::StringView(const UChar* chars)
14 : StringView(chars, chars ? lengthOfNullTerminatedString(chars) : 0) {}
15
16 #if DCHECK_IS_ON()
17 StringView::~StringView() {
18 DCHECK(m_impl);
19 DCHECK(!m_impl->hasOneRef() || m_impl->isStatic())
20 << "StringView does not own the StringImpl, it "
21 "must not have the last ref.";
22 }
23 #endif
24
25 String StringView::toString() const {
26 if (isNull())
27 return String();
28 if (isEmpty())
29 return emptyString;
30 if (StringImpl* impl = sharedImpl())
31 return impl;
32 if (is8Bit())
33 return String(characters8(), m_length);
34 return StringImpl::create8BitIfPossible(characters16(), m_length);
35 }
36
37 AtomicString StringView::toAtomicString() const {
38 if (isNull())
39 return nullAtom;
40 if (isEmpty())
41 return emptyAtom;
42 if (StringImpl* impl = sharedImpl())
43 return AtomicString(impl);
44 if (is8Bit())
45 return AtomicString(characters8(), m_length);
46 return AtomicString(characters16(), m_length);
47 }
48
49 bool equalStringView(const StringView& a, const StringView& b) {
50 if (a.isNull() || b.isNull())
51 return a.isNull() == b.isNull();
52 if (a.length() != b.length())
53 return false;
54 if (a.is8Bit()) {
55 if (b.is8Bit())
56 return equal(a.characters8(), b.characters8(), a.length());
57 return equal(a.characters8(), b.characters16(), a.length());
58 }
59 if (b.is8Bit())
60 return equal(a.characters16(), b.characters8(), a.length());
61 return equal(a.characters16(), b.characters16(), a.length());
62 }
63
64 bool equalIgnoringCaseAndNullity(const StringView& a, const StringView& b) {
65 if (a.length() != b.length())
66 return false;
67 if (a.is8Bit()) {
68 if (b.is8Bit())
69 return equalIgnoringCase(a.characters8(), b.characters8(), a.length());
70 return equalIgnoringCase(a.characters8(), b.characters16(), a.length());
71 }
72 if (b.is8Bit())
73 return equalIgnoringCase(a.characters16(), b.characters8(), a.length());
74 return equalIgnoringCase(a.characters16(), b.characters16(), a.length());
75 }
76
77 bool equalIgnoringCase(const StringView& a, const StringView& b) {
78 if (a.isNull() || b.isNull())
79 return a.isNull() == b.isNull();
80 return equalIgnoringCaseAndNullity(a, b);
81 }
82
83 bool equalIgnoringASCIICase(const StringView& a, const StringView& b) {
84 if (a.isNull() || b.isNull())
85 return a.isNull() == b.isNull();
86 if (a.length() != b.length())
87 return false;
88 if (a.is8Bit()) {
89 if (b.is8Bit())
90 return equalIgnoringASCIICase(a.characters8(), b.characters8(),
91 a.length());
92 return equalIgnoringASCIICase(a.characters8(), b.characters16(),
93 a.length());
94 }
95 if (b.is8Bit())
96 return equalIgnoringASCIICase(a.characters16(), b.characters8(),
97 a.length());
98 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length());
99 }
100
101 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringView.h ('k') | third_party/WebKit/Source/wtf/text/UTF8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698