<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[174234] trunk/Source/WTF</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/174234">174234</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-10-02 15:48:48 -0700 (Thu, 02 Oct 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Simplify StringTypeAdapter templates
https://bugs.webkit.org/show_bug.cgi?id=137356
Reviewed by Andreas Kling.
* wtf/text/StringConcatenate.h:
Use StringView for copying characters. Use inheritance for char* vs const char* etc. Make all StringAdapter member functions const.
* wtf/text/StringView.h:
Move enough functions out of line so we can include WTFString.h after the StringView class definition.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtftextStringConcatenateh">trunk/Source/WTF/wtf/text/StringConcatenate.h</a></li>
<li><a href="#trunkSourceWTFwtftextStringViewh">trunk/Source/WTF/wtf/text/StringView.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (174233 => 174234)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-10-02 22:25:50 UTC (rev 174233)
+++ trunk/Source/WTF/ChangeLog        2014-10-02 22:48:48 UTC (rev 174234)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2014-10-02 Anders Carlsson <andersca@apple.com>
+
+ Simplify StringTypeAdapter templates
+ https://bugs.webkit.org/show_bug.cgi?id=137356
+
+ Reviewed by Andreas Kling.
+
+ * wtf/text/StringConcatenate.h:
+ Use StringView for copying characters. Use inheritance for char* vs const char* etc. Make all StringAdapter member functions const.
+
+ * wtf/text/StringView.h:
+ Move enough functions out of line so we can include WTFString.h after the StringView class definition.
+
</ins><span class="cx"> 2014-10-01 Christophe Dumez <cdumez@apple.com>
</span><span class="cx">
</span><span class="cx"> Have is<>(T*) function do a null check on the pointer argument
</span></span></pre></div>
<a id="trunkSourceWTFwtftextStringConcatenateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/text/StringConcatenate.h (174233 => 174234)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/text/StringConcatenate.h        2014-10-02 22:25:50 UTC (rev 174233)
+++ trunk/Source/WTF/wtf/text/StringConcatenate.h        2014-10-02 22:48:48 UTC (rev 174234)
</span><span class="lines">@@ -32,6 +32,10 @@
</span><span class="cx"> #include <wtf/text/AtomicString.h>
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#ifndef StringView_h
+#include <wtf/text/StringView.h>
+#endif
+
</ins><span class="cx"> // This macro is helpful for testing how many intermediate Strings are created while evaluating an
</span><span class="cx"> // expression containing operator+.
</span><span class="cx"> #ifndef WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING
</span><span class="lines">@@ -41,379 +45,204 @@
</span><span class="cx"> namespace WTF {
</span><span class="cx">
</span><span class="cx"> template<typename StringType>
</span><del>-class StringTypeAdapter {
-};
</del><ins>+class StringTypeAdapter;
</ins><span class="cx">
</span><span class="cx"> template<>
</span><span class="cx"> class StringTypeAdapter<char> {
</span><span class="cx"> public:
</span><del>- StringTypeAdapter<char>(char buffer)
- : m_buffer(buffer)
</del><ins>+ StringTypeAdapter<char>(char character)
+ : m_character(character)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> unsigned length() { return 1; }
</span><del>-
</del><span class="cx"> bool is8Bit() { return true; }
</span><span class="cx">
</span><del>- void writeTo(LChar* destination)
</del><ins>+ void writeTo(LChar* destination) const
</ins><span class="cx"> {
</span><del>- *destination = m_buffer;
</del><ins>+ *destination = m_character;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- void writeTo(UChar* destination) { *destination = m_buffer; }
-
-private:
- unsigned char m_buffer;
-};
-
-template<>
-class StringTypeAdapter<LChar> {
-public:
- StringTypeAdapter<LChar>(LChar buffer)
- : m_buffer(buffer)
</del><ins>+ void writeTo(UChar* destination) const
</ins><span class="cx"> {
</span><ins>+ *destination = m_character;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- unsigned length() { return 1; }
-
- bool is8Bit() { return true; }
-
- void writeTo(LChar* destination)
- {
- *destination = m_buffer;
- }
-
- void writeTo(UChar* destination) { *destination = m_buffer; }
-
</del><span class="cx"> private:
</span><del>- LChar m_buffer;
</del><ins>+ char m_character;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<>
</span><span class="cx"> class StringTypeAdapter<UChar> {
</span><span class="cx"> public:
</span><del>- StringTypeAdapter<UChar>(UChar buffer)
- : m_buffer(buffer)
</del><ins>+ StringTypeAdapter<UChar>(UChar character)
+ : m_character(character)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>- unsigned length() { return 1; }
</del><ins>+ unsigned length() const { return 1; }
+ bool is8Bit() const { return m_character <= 0xff; }
</ins><span class="cx">
</span><del>- bool is8Bit() { return m_buffer <= 0xff; }
-
- void writeTo(LChar* destination)
</del><ins>+ void writeTo(LChar* destination) const
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(is8Bit());
</span><del>- *destination = static_cast<LChar>(m_buffer);
</del><ins>+ *destination = static_cast<LChar>(m_character);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- void writeTo(UChar* destination) { *destination = m_buffer; }
-
-private:
- UChar m_buffer;
-};
-
-template<>
-class StringTypeAdapter<char*> {
-public:
- StringTypeAdapter<char*>(char* buffer)
- : m_buffer(buffer)
- , m_length(strlen(buffer))
</del><ins>+ void writeTo(UChar* destination) const
</ins><span class="cx"> {
</span><ins>+ *destination = m_character;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- unsigned length() { return m_length; }
-
- bool is8Bit() { return true; }
-
- void writeTo(LChar* destination)
- {
- for (unsigned i = 0; i < m_length; ++i)
- destination[i] = static_cast<LChar>(m_buffer[i]);
- }
-
- void writeTo(UChar* destination)
- {
- for (unsigned i = 0; i < m_length; ++i) {
- unsigned char c = m_buffer[i];
- destination[i] = c;
- }
- }
-
</del><span class="cx"> private:
</span><del>- const char* m_buffer;
- unsigned m_length;
</del><ins>+ UChar m_character;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<>
</span><del>-class StringTypeAdapter<LChar*> {
</del><ins>+class StringTypeAdapter<const LChar*> {
</ins><span class="cx"> public:
</span><del>- StringTypeAdapter<LChar*>(LChar* buffer)
- : m_buffer(buffer)
- , m_length(strlen(reinterpret_cast<char*>(buffer)))
</del><ins>+ StringTypeAdapter(const LChar* characters)
+ : m_characters(characters)
+ , m_length(strlen(reinterpret_cast<const char*>(characters)))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>- unsigned length() { return m_length; }
</del><ins>+ unsigned length() const { return m_length; }
+ bool is8Bit() const { return true; }
</ins><span class="cx">
</span><del>- bool is8Bit() { return true; }
-
- void writeTo(LChar* destination)
</del><ins>+ void writeTo(LChar* destination) const
</ins><span class="cx"> {
</span><del>- memcpy(destination, m_buffer, m_length * sizeof(LChar));
</del><ins>+ StringView(m_characters, m_length).getCharactersWithUpconvert(destination);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- void writeTo(UChar* destination)
</del><ins>+ void writeTo(UChar* destination) const
</ins><span class="cx"> {
</span><del>- StringImpl::copyChars(destination, m_buffer, m_length);
</del><ins>+ StringView(m_characters, m_length).getCharactersWithUpconvert(destination);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- const LChar* m_buffer;
</del><ins>+ const LChar* m_characters;
</ins><span class="cx"> unsigned m_length;
</span><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<>
</span><span class="cx"> class StringTypeAdapter<const UChar*> {
</span><span class="cx"> public:
</span><del>- StringTypeAdapter<const UChar*>(const UChar* buffer)
- : m_buffer(buffer)
</del><ins>+ StringTypeAdapter(const UChar* characters)
+ : m_characters(characters)
</ins><span class="cx"> {
</span><del>- size_t len = 0;
- while (m_buffer[len] != UChar(0))
- ++len;
</del><ins>+ unsigned length = 0;
+ while (m_characters[length])
+ ++length;
</ins><span class="cx">
</span><del>- if (len > std::numeric_limits<unsigned>::max())
</del><ins>+ if (length > std::numeric_limits<unsigned>::max())
</ins><span class="cx"> CRASH();
</span><span class="cx">
</span><del>- m_length = len;
</del><ins>+ m_length = length;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- unsigned length() { return m_length; }
</del><ins>+ unsigned length() const { return m_length; }
+ bool is8Bit() const { return false; }
</ins><span class="cx">
</span><del>- bool is8Bit() { return false; }
-
- NO_RETURN_DUE_TO_CRASH void writeTo(LChar*)
</del><ins>+ NO_RETURN_DUE_TO_CRASH void writeTo(LChar*) const
</ins><span class="cx"> {
</span><span class="cx"> CRASH();
</span><span class="cx"> }
</span><span class="cx">
</span><del>- void writeTo(UChar* destination)
</del><ins>+ void writeTo(UChar* destination) const
</ins><span class="cx"> {
</span><del>- memcpy(destination, m_buffer, m_length * sizeof(UChar));
</del><ins>+ memcpy(destination, m_characters, m_length * sizeof(UChar));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- const UChar* m_buffer;
</del><ins>+ const UChar* m_characters;
</ins><span class="cx"> unsigned m_length;
</span><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<>
</span><del>-class StringTypeAdapter<const char*> {
</del><ins>+class StringTypeAdapter<const char*> : public StringTypeAdapter<const LChar*> {
</ins><span class="cx"> public:
</span><del>- StringTypeAdapter<const char*>(const char* buffer)
- : m_buffer(buffer)
- , m_length(strlen(buffer))
</del><ins>+ StringTypeAdapter(const char* characters)
+ : StringTypeAdapter<const LChar*>(reinterpret_cast<const LChar*>(characters))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><del>-
- unsigned length() { return m_length; }
-
- bool is8Bit() { return true; }
-
- void writeTo(LChar* destination)
- {
- memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar));
- }
-
- void writeTo(UChar* destination)
- {
- for (unsigned i = 0; i < m_length; ++i) {
- unsigned char c = m_buffer[i];
- destination[i] = c;
- }
- }
-
-private:
- const char* m_buffer;
- unsigned m_length;
</del><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<>
</span><del>-class StringTypeAdapter<const LChar*> {
</del><ins>+class StringTypeAdapter<char*> : public StringTypeAdapter<const char*> {
</ins><span class="cx"> public:
</span><del>- StringTypeAdapter<const LChar*>(const LChar* buffer)
- : m_buffer(buffer)
- , m_length(strlen(reinterpret_cast<const char*>(buffer)))
</del><ins>+ StringTypeAdapter(const char* characters)
+ : StringTypeAdapter<const char*>(characters)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><del>-
- unsigned length() { return m_length; }
-
- bool is8Bit() { return true; }
-
- void writeTo(LChar* destination)
- {
- memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(LChar));
- }
-
- void writeTo(UChar* destination)
- {
- StringImpl::copyChars(destination, m_buffer, m_length);
- }
-
-private:
- const LChar* m_buffer;
- unsigned m_length;
</del><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<>
</span><del>-class StringTypeAdapter<ASCIILiteral> {
</del><ins>+class StringTypeAdapter<ASCIILiteral> : public StringTypeAdapter<const char*> {
</ins><span class="cx"> public:
</span><del>- StringTypeAdapter<ASCIILiteral>(ASCIILiteral buffer)
- : m_buffer(reinterpret_cast<const LChar*>(static_cast<const char*>(buffer)))
- , m_length(strlen(buffer))
</del><ins>+ StringTypeAdapter(ASCIILiteral characters)
+ : StringTypeAdapter<const char*>(characters)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><del>-
- size_t length() { return m_length; }
-
- bool is8Bit() { return true; }
-
- void writeTo(LChar* destination)
- {
- memcpy(destination, m_buffer, static_cast<size_t>(m_length));
- }
-
- void writeTo(UChar* destination)
- {
- StringImpl::copyChars(destination, m_buffer, m_length);
- }
-
-private:
- const LChar* m_buffer;
- unsigned m_length;
</del><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<>
</span><span class="cx"> class StringTypeAdapter<Vector<char>> {
</span><span class="cx"> public:
</span><del>- StringTypeAdapter<Vector<char>>(const Vector<char>& buffer)
- : m_buffer(buffer)
</del><ins>+ StringTypeAdapter(const Vector<char>& vector)
+ : m_vector(vector)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>- size_t length() { return m_buffer.size(); }
</del><ins>+ size_t length() const { return m_vector.size(); }
+ bool is8Bit() const { return true; }
</ins><span class="cx">
</span><del>- bool is8Bit() { return true; }
-
- void writeTo(LChar* destination)
</del><ins>+ void writeTo(LChar* destination) const
</ins><span class="cx"> {
</span><del>- for (size_t i = 0; i < m_buffer.size(); ++i)
- destination[i] = static_cast<unsigned char>(m_buffer[i]);
</del><ins>+ StringView(reinterpret_cast<const LChar*>(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- void writeTo(UChar* destination)
</del><ins>+ void writeTo(UChar* destination) const
</ins><span class="cx"> {
</span><del>- for (size_t i = 0; i < m_buffer.size(); ++i)
- destination[i] = static_cast<unsigned char>(m_buffer[i]);
</del><ins>+ StringView(reinterpret_cast<const LChar*>(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- const Vector<char>& m_buffer;
</del><ins>+ const Vector<char>& m_vector;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<>
</span><del>-class StringTypeAdapter<Vector<LChar>> {
-public:
- StringTypeAdapter<Vector<LChar>>(const Vector<LChar>& buffer)
- : m_buffer(buffer)
- {
- }
-
- size_t length() { return m_buffer.size(); }
-
- bool is8Bit() { return true; }
-
- void writeTo(LChar* destination)
- {
- for (size_t i = 0; i < m_buffer.size(); ++i)
- destination[i] = m_buffer[i];
- }
-
- void writeTo(UChar* destination)
- {
- for (size_t i = 0; i < m_buffer.size(); ++i)
- destination[i] = m_buffer[i];
- }
-
-private:
- const Vector<LChar>& m_buffer;
-};
-
-template<>
</del><span class="cx"> class StringTypeAdapter<String> {
</span><span class="cx"> public:
</span><span class="cx"> StringTypeAdapter<String>(const String& string)
</span><del>- : m_buffer(string)
</del><ins>+ : m_string(string)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>- unsigned length() { return m_buffer.length(); }
</del><ins>+ unsigned length() const { return m_string.length(); }
+ bool is8Bit() const { return m_string.isNull() || m_string.is8Bit(); }
</ins><span class="cx">
</span><del>- bool is8Bit() { return m_buffer.isNull() || m_buffer.is8Bit(); }
-
- void writeTo(LChar* destination)
</del><ins>+ void writeTo(LChar* destination) const
</ins><span class="cx"> {
</span><del>- unsigned length = m_buffer.length();
-
- ASSERT(is8Bit());
- const LChar* data = m_buffer.characters8();
- for (unsigned i = 0; i < length; ++i)
- destination[i] = data[i];
-
- WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
</del><ins>+ StringView(m_string).getCharactersWithUpconvert(destination);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- void writeTo(UChar* destination)
</del><ins>+ void writeTo(UChar* destination) const
</ins><span class="cx"> {
</span><del>- unsigned length = m_buffer.length();
-
- if (is8Bit()) {
- const LChar* data = m_buffer.characters8();
- for (unsigned i = 0; i < length; ++i)
- destination[i] = data[i];
- } else {
- const UChar* data = m_buffer.characters16();
- for (unsigned i = 0; i < length; ++i)
- destination[i] = data[i];
- }
-
- WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
</del><ins>+ StringView(m_string).getCharactersWithUpconvert(destination);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- const String& m_buffer;
</del><ins>+ const String& m_string;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> template<>
</span><del>-class StringTypeAdapter<AtomicString> {
</del><ins>+class StringTypeAdapter<AtomicString> : public StringTypeAdapter<String> {
</ins><span class="cx"> public:
</span><del>- StringTypeAdapter<AtomicString>(const AtomicString& string)
- : m_adapter(string.string())
</del><ins>+ StringTypeAdapter(const AtomicString& string)
+ : StringTypeAdapter<String>(string.string())
</ins><span class="cx"> {
</span><span class="cx"> }
</span><del>-
- unsigned length() { return m_adapter.length(); }
-
- bool is8Bit() { return m_adapter.is8Bit(); }
-
- void writeTo(LChar* destination) { m_adapter.writeTo(destination); }
- void writeTo(UChar* destination) { m_adapter.writeTo(destination); }
-
-private:
- StringTypeAdapter<String> m_adapter;
</del><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> inline void sumWithOverflow(unsigned& total, unsigned addend, bool& overflow)
</span></span></pre></div>
<a id="trunkSourceWTFwtftextStringViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/text/StringView.h (174233 => 174234)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/text/StringView.h        2014-10-02 22:25:50 UTC (rev 174233)
+++ trunk/Source/WTF/wtf/text/StringView.h        2014-10-02 22:48:48 UTC (rev 174234)
</span><span class="lines">@@ -26,7 +26,11 @@
</span><span class="cx"> #ifndef StringView_h
</span><span class="cx"> #define StringView_h
</span><span class="cx">
</span><del>-#include <wtf/text/StringConcatenate.h>
</del><ins>+#include <unicode/utypes.h>
+#include <wtf/Forward.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/text/LChar.h>
</ins><span class="cx">
</span><span class="cx"> namespace WTF {
</span><span class="cx">
</span><span class="lines">@@ -53,28 +57,9 @@
</span><span class="cx"> initialize(characters, length);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- StringView(const StringImpl& string)
- {
- if (string.is8Bit())
- initialize(string.characters8(), string.length());
- else
- initialize(string.characters16(), string.length());
- }
</del><ins>+ StringView(const StringImpl&);
+ StringView(const String&);
</ins><span class="cx">
</span><del>- StringView(const String& string)
- {
- if (!string.impl()) {
- m_characters = nullptr;
- m_length = 0;
- return;
- }
- if (string.is8Bit()) {
- initialize(string.characters8(), string.length());
- return;
- }
- initialize(string.characters16(), string.length());
- }
-
</del><span class="cx"> static StringView empty()
</span><span class="cx"> {
</span><span class="cx"> return StringView(reinterpret_cast<const LChar*>(""), 0);
</span><span class="lines">@@ -134,36 +119,13 @@
</span><span class="cx"> return StringView(characters16() + start, length);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- String toString() const
- {
- if (is8Bit())
- return String(characters8(), length());
</del><ins>+ String toString() const;
</ins><span class="cx">
</span><del>- return String(characters16(), length());
- }
</del><ins>+ float toFloat(bool& isValid) const;
+ int toInt(bool& isValid) const;
</ins><span class="cx">
</span><del>- float toFloat(bool& isValid)
- {
- if (is8Bit())
- return charactersToFloat(characters8(), length(), &isValid);
- return charactersToFloat(characters16(), length(), &isValid);
- }
</del><ins>+ String toStringWithoutCopying() const;
</ins><span class="cx">
</span><del>- int toInt(bool& isValid)
- {
- if (is8Bit())
- return charactersToInt(characters8(), length(), &isValid);
- return charactersToInt(characters16(), length(), &isValid);
- }
-
- String toStringWithoutCopying() const
- {
- if (is8Bit())
- return StringImpl::createWithoutCopying(characters8(), length());
-
- return StringImpl::createWithoutCopying(characters16(), length());
- }
-
</del><span class="cx"> UChar operator[](unsigned index) const
</span><span class="cx"> {
</span><span class="cx"> ASSERT(index < length());
</span><span class="lines">@@ -172,12 +134,7 @@
</span><span class="cx"> return characters16()[index];
</span><span class="cx"> }
</span><span class="cx">
</span><del>- size_t find(UChar character, unsigned start = 0) const
- {
- if (is8Bit())
- return WTF::find(characters8(), length(), character, start);
- return WTF::find(characters16(), length(), character, start);
- }
</del><ins>+ size_t find(UChar character, unsigned start = 0) const;
</ins><span class="cx">
</span><span class="cx"> bool contains(UChar c) const { return find(c) != notFound; }
</span><span class="cx">
</span><span class="lines">@@ -215,6 +172,34 @@
</span><span class="cx"> unsigned m_length;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+}
+
+#include <wtf/text/WTFString.h>
+
+namespace WTF {
+
+inline StringView::StringView(const StringImpl& string)
+{
+ if (string.is8Bit())
+ initialize(string.characters8(), string.length());
+ else
+ initialize(string.characters16(), string.length());
+}
+
+inline StringView::StringView(const String& string)
+{
+ if (!string.impl()) {
+ m_characters = nullptr;
+ m_length = 0;
+ return;
+ }
+ if (string.is8Bit()) {
+ initialize(string.characters8(), string.length());
+ return;
+ }
+ initialize(string.characters16(), string.length());
+}
+
</ins><span class="cx"> inline void StringView::getCharactersWithUpconvert(LChar* destination) const
</span><span class="cx"> {
</span><span class="cx"> ASSERT(is8Bit());
</span><span class="lines">@@ -247,6 +232,45 @@
</span><span class="cx"> m_characters = m_upconvertedCharacters.data();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+inline String StringView::toString() const
+{
+ if (is8Bit())
+ return String(characters8(), length());
+
+ return String(characters16(), length());
+}
+
+inline float StringView::toFloat(bool& isValid) const
+{
+ if (is8Bit())
+ return charactersToFloat(characters8(), length(), &isValid);
+ return charactersToFloat(characters16(), length(), &isValid);
+}
+
+inline int StringView::toInt(bool& isValid) const
+{
+ if (is8Bit())
+ return charactersToInt(characters8(), length(), &isValid);
+ return charactersToInt(characters16(), length(), &isValid);
+}
+
+inline String StringView::toStringWithoutCopying() const
+{
+ if (is8Bit())
+ return StringImpl::createWithoutCopying(characters8(), length());
+
+ return StringImpl::createWithoutCopying(characters16(), length());
+}
+
+inline size_t StringView::find(UChar character, unsigned start) const
+{
+ if (is8Bit())
+ return WTF::find(characters8(), length(), character, start);
+ return WTF::find(characters16(), length(), character, start);
+}
+
+template<typename StringType> class StringTypeAdapter;
+
</ins><span class="cx"> template<> class StringTypeAdapter<StringView> {
</span><span class="cx"> public:
</span><span class="cx"> StringTypeAdapter<StringView>(StringView string)
</span></span></pre>
</div>
</div>
</body>
</html>