Add ICU message format support
[chromium-blink-merge.git] / url / url_canon_stdstring.h
blob662cac73b41cb036c706cefc7dbed4a3baebcd54
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
3 // found in the LICENSE file.
5 #ifndef URL_URL_CANON_STDSTRING_H_
6 #define URL_URL_CANON_STDSTRING_H_
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,
10 // we have segregated it here.
12 #include <string>
14 #include "base/compiler_specific.h"
15 #include "base/strings/string_piece.h"
16 #include "url/url_canon.h"
17 #include "url/url_export.h"
19 namespace url {
21 // Write into a std::string given in the constructor. This object does not own
22 // the string itself, and the user must ensure that the string stays alive
23 // throughout the lifetime of this object.
25 // The given string will be appended to; any existing data in the string will
26 // be preserved. The caller should reserve() the amount of data in the string
27 // they expect to be written. We will resize if necessary, but that's slow.
29 // Note that when canonicalization is complete, the string will likely have
30 // unused space at the end because we make the string very big to start out
31 // with (by |initial_size|). This ends up being important because resize
32 // operations are slow, and because the base class needs to write directly
33 // into the buffer.
35 // Therefore, the user should call Complete() before using the string that
36 // this class wrote into.
37 class URL_EXPORT StdStringCanonOutput : public CanonOutput {
38 public:
39 StdStringCanonOutput(std::string* str);
40 ~StdStringCanonOutput() override;
42 // Must be called after writing has completed but before the string is used.
43 void Complete();
45 void Resize(int sz) override;
47 protected:
48 std::string* str_;
51 // An extension of the Replacements class that allows the setters to use
52 // StringPieces (implicitly allowing strings or char*s).
54 // The contents of the StringPieces are not copied and must remain valid until
55 // the StringPieceReplacements object goes out of scope.
56 template<typename STR>
57 class StringPieceReplacements : public Replacements<typename STR::value_type> {
58 public:
59 void SetSchemeStr(const base::BasicStringPiece<STR>& s) {
60 this->SetScheme(s.data(), Component(0, static_cast<int>(s.length())));
62 void SetUsernameStr(const base::BasicStringPiece<STR>& s) {
63 this->SetUsername(s.data(), Component(0, static_cast<int>(s.length())));
65 void SetPasswordStr(const base::BasicStringPiece<STR>& s) {
66 this->SetPassword(s.data(), Component(0, static_cast<int>(s.length())));
68 void SetHostStr(const base::BasicStringPiece<STR>& s) {
69 this->SetHost(s.data(), Component(0, static_cast<int>(s.length())));
71 void SetPortStr(const base::BasicStringPiece<STR>& s) {
72 this->SetPort(s.data(), Component(0, static_cast<int>(s.length())));
74 void SetPathStr(const base::BasicStringPiece<STR>& s) {
75 this->SetPath(s.data(), Component(0, static_cast<int>(s.length())));
77 void SetQueryStr(const base::BasicStringPiece<STR>& s) {
78 this->SetQuery(s.data(), Component(0, static_cast<int>(s.length())));
80 void SetRefStr(const base::BasicStringPiece<STR>& s) {
81 this->SetRef(s.data(), Component(0, static_cast<int>(s.length())));
85 } // namespace url
87 #endif // URL_URL_CANON_STDSTRING_H_