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

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringUTF8Adaptor.h

Issue 1458513002: Implement StringUTF8Adaptor::asStringPiece. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add //base to wtf's public_deps. Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef StringUTF8Adaptor_h 31 #ifndef StringUTF8Adaptor_h
32 #define StringUTF8Adaptor_h 32 #define StringUTF8Adaptor_h
33 33
34 #include "base/strings/string_piece.h"
34 #include "wtf/text/CString.h" 35 #include "wtf/text/CString.h"
35 #include "wtf/text/TextEncoding.h" 36 #include "wtf/text/TextEncoding.h"
36 #include "wtf/text/WTFString.h" 37 #include "wtf/text/WTFString.h"
37 38
38 namespace WTF { 39 namespace WTF {
39 40
40 // This class lets you get UTF-8 data out of a String without mallocing a 41 // This class lets you get UTF-8 data out of a String without mallocing a
41 // separate buffer to hold the data if the String happens to be 8 bit and 42 // separate buffer to hold the data if the String happens to be 8 bit and
42 // contain only ASCII characters. 43 // contain only ASCII characters.
43 class StringUTF8Adaptor { 44 class StringUTF8Adaptor {
(...skipping 14 matching lines...) Expand all
58 } else { 59 } else {
59 m_utf8Buffer = string.utf8(); 60 m_utf8Buffer = string.utf8();
60 m_data = m_utf8Buffer.data(); 61 m_data = m_utf8Buffer.data();
61 m_length = m_utf8Buffer.length(); 62 m_length = m_utf8Buffer.length();
62 } 63 }
63 } 64 }
64 65
65 const char* data() const { return m_data; } 66 const char* data() const { return m_data; }
66 size_t length() const { return m_length; } 67 size_t length() const { return m_length; }
67 68
69 base::StringPiece asStringPiece() const { return base::StringPiece(m_data, m _length); }
70
68 private: 71 private:
69 CString m_utf8Buffer; 72 CString m_utf8Buffer;
70 const char* m_data; 73 const char* m_data;
71 size_t m_length; 74 size_t m_length;
72 }; 75 };
73 76
74 } // namespace WTF 77 } // namespace WTF
75 78
76 using WTF::StringUTF8Adaptor; 79 using WTF::StringUTF8Adaptor;
77 80
78 #endif // StringUTF8Adaptor_h 81 #endif // StringUTF8Adaptor_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698