string_utils.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //===-- string_utils.h ------------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef SCUDO_STRING_UTILS_H_
  9. #define SCUDO_STRING_UTILS_H_
  10. #include "internal_defs.h"
  11. #include "vector.h"
  12. #include <stdarg.h>
  13. namespace scudo {
  14. class ScopedString {
  15. public:
  16. explicit ScopedString() { String.push_back('\0'); }
  17. uptr length() { return String.size() - 1; }
  18. const char *data() { return String.data(); }
  19. void clear() {
  20. String.clear();
  21. String.push_back('\0');
  22. }
  23. void append(const char *Format, va_list Args);
  24. void append(const char *Format, ...) FORMAT(2, 3);
  25. void output() const { outputRaw(String.data()); }
  26. void reserve(size_t Size) { String.reserve(Size + 1); }
  27. private:
  28. Vector<char> String;
  29. };
  30. int formatString(char *Buffer, uptr BufferLength, const char *Format, ...)
  31. FORMAT(3, 4);
  32. void Printf(const char *Format, ...) FORMAT(1, 2);
  33. } // namespace scudo
  34. #endif // SCUDO_STRING_UTILS_H_