Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/StringImpl.h" | |
| 8 #include "wtf/text/WTFString.h" | |
| 9 | |
| 10 namespace WTF { | |
| 11 | |
| 12 StringView::StringView(const UChar* chars, unsigned length) | |
| 13 : m_length(length) | |
| 14 , m_is8Bit(false) | |
| 15 { | |
| 16 SECURITY_DCHECK(!chars || length <= lengthOfNullTerminatedString(chars)); | |
| 17 m_data.characters16 = chars; | |
| 18 } | |
| 19 | |
| 20 StringView::StringView(const UChar* chars) | |
| 21 : StringView(chars, chars ? lengthOfNullTerminatedString(chars) : 0) {} | |
| 22 | |
| 23 String StringView::toString() const | |
| 24 { | |
| 25 if (!m_data.bytes) | |
|
haraken
2016/05/26 22:27:22
isNull()
esprehn
2016/05/26 22:40:21
done, also added a case for empty strings.
| |
| 26 return String(); | |
| 27 if (is8Bit()) | |
| 28 return String(m_data.characters8, m_length); | |
| 29 return String(m_data.characters16, m_length); | |
| 30 } | |
| 31 | |
| 32 bool equalStringView(const StringView& a, const StringView& b) | |
| 33 { | |
| 34 if (a.length() != b.length()) | |
| 35 return false; | |
| 36 if (a.isNull() || b.isNull()) | |
| 37 return a.isNull() == b.isNull(); | |
|
haraken
2016/05/26 22:27:22
A better check would be:
if (a.length() == 0 ||
esprehn
2016/05/26 22:40:21
Yeah, checking isEmpty() works here.
| |
| 38 if (a.is8Bit()) { | |
| 39 if (b.is8Bit()) | |
| 40 return WTF::equal(a.characters8(), b.characters8(), a.length()); | |
| 41 return WTF::equal(a.characters8(), b.characters16(), a.length()); | |
| 42 } | |
| 43 if (b.is8Bit()) | |
| 44 return WTF::equal(a.characters16(), b.characters8(), a.length()); | |
| 45 return WTF::equal(a.characters16(), b.characters16(), a.length()); | |
| 46 } | |
| 47 | |
| 48 } // namespace WTF | |
| OLD | NEW |