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

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

Issue 2033503002: Add StringView::toAtomicString(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tests. Created 4 years, 6 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 namespace WTF { 7 namespace WTF {
8 8
9 StringView::StringView(const UChar* chars, unsigned length) 9 StringView::StringView(const UChar* chars, unsigned length)
10 : m_length(length) 10 : m_length(length)
(...skipping 17 matching lines...) Expand all
28 { 28 {
29 if (isNull()) 29 if (isNull())
30 return String(); 30 return String();
31 if (isEmpty()) 31 if (isEmpty())
32 return emptyString(); 32 return emptyString();
33 if (is8Bit()) 33 if (is8Bit())
34 return String(m_data.characters8, m_length); 34 return String(m_data.characters8, m_length);
35 return StringImpl::create8BitIfPossible(m_data.characters16, m_length); 35 return StringImpl::create8BitIfPossible(m_data.characters16, m_length);
36 } 36 }
37 37
38 AtomicString StringView::toAtomicString() const
39 {
40 if (isNull())
41 return nullAtom;
42 if (isEmpty())
43 return emptyAtom;
44 if (is8Bit())
45 return AtomicString(m_data.characters8, m_length);
46 return AtomicString(m_data.characters16, m_length);
47 }
48
38 bool equalStringView(const StringView& a, const StringView& b) 49 bool equalStringView(const StringView& a, const StringView& b)
39 { 50 {
40 if (a.isNull() || b.isNull()) 51 if (a.isNull() || b.isNull())
41 return a.isNull() == b.isNull(); 52 return a.isNull() == b.isNull();
42 if (a.length() != b.length()) 53 if (a.length() != b.length())
43 return false; 54 return false;
44 if (a.is8Bit()) { 55 if (a.is8Bit()) {
45 if (b.is8Bit()) 56 if (b.is8Bit())
46 return equal(a.characters8(), b.characters8(), a.length()); 57 return equal(a.characters8(), b.characters8(), a.length());
47 return equal(a.characters8(), b.characters16(), a.length()); 58 return equal(a.characters8(), b.characters16(), a.length());
(...skipping 13 matching lines...) Expand all
61 if (b.is8Bit()) 72 if (b.is8Bit())
62 return equalIgnoringASCIICase(a.characters8(), b.characters8(), a.le ngth()); 73 return equalIgnoringASCIICase(a.characters8(), b.characters8(), a.le ngth());
63 return equalIgnoringASCIICase(a.characters8(), b.characters16(), a.lengt h()); 74 return equalIgnoringASCIICase(a.characters8(), b.characters16(), a.lengt h());
64 } 75 }
65 if (b.is8Bit()) 76 if (b.is8Bit())
66 return equalIgnoringASCIICase(a.characters16(), b.characters8(), a.lengt h()); 77 return equalIgnoringASCIICase(a.characters16(), b.characters8(), a.lengt h());
67 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length() ); 78 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length() );
68 } 79 }
69 80
70 } // namespace WTF 81 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringView.h ('k') | third_party/WebKit/Source/wtf/text/StringViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698