xref: /freebsd/contrib/llvm-project/compiler-rt/lib/scudo/standalone/string_utils.h (revision 3e8eb5c7f4909209c042403ddee340b2ee7003a5)
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 
9 #ifndef SCUDO_STRING_UTILS_H_
10 #define SCUDO_STRING_UTILS_H_
11 
12 #include "internal_defs.h"
13 #include "vector.h"
14 
15 #include <stdarg.h>
16 
17 namespace scudo {
18 
19 class ScopedString {
20 public:
21   explicit ScopedString() { String.push_back('\0'); }
22   uptr length() { return String.size() - 1; }
23   const char *data() { return String.data(); }
24   void clear() {
25     String.clear();
26     String.push_back('\0');
27   }
28   void append(const char *Format, va_list Args);
29   void append(const char *Format, ...) FORMAT(2, 3);
30   void output() const { outputRaw(String.data()); }
31 
32 private:
33   Vector<char> String;
34 };
35 
36 int formatString(char *Buffer, uptr BufferLength, const char *Format, ...)
37     FORMAT(3, 4);
38 void Printf(const char *Format, ...) FORMAT(1, 2);
39 
40 } // namespace scudo
41 
42 #endif // SCUDO_STRING_UTILS_H_
43