| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 URL_URL_CANON_STDSTRING_H_ | 5 #ifndef URL_URL_CANON_STDSTRING_H_ |
| 6 #define URL_URL_CANON_STDSTRING_H_ | 6 #define URL_URL_CANON_STDSTRING_H_ |
| 7 | 7 |
| 8 // This header file defines a canonicalizer output method class for STL | 8 // This header file defines a canonicalizer output method class for STL |
| 9 // strings. Because the canonicalizer tries not to be dependent on the STL, | 9 // strings. Because the canonicalizer tries not to be dependent on the STL, |
| 10 // we have segregated it here. | 10 // we have segregated it here. |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/strings/string_piece.h" |
| 15 #include "url/url_canon.h" | 16 #include "url/url_canon.h" |
| 16 #include "url/url_export.h" | 17 #include "url/url_export.h" |
| 17 | 18 |
| 18 namespace url { | 19 namespace url { |
| 19 | 20 |
| 20 // Write into a std::string given in the constructor. This object does not own | 21 // Write into a std::string given in the constructor. This object does not own |
| 21 // the string itself, and the user must ensure that the string stays alive | 22 // the string itself, and the user must ensure that the string stays alive |
| 22 // throughout the lifetime of this object. | 23 // throughout the lifetime of this object. |
| 23 // | 24 // |
| 24 // The given string will be appended to; any existing data in the string will | 25 // The given string will be appended to; any existing data in the string will |
| (...skipping 16 matching lines...) Expand all Loading... |
| 41 // Must be called after writing has completed but before the string is used. | 42 // Must be called after writing has completed but before the string is used. |
| 42 void Complete(); | 43 void Complete(); |
| 43 | 44 |
| 44 void Resize(int sz) override; | 45 void Resize(int sz) override; |
| 45 | 46 |
| 46 protected: | 47 protected: |
| 47 std::string* str_; | 48 std::string* str_; |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 // An extension of the Replacements class that allows the setters to use | 51 // An extension of the Replacements class that allows the setters to use |
| 51 // standard strings. | 52 // StringPieces (implicitly allowing strings or char*s). |
| 52 // | 53 // |
| 53 // The strings passed as arguments are not copied and must remain valid until | 54 // The contents of the StringPieces are not copied and must remain valid until |
| 54 // this class goes out of scope. | 55 // the StringPieceReplacements object goes out of scope. |
| 55 template<typename STR> | 56 template<typename STR> |
| 56 class StdStringReplacements : public Replacements<typename STR::value_type> { | 57 class StringPieceReplacements : public Replacements<typename STR::value_type> { |
| 57 public: | 58 public: |
| 58 void SetSchemeStr(const STR& s) { | 59 void SetSchemeStr(const base::BasicStringPiece<STR>& s) { |
| 59 this->SetScheme(s.data(), Component(0, static_cast<int>(s.length()))); | 60 this->SetScheme(s.data(), Component(0, static_cast<int>(s.length()))); |
| 60 } | 61 } |
| 61 void SetUsernameStr(const STR& s) { | 62 void SetUsernameStr(const base::BasicStringPiece<STR>& s) { |
| 62 this->SetUsername(s.data(), Component(0, static_cast<int>(s.length()))); | 63 this->SetUsername(s.data(), Component(0, static_cast<int>(s.length()))); |
| 63 } | 64 } |
| 64 void SetPasswordStr(const STR& s) { | 65 void SetPasswordStr(const base::BasicStringPiece<STR>& s) { |
| 65 this->SetPassword(s.data(), Component(0, static_cast<int>(s.length()))); | 66 this->SetPassword(s.data(), Component(0, static_cast<int>(s.length()))); |
| 66 } | 67 } |
| 67 void SetHostStr(const STR& s) { | 68 void SetHostStr(const base::BasicStringPiece<STR>& s) { |
| 68 this->SetHost(s.data(), Component(0, static_cast<int>(s.length()))); | 69 this->SetHost(s.data(), Component(0, static_cast<int>(s.length()))); |
| 69 } | 70 } |
| 70 void SetPortStr(const STR& s) { | 71 void SetPortStr(const base::BasicStringPiece<STR>& s) { |
| 71 this->SetPort(s.data(), Component(0, static_cast<int>(s.length()))); | 72 this->SetPort(s.data(), Component(0, static_cast<int>(s.length()))); |
| 72 } | 73 } |
| 73 void SetPathStr(const STR& s) { | 74 void SetPathStr(const base::BasicStringPiece<STR>& s) { |
| 74 this->SetPath(s.data(), Component(0, static_cast<int>(s.length()))); | 75 this->SetPath(s.data(), Component(0, static_cast<int>(s.length()))); |
| 75 } | 76 } |
| 76 void SetQueryStr(const STR& s) { | 77 void SetQueryStr(const base::BasicStringPiece<STR>& s) { |
| 77 this->SetQuery(s.data(), Component(0, static_cast<int>(s.length()))); | 78 this->SetQuery(s.data(), Component(0, static_cast<int>(s.length()))); |
| 78 } | 79 } |
| 79 void SetRefStr(const STR& s) { | 80 void SetRefStr(const base::BasicStringPiece<STR>& s) { |
| 80 this->SetRef(s.data(), Component(0, static_cast<int>(s.length()))); | 81 this->SetRef(s.data(), Component(0, static_cast<int>(s.length()))); |
| 81 } | 82 } |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 } // namespace url | 85 } // namespace url |
| 85 | 86 |
| 86 #endif // URL_URL_CANON_STDSTRING_H_ | 87 #endif // URL_URL_CANON_STDSTRING_H_ |
| OLD | NEW |