1 //===-- MIUtilString.h ------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
11 // Third party headers:
18 #include "MIDataTypes.h"
21 //============================================================================
22 // Details: MI common code utility class. Used to help handle text.
23 // Derived from std::string
25 class CMIUtilString : public std::string {
28 typedef std::vector<CMIUtilString> VecString_t;
32 static CMIUtilString Format(const char *vFormating, ...);
33 static CMIUtilString FormatBinary(const MIuint64 vnDecimal);
34 static CMIUtilString FormatValist(const CMIUtilString &vrFormating,
36 static bool IsAllValidAlphaAndNumeric(const char *vpText);
37 static const char *WithNullAsEmpty(const char *vpText) {
38 return vpText ? vpText : "";
40 static bool Compare(const CMIUtilString &vrLhs, const CMIUtilString &vrRhs);
41 static CMIUtilString ConvertToPrintableASCII(const char vChar,
42 bool bEscapeQuotes = false);
43 static CMIUtilString ConvertToPrintableASCII(const char16_t vChar16,
44 bool bEscapeQuotes = false);
45 static CMIUtilString ConvertToPrintableASCII(const char32_t vChar32,
46 bool bEscapeQuotes = false);
50 /* ctor */ CMIUtilString();
51 /* ctor */ CMIUtilString(const char *vpData);
52 /* ctor */ CMIUtilString(const std::string &vrStr);
54 bool ExtractNumber(MIint64 &vwrNumber) const;
55 CMIUtilString FindAndReplace(const CMIUtilString &vFind,
56 const CMIUtilString &vReplaceWith) const;
57 bool IsNumber() const;
58 bool IsHexadecimalNumber() const;
59 bool IsQuoted() const;
60 CMIUtilString RemoveRepeatedCharacters(const char vChar);
61 size_t Split(const CMIUtilString &vDelimiter, VecString_t &vwVecSplits) const;
62 size_t SplitConsiderQuotes(const CMIUtilString &vDelimiter,
63 VecString_t &vwVecSplits) const;
64 size_t SplitLines(VecString_t &vwVecSplits) const;
65 CMIUtilString StripCREndOfLine() const;
66 CMIUtilString StripCRAll() const;
67 CMIUtilString Trim() const;
68 CMIUtilString Trim(const char vChar) const;
69 size_t FindFirst(const CMIUtilString &vrPattern, size_t vnPos = 0) const;
70 size_t FindFirst(const CMIUtilString &vrPattern, bool vbSkipQuotedText,
71 bool &vrwbNotFoundClosedQuote, size_t vnPos = 0) const;
72 size_t FindFirstNot(const CMIUtilString &vrPattern, size_t vnPos = 0) const;
73 CMIUtilString Escape(bool vbEscapeQuotes = false) const;
74 CMIUtilString AddSlashes() const;
75 CMIUtilString StripSlashes() const;
77 CMIUtilString &operator=(const char *vpRhs);
78 CMIUtilString &operator=(const std::string &vrRhs);
82 /* dtor */ virtual ~CMIUtilString();
86 static CMIUtilString FormatPriv(const CMIUtilString &vrFormat, va_list vArgs);
87 static CMIUtilString ConvertCharValueToPrintableASCII(char vChar,
92 bool ExtractNumberFromHexadecimal(MIint64 &vwrNumber) const;
93 CMIUtilString RemoveRepeatedCharacters(size_t vnPos, const char vChar);
94 size_t FindFirstQuote(size_t vnPos) const;