]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MIUtilString.h
Unbreak DRM KMS build by adding the needed compatibility field in the LinuxKPI.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MIUtilString.h
1 //===-- MIUtilString.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 #pragma once
10
11 // Third party headers:
12 #include <cinttypes>
13 #include <cstdarg>
14 #include <string>
15 #include <vector>
16
17 // In-house headers:
18 #include "MIDataTypes.h"
19
20 //++
21 //============================================================================
22 // Details: MI common code utility class. Used to help handle text.
23 //          Derived from std::string
24 //--
25 class CMIUtilString : public std::string {
26   // Typedefs:
27 public:
28   typedef std::vector<CMIUtilString> VecString_t;
29
30   // Static method:
31 public:
32   static CMIUtilString Format(const char *vFormating, ...);
33   static CMIUtilString FormatBinary(const MIuint64 vnDecimal);
34   static CMIUtilString FormatValist(const CMIUtilString &vrFormating,
35                                     va_list vArgs);
36   static bool IsAllValidAlphaAndNumeric(const char *vpText);
37   static const char *WithNullAsEmpty(const char *vpText) {
38     return vpText ? vpText : "";
39   }
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);
47
48   // Methods:
49 public:
50   /* ctor */ CMIUtilString();
51   /* ctor */ CMIUtilString(const char *vpData);
52   /* ctor */ CMIUtilString(const std::string &vrStr);
53   //
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;
76   //
77   CMIUtilString &operator=(const char *vpRhs);
78   CMIUtilString &operator=(const std::string &vrRhs);
79
80   // Overrideable:
81 public:
82   /* dtor */ virtual ~CMIUtilString();
83
84   // Static method:
85 private:
86   static CMIUtilString FormatPriv(const CMIUtilString &vrFormat, va_list vArgs);
87   static CMIUtilString ConvertCharValueToPrintableASCII(char vChar,
88                                                         bool bEscapeQuotes);
89
90   // Methods:
91 private:
92   bool ExtractNumberFromHexadecimal(MIint64 &vwrNumber) const;
93   CMIUtilString RemoveRepeatedCharacters(size_t vnPos, const char vChar);
94   size_t FindFirstQuote(size_t vnPos) const;
95 };