OLD | NEW |
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 14 matching lines...) Expand all Loading... |
25 #endif | 25 #endif |
26 | 26 |
27 String StringView::toString() const | 27 String StringView::toString() const |
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 String(m_data.characters16, m_length); | 35 return StringImpl::create8BitIfPossible(m_data.characters16, m_length); |
36 } | 36 } |
37 | 37 |
38 bool equalStringView(const StringView& a, const StringView& b) | 38 bool equalStringView(const StringView& a, const StringView& b) |
39 { | 39 { |
| 40 if (a.isNull() || b.isNull()) |
| 41 return a.isNull() == b.isNull(); |
40 if (a.length() != b.length()) | 42 if (a.length() != b.length()) |
41 return false; | 43 return false; |
42 if (a.isEmpty() || b.isEmpty()) | |
43 return a.isEmpty() == b.isEmpty(); | |
44 if (a.is8Bit()) { | 44 if (a.is8Bit()) { |
45 if (b.is8Bit()) | 45 if (b.is8Bit()) |
46 return equal(a.characters8(), b.characters8(), a.length()); | 46 return equal(a.characters8(), b.characters8(), a.length()); |
47 return equal(a.characters8(), b.characters16(), a.length()); | 47 return equal(a.characters8(), b.characters16(), a.length()); |
48 } | 48 } |
49 if (b.is8Bit()) | 49 if (b.is8Bit()) |
50 return equal(a.characters16(), b.characters8(), a.length()); | 50 return equal(a.characters16(), b.characters8(), a.length()); |
51 return equal(a.characters16(), b.characters16(), a.length()); | 51 return equal(a.characters16(), b.characters16(), a.length()); |
52 } | 52 } |
53 | 53 |
| 54 bool equalIgnoringASCIICase(const StringView& a, const StringView& b) |
| 55 { |
| 56 if (a.isNull() || b.isNull()) |
| 57 return a.isNull() == b.isNull(); |
| 58 if (a.length() != b.length()) |
| 59 return false; |
| 60 if (a.is8Bit()) { |
| 61 if (b.is8Bit()) |
| 62 return equalIgnoringASCIICase(a.characters8(), b.characters8(), a.le
ngth()); |
| 63 return equalIgnoringASCIICase(a.characters8(), b.characters16(), a.lengt
h()); |
| 64 } |
| 65 if (b.is8Bit()) |
| 66 return equalIgnoringASCIICase(a.characters16(), b.characters8(), a.lengt
h()); |
| 67 return equalIgnoringASCIICase(a.characters16(), b.characters16(), a.length()
); |
| 68 } |
| 69 |
54 } // namespace WTF | 70 } // namespace WTF |
OLD | NEW |