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

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

Issue 2148423003: Use StringView for equalIgnoringCase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK is silly. Created 4 years, 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "wtf/text/StringView.h" 5 #include "wtf/text/StringView.h"
6 6
7 #include "wtf/text/AtomicString.h" 7 #include "wtf/text/AtomicString.h"
8 #include "wtf/text/StringImpl.h"
8 #include "wtf/text/WTFString.h" 9 #include "wtf/text/WTFString.h"
9 10
10 namespace WTF { 11 namespace WTF {
11 12
12 StringView::StringView(const UChar* chars) 13 StringView::StringView(const UChar* chars)
13 : StringView(chars, chars ? lengthOfNullTerminatedString(chars) : 0) {} 14 : StringView(chars, chars ? lengthOfNullTerminatedString(chars) : 0) {}
14 15
15 #if DCHECK_IS_ON() 16 #if DCHECK_IS_ON()
16 StringView::~StringView() 17 StringView::~StringView()
17 { 18 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (a.is8Bit()) { 57 if (a.is8Bit()) {
57 if (b.is8Bit()) 58 if (b.is8Bit())
58 return equal(a.characters8(), b.characters8(), a.length()); 59 return equal(a.characters8(), b.characters8(), a.length());
59 return equal(a.characters8(), b.characters16(), a.length()); 60 return equal(a.characters8(), b.characters16(), a.length());
60 } 61 }
61 if (b.is8Bit()) 62 if (b.is8Bit())
62 return equal(a.characters16(), b.characters8(), a.length()); 63 return equal(a.characters16(), b.characters8(), a.length());
63 return equal(a.characters16(), b.characters16(), a.length()); 64 return equal(a.characters16(), b.characters16(), a.length());
64 } 65 }
65 66
67
68 bool equalIgnoringCaseAndNullity(const StringView& a, const StringView& b)
69 {
70 if (a.length() != b.length())
71 return false;
72 if (a.is8Bit()) {
73 if (b.is8Bit())
74 return equalIgnoringCase(a.characters8(), b.characters8(), a.length( ));
75 return equalIgnoringCase(a.characters8(), b.characters16(), a.length());
76 }
77 if (b.is8Bit())
78 return equalIgnoringCase(a.characters16(), b.characters8(), a.length());
79 return equalIgnoringCase(a.characters16(), b.characters16(), a.length());
80 }
81
82 bool equalIgnoringCase(const StringView& a, const StringView& b)
83 {
84 if (a.isNull() || b.isNull())
85 return a.isNull() == b.isNull();
86 return equalIgnoringCaseAndNullity(a, b);
87 }
88
66 bool equalIgnoringASCIICase(const StringView& a, const StringView& b) 89 bool equalIgnoringASCIICase(const StringView& a, const StringView& b)
67 { 90 {
68 if (a.isNull() || b.isNull()) 91 if (a.isNull() || b.isNull())
69 return a.isNull() == b.isNull(); 92 return a.isNull() == b.isNull();
70 if (a.length() != b.length()) 93 if (a.length() != b.length())
71 return false; 94 return false;
72 if (a.is8Bit()) { 95 if (a.is8Bit()) {
73 if (b.is8Bit()) 96 if (b.is8Bit())
74 return equalIgnoringASCIICase(a.characters8(), b.characters8(), a.le ngth()); 97 return equalIgnoringASCIICase(a.characters8(), b.characters8(), a.le ngth());
75 return equalIgnoringASCIICase(a.characters8(), b.characters16(), a.lengt h()); 98 return equalIgnoringASCIICase(a.characters8(), b.characters16(), a.lengt h());
76 } 99 }
77 if (b.is8Bit()) 100 if (b.is8Bit())
78 return equalIgnoringASCIICase(a.characters16(), b.characters8(), a.lengt h()); 101 return equalIgnoringASCIICase(a.characters16(), b.characters8(), a.lengt h());
79 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length() ); 102 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length() );
80 } 103 }
81 104
82 } // namespace WTF 105 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringView.h ('k') | third_party/WebKit/Source/wtf/text/WTFString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698