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

Unified Diff: third_party/WebKit/Source/wtf/text/StringImpl.h

Issue 2007103003: Expand WTF::StringView's API to be more like StringPiece. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo for length access. Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/text/StringImpl.h
diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.h b/third_party/WebKit/Source/wtf/text/StringImpl.h
index eaf077a7371ca90940ca996c9327900bc18c478d..a0bcc9a227c4b7a2b083b409c374a2a12983d392 100644
--- a/third_party/WebKit/Source/wtf/text/StringImpl.h
+++ b/third_party/WebKit/Source/wtf/text/StringImpl.h
@@ -29,6 +29,7 @@
#include "wtf/StringHasher.h"
#include "wtf/Vector.h"
#include "wtf/WTFExport.h"
+#include "wtf/text/StringView.h"
#include "wtf/text/Unicode.h"
#include <limits.h>
@@ -743,6 +744,32 @@ inline PassRefPtr<StringImpl> StringImpl::isolatedCopy() const
return create(characters16(), m_length);
}
+inline void StringView::set(StringImpl& impl, unsigned offset, unsigned length)
+{
+ SECURITY_DCHECK(offset + length <= impl.length());
+ m_length = length;
+ m_is8Bit = impl.is8Bit();
+ if (m_is8Bit)
+ m_data.characters8 = impl.characters8() + offset;
+ else
+ m_data.characters16 = impl.characters16() + offset;
+}
+
+inline StringView::StringView(StringImpl* impl)
+{
+ impl ? set(*impl, 0, impl->length()) : clear();
+}
+
+inline StringView::StringView(StringImpl* impl, unsigned offset)
+{
+ impl ? set(*impl, offset, impl->length()) : clear();
+}
+
+inline StringView::StringView(StringImpl* impl, unsigned offset, unsigned length)
+{
+ impl ? set(*impl, offset, length) : clear();
+}
+
// TODO(rob.buis) possibly find a better place for this method.
// Turns a UChar32 to uppercase based on localeIdentifier.
WTF_EXPORT UChar32 toUpper(UChar32, const AtomicString& localeIdentifier);

Powered by Google App Engine
This is Rietveld 408576698