| 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 #ifndef WTF_StringView_h | 5 #ifndef WTF_StringView_h |
| 6 #define WTF_StringView_h | 6 #define WTF_StringView_h |
| 7 | 7 |
| 8 #include "wtf/Allocator.h" | 8 #include "wtf/Allocator.h" |
| 9 #include "wtf/GetPtr.h" | 9 #include "wtf/GetPtr.h" |
| 10 #if DCHECK_IS_ON() | 10 #if DCHECK_IS_ON() |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 inline StringView(const String&, unsigned offset); | 61 inline StringView(const String&, unsigned offset); |
| 62 inline StringView(const String&); | 62 inline StringView(const String&); |
| 63 | 63 |
| 64 // From an AtomicString, implemented in AtomicString.h | 64 // From an AtomicString, implemented in AtomicString.h |
| 65 inline StringView(const AtomicString&, unsigned offset, unsigned length); | 65 inline StringView(const AtomicString&, unsigned offset, unsigned length); |
| 66 inline StringView(const AtomicString&, unsigned offset); | 66 inline StringView(const AtomicString&, unsigned offset); |
| 67 inline StringView(const AtomicString&); | 67 inline StringView(const AtomicString&); |
| 68 | 68 |
| 69 // From a literal string or LChar buffer: | 69 // From a literal string or LChar buffer: |
| 70 StringView(const LChar* chars, unsigned length) | 70 StringView(const LChar* chars, unsigned length) |
| 71 : m_impl(StringImpl::empty()), m_characters8(chars), m_length(length) {} | 71 : m_impl(StringImpl::empty), m_characters8(chars), m_length(length) {} |
| 72 StringView(const char* chars, unsigned length) | 72 StringView(const char* chars, unsigned length) |
| 73 : StringView(reinterpret_cast<const LChar*>(chars), length) {} | 73 : StringView(reinterpret_cast<const LChar*>(chars), length) {} |
| 74 StringView(const LChar* chars) | 74 StringView(const LChar* chars) |
| 75 : StringView(chars, | 75 : StringView(chars, |
| 76 chars ? strlen(reinterpret_cast<const char*>(chars)) : 0) {} | 76 chars ? strlen(reinterpret_cast<const char*>(chars)) : 0) {} |
| 77 StringView(const char* chars) | 77 StringView(const char* chars) |
| 78 : StringView(reinterpret_cast<const LChar*>(chars)) {} | 78 : StringView(reinterpret_cast<const LChar*>(chars)) {} |
| 79 | 79 |
| 80 // From a wide literal string or UChar buffer. | 80 // From a wide literal string or UChar buffer. |
| 81 StringView(const UChar* chars, unsigned length) | 81 StringView(const UChar* chars, unsigned length) |
| 82 : m_impl(StringImpl::empty16Bit()), | 82 : m_impl(StringImpl::empty16Bit), |
| 83 m_characters16(chars), | 83 m_characters16(chars), |
| 84 m_length(length) {} | 84 m_length(length) {} |
| 85 StringView(const UChar* chars); | 85 StringView(const UChar* chars); |
| 86 StringView(const char16_t* chars) | 86 StringView(const char16_t* chars) |
| 87 : StringView(reinterpret_cast<const UChar*>(chars)) {} | 87 : StringView(reinterpret_cast<const UChar*>(chars)) {} |
| 88 | 88 |
| 89 #if DCHECK_IS_ON() | 89 #if DCHECK_IS_ON() |
| 90 ~StringView(); | 90 ~StringView(); |
| 91 #endif | 91 #endif |
| 92 | 92 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 196 |
| 197 inline StringView::StringView(StringImpl& impl, | 197 inline StringView::StringView(StringImpl& impl, |
| 198 unsigned offset, | 198 unsigned offset, |
| 199 unsigned length) { | 199 unsigned length) { |
| 200 set(impl, offset, length); | 200 set(impl, offset, length); |
| 201 } | 201 } |
| 202 | 202 |
| 203 inline void StringView::clear() { | 203 inline void StringView::clear() { |
| 204 m_length = 0; | 204 m_length = 0; |
| 205 m_bytes = nullptr; | 205 m_bytes = nullptr; |
| 206 m_impl = StringImpl::empty(); // mark as 8 bit. | 206 m_impl = StringImpl::empty; // mark as 8 bit. |
| 207 } | 207 } |
| 208 | 208 |
| 209 inline void StringView::set(const StringImpl& impl, | 209 inline void StringView::set(const StringImpl& impl, |
| 210 unsigned offset, | 210 unsigned offset, |
| 211 unsigned length) { | 211 unsigned length) { |
| 212 SECURITY_DCHECK(offset + length <= impl.length()); | 212 SECURITY_DCHECK(offset + length <= impl.length()); |
| 213 m_length = length; | 213 m_length = length; |
| 214 m_impl = const_cast<StringImpl*>(&impl); | 214 m_impl = const_cast<StringImpl*>(&impl); |
| 215 if (impl.is8Bit()) | 215 if (impl.is8Bit()) |
| 216 m_characters8 = impl.characters8() + offset; | 216 m_characters8 = impl.characters8() + offset; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 263 } |
| 264 | 264 |
| 265 } // namespace WTF | 265 } // namespace WTF |
| 266 | 266 |
| 267 using WTF::StringView; | 267 using WTF::StringView; |
| 268 using WTF::equalIgnoringASCIICase; | 268 using WTF::equalIgnoringASCIICase; |
| 269 using WTF::equalIgnoringCase; | 269 using WTF::equalIgnoringCase; |
| 270 using WTF::isAllSpecialCharacters; | 270 using WTF::isAllSpecialCharacters; |
| 271 | 271 |
| 272 #endif | 272 #endif |
| OLD | NEW |