/* * Copyright 2018 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// This is a minimalistic string builder class meant to cover the most cases of // when you might otherwise be tempted to use a stringstream (discouraged for // anything except logging). It uses a fixed-size buffer provided by the caller // and concatenates strings and numbers into it, allowing the results to be // read via `str()`. class SimpleStringBuilder { public: explicit SimpleStringBuilder(rtc::ArrayView<char> buffer);
SimpleStringBuilder(const SimpleStringBuilder&) = delete;
SimpleStringBuilder& operator=(const SimpleStringBuilder&) = delete;
// Returns a pointer to the built string. The name `str()` is borrowed for // compatibility reasons as we replace usage of stringstream throughout the // code base. constchar* str() const { return buffer_.data(); }
// Returns the length of the string. The name `size()` is picked for STL // compatibility reasons.
size_t size() const { return size_; }
// An always-zero-terminated fixed-size buffer that we write to. The fixed // size allows the buffer to be stack allocated, which helps performance. // Having a fixed size is furthermore useful to avoid unnecessary resizing // while building it. const rtc::ArrayView<char> buffer_;
// Represents the number of characters written to the buffer. // This does not include the terminating '\0'.
size_t size_ = 0;
};
// A string builder that supports dynamic resizing while building a string. // The class is based around an instance of std::string and allows moving // ownership out of the class once the string has been built. // Note that this class uses the heap for allocations, so SimpleStringBuilder // might be more efficient for some use cases. class StringBuilder { public:
StringBuilder() {} explicit StringBuilder(absl::string_view s) : str_(s) {}
// TODO(tommi): Support construction from StringBuilder?
StringBuilder(const StringBuilder&) = delete;
StringBuilder& operator=(const StringBuilder&) = delete;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.