xref: /aosp_15_r20/external/cronet/url/url_canon_stdstring.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "url/url_canon_stdstring.h"
6 
7 namespace url {
8 
StdStringCanonOutput(std::string * str)9 StdStringCanonOutput::StdStringCanonOutput(std::string* str) : str_(str) {
10   cur_len_ = str_->size();  // Append to existing data.
11   buffer_ = str_->empty() ? nullptr : &(*str_)[0];
12   buffer_len_ = str_->size();
13 }
14 
~StdStringCanonOutput()15 StdStringCanonOutput::~StdStringCanonOutput() {
16   // Nothing to do, we don't own the string.
17 }
18 
Complete()19 void StdStringCanonOutput::Complete() {
20   str_->resize(cur_len_);
21   buffer_len_ = cur_len_;
22 }
23 
Resize(size_t sz)24 void StdStringCanonOutput::Resize(size_t sz) {
25   str_->resize(sz);
26   buffer_ = str_->empty() ? nullptr : &(*str_)[0];
27   buffer_len_ = sz;
28 }
29 
30 }  // namespace url
31