| 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 25 matching lines...) Expand all Loading... |
| 36 // From a StringView: | 36 // From a StringView: |
| 37 StringView(const StringView&, unsigned offset, unsigned length); | 37 StringView(const StringView&, unsigned offset, unsigned length); |
| 38 StringView(const StringView& view, unsigned offset) | 38 StringView(const StringView& view, unsigned offset) |
| 39 : StringView(view, offset, view.m_length - offset) {} | 39 : StringView(view, offset, view.m_length - offset) {} |
| 40 | 40 |
| 41 // From a StringImpl: | 41 // From a StringImpl: |
| 42 StringView(StringImpl*); | 42 StringView(StringImpl*); |
| 43 StringView(StringImpl*, unsigned offset); | 43 StringView(StringImpl*, unsigned offset); |
| 44 StringView(StringImpl*, unsigned offset, unsigned length); | 44 StringView(StringImpl*, unsigned offset, unsigned length); |
| 45 | 45 |
| 46 // From a non-null StringImpl, avoids the null check. |
| 47 StringView(StringImpl& impl) |
| 48 : m_impl(&impl) |
| 49 , m_bytes(impl.bytes()) |
| 50 , m_length(impl.length()) {} |
| 51 StringView(StringImpl&, unsigned offset); |
| 52 StringView(StringImpl&, unsigned offset, unsigned length); |
| 53 |
| 46 // From an String, implemented in String.h | 54 // From an String, implemented in String.h |
| 47 inline StringView(const String&, unsigned offset, unsigned length); | 55 inline StringView(const String&, unsigned offset, unsigned length); |
| 48 inline StringView(const String&, unsigned offset); | 56 inline StringView(const String&, unsigned offset); |
| 49 inline StringView(const String&); | 57 inline StringView(const String&); |
| 50 | 58 |
| 51 // From an AtomicString, implemented in AtomicString.h | 59 // From an AtomicString, implemented in AtomicString.h |
| 52 inline StringView(const AtomicString&, unsigned offset, unsigned length); | 60 inline StringView(const AtomicString&, unsigned offset, unsigned length); |
| 53 inline StringView(const AtomicString&, unsigned offset); | 61 inline StringView(const AtomicString&, unsigned offset); |
| 54 inline StringView(const AtomicString&); | 62 inline StringView(const AtomicString&); |
| 55 | 63 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 inline StringView::StringView(StringImpl* impl, unsigned offset) | 176 inline StringView::StringView(StringImpl* impl, unsigned offset) |
| 169 { | 177 { |
| 170 impl ? set(*impl, offset, impl->length() - offset) : clear(); | 178 impl ? set(*impl, offset, impl->length() - offset) : clear(); |
| 171 } | 179 } |
| 172 | 180 |
| 173 inline StringView::StringView(StringImpl* impl, unsigned offset, unsigned length
) | 181 inline StringView::StringView(StringImpl* impl, unsigned offset, unsigned length
) |
| 174 { | 182 { |
| 175 impl ? set(*impl, offset, length) : clear(); | 183 impl ? set(*impl, offset, length) : clear(); |
| 176 } | 184 } |
| 177 | 185 |
| 186 inline StringView::StringView(StringImpl& impl, unsigned offset) |
| 187 { |
| 188 set(impl, offset, impl.length() - offset); |
| 189 } |
| 190 |
| 191 inline StringView::StringView(StringImpl& impl, unsigned offset, unsigned length
) |
| 192 { |
| 193 set(impl, offset, length); |
| 194 } |
| 195 |
| 178 inline void StringView::clear() | 196 inline void StringView::clear() |
| 179 { | 197 { |
| 180 m_length = 0; | 198 m_length = 0; |
| 181 m_bytes = nullptr; | 199 m_bytes = nullptr; |
| 182 m_impl = StringImpl::empty(); // mark as 8 bit. | 200 m_impl = StringImpl::empty(); // mark as 8 bit. |
| 183 } | 201 } |
| 184 | 202 |
| 185 inline void StringView::set(StringImpl& impl, unsigned offset, unsigned length) | 203 inline void StringView::set(StringImpl& impl, unsigned offset, unsigned length) |
| 186 { | 204 { |
| 187 SECURITY_DCHECK(offset + length <= impl.length()); | 205 SECURITY_DCHECK(offset + length <= impl.length()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 208 inline bool operator!=(const StringView& a, const StringView& b) | 226 inline bool operator!=(const StringView& a, const StringView& b) |
| 209 { | 227 { |
| 210 return !(a == b); | 228 return !(a == b); |
| 211 } | 229 } |
| 212 | 230 |
| 213 } // namespace WTF | 231 } // namespace WTF |
| 214 | 232 |
| 215 using WTF::StringView; | 233 using WTF::StringView; |
| 216 | 234 |
| 217 #endif | 235 #endif |
| OLD | NEW |