10b57cec5SDimitry Andric //===-- string_utils.h ------------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef SCUDO_STRING_UTILS_H_ 100b57cec5SDimitry Andric #define SCUDO_STRING_UTILS_H_ 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "internal_defs.h" 130b57cec5SDimitry Andric #include "vector.h" 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric #include <stdarg.h> 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric namespace scudo { 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric class ScopedString { 200b57cec5SDimitry Andric public: ScopedString()21fe6060f1SDimitry Andric explicit ScopedString() { String.push_back('\0'); } length()22fe6060f1SDimitry Andric uptr length() { return String.size() - 1; } data()230b57cec5SDimitry Andric const char *data() { return String.data(); } clear()240b57cec5SDimitry Andric void clear() { 25fe6060f1SDimitry Andric String.clear(); 26fe6060f1SDimitry Andric String.push_back('\0'); 270b57cec5SDimitry Andric } 28*0fca6ea1SDimitry Andric void vappend(const char *Format, va_list &Args); 29349cc55cSDimitry Andric void append(const char *Format, ...) FORMAT(2, 3); output()3068d75effSDimitry Andric void output() const { outputRaw(String.data()); } reserve(size_t Size)31bdd1243dSDimitry Andric void reserve(size_t Size) { String.reserve(Size + 1); } capacity()32*0fca6ea1SDimitry Andric uptr capacity() { return String.capacity() - 1; } 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric private: 35*0fca6ea1SDimitry Andric void appendNumber(u64 AbsoluteValue, u8 Base, u8 MinNumberLength, 36*0fca6ea1SDimitry Andric bool PadWithZero, bool Negative, bool Upper); 37*0fca6ea1SDimitry Andric void appendUnsigned(u64 Num, u8 Base, u8 MinNumberLength, bool PadWithZero, 38*0fca6ea1SDimitry Andric bool Upper); 39*0fca6ea1SDimitry Andric void appendSignedDecimal(s64 Num, u8 MinNumberLength, bool PadWithZero); 40*0fca6ea1SDimitry Andric void appendString(int Width, int MaxChars, const char *S); 41*0fca6ea1SDimitry Andric void appendPointer(u64 ptr_value); 42*0fca6ea1SDimitry Andric 43*0fca6ea1SDimitry Andric Vector<char, 256> String; 440b57cec5SDimitry Andric }; 450b57cec5SDimitry Andric 46349cc55cSDimitry Andric void Printf(const char *Format, ...) FORMAT(1, 2); 470b57cec5SDimitry Andric 480b57cec5SDimitry Andric } // namespace scudo 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric #endif // SCUDO_STRING_UTILS_H_ 51