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

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

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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 unified diff | Download patch
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 25 matching lines...) Expand all
36 #include "wtf/text/CString.h" 36 #include "wtf/text/CString.h"
37 #include "wtf/text/TextEncoding.h" 37 #include "wtf/text/TextEncoding.h"
38 #include "wtf/text/WTFString.h" 38 #include "wtf/text/WTFString.h"
39 39
40 namespace WTF { 40 namespace WTF {
41 41
42 // This class lets you get UTF-8 data out of a String without mallocing a 42 // This class lets you get UTF-8 data out of a String without mallocing a
43 // separate buffer to hold the data if the String happens to be 8 bit and 43 // separate buffer to hold the data if the String happens to be 8 bit and
44 // contain only ASCII characters. 44 // contain only ASCII characters.
45 class StringUTF8Adaptor final { 45 class StringUTF8Adaptor final {
46 DISALLOW_NEW(); 46 DISALLOW_NEW();
47 public: 47
48 explicit StringUTF8Adaptor(const String& string) 48 public:
49 : m_data(0) 49 explicit StringUTF8Adaptor(const String& string) : m_data(0), m_length(0) {
50 , m_length(0) 50 if (string.isEmpty())
51 { 51 return;
52 if (string.isEmpty()) 52 // Unfortunately, 8 bit WTFStrings are encoded in Latin-1 and GURL uses UTF- 8
53 return; 53 // when processing 8 bit strings. If |relative| is entirely ASCII, we luck o ut
54 // Unfortunately, 8 bit WTFStrings are encoded in Latin-1 and GURL uses UTF-8 54 // and can avoid mallocing a new buffer to hold the UTF-8 data because UTF-8
55 // when processing 8 bit strings. If |relative| is entirely ASCII, we lu ck out 55 // and Latin-1 use the same code units for ASCII code points.
56 // and can avoid mallocing a new buffer to hold the UTF-8 data because U TF-8 56 if (string.is8Bit() && string.containsOnlyASCII()) {
57 // and Latin-1 use the same code units for ASCII code points. 57 m_data = reinterpret_cast<const char*>(string.characters8());
58 if (string.is8Bit() && string.containsOnlyASCII()) { 58 m_length = string.length();
59 m_data = reinterpret_cast<const char*>(string.characters8()); 59 } else {
60 m_length = string.length(); 60 m_utf8Buffer = string.utf8();
61 } else { 61 m_data = m_utf8Buffer.data();
62 m_utf8Buffer = string.utf8(); 62 m_length = m_utf8Buffer.length();
63 m_data = m_utf8Buffer.data();
64 m_length = m_utf8Buffer.length();
65 }
66 } 63 }
64 }
67 65
68 const char* data() const { return m_data; } 66 const char* data() const { return m_data; }
69 size_t length() const { return m_length; } 67 size_t length() const { return m_length; }
70 68
71 base::StringPiece asStringPiece() const { return base::StringPiece(m_data, m _length); } 69 base::StringPiece asStringPiece() const {
70 return base::StringPiece(m_data, m_length);
71 }
72 72
73 private: 73 private:
74 CString m_utf8Buffer; 74 CString m_utf8Buffer;
75 const char* m_data; 75 const char* m_data;
76 size_t m_length; 76 size_t m_length;
77 }; 77 };
78 78
79 } // namespace WTF 79 } // namespace WTF
80 80
81 using WTF::StringUTF8Adaptor; 81 using WTF::StringUTF8Adaptor;
82 82
83 #endif // StringUTF8Adaptor_h 83 #endif // StringUTF8Adaptor_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringStatics.cpp ('k') | third_party/WebKit/Source/wtf/text/StringView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698