1 //===-- MIUtilString.h ------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #pragma once 11 12 // Third party headers: 13 #include <cinttypes> 14 #include <cstdarg> 15 #include <string> 16 #include <vector> 17 18 // In-house headers: 19 #include "MIDataTypes.h" 20 21 //++ 22 //============================================================================ 23 // Details: MI common code utility class. Used to help handle text. 24 // Derived from std::string 25 //-- 26 class CMIUtilString : public std::string { 27 // Typedefs: 28 public: 29 typedef std::vector<CMIUtilString> VecString_t; 30 31 // Static method: 32 public: 33 static CMIUtilString Format(const char *vFormating, ...); 34 static CMIUtilString FormatBinary(const MIuint64 vnDecimal); 35 static CMIUtilString FormatValist(const CMIUtilString &vrFormating, 36 va_list vArgs); 37 static bool IsAllValidAlphaAndNumeric(const char *vpText); 38 static bool Compare(const CMIUtilString &vrLhs, const CMIUtilString &vrRhs); 39 static CMIUtilString ConvertToPrintableASCII(const char vChar, 40 bool bEscapeQuotes = false); 41 static CMIUtilString ConvertToPrintableASCII(const char16_t vChar16, 42 bool bEscapeQuotes = false); 43 static CMIUtilString ConvertToPrintableASCII(const char32_t vChar32, 44 bool bEscapeQuotes = false); 45 46 // Methods: 47 public: 48 /* ctor */ CMIUtilString(); 49 /* ctor */ CMIUtilString(const char *vpData); 50 /* ctor */ CMIUtilString(const std::string &vrStr); 51 // 52 bool ExtractNumber(MIint64 &vwrNumber) const; 53 CMIUtilString FindAndReplace(const CMIUtilString &vFind, 54 const CMIUtilString &vReplaceWith) const; 55 bool IsNumber() const; 56 bool IsHexadecimalNumber() const; 57 bool IsQuoted() const; 58 CMIUtilString RemoveRepeatedCharacters(const char vChar); 59 size_t Split(const CMIUtilString &vDelimiter, VecString_t &vwVecSplits) const; 60 size_t SplitConsiderQuotes(const CMIUtilString &vDelimiter, 61 VecString_t &vwVecSplits) const; 62 size_t SplitLines(VecString_t &vwVecSplits) const; 63 CMIUtilString StripCREndOfLine() const; 64 CMIUtilString StripCRAll() const; 65 CMIUtilString Trim() const; 66 CMIUtilString Trim(const char vChar) const; 67 size_t FindFirst(const CMIUtilString &vrPattern, size_t vnPos = 0) const; 68 size_t FindFirst(const CMIUtilString &vrPattern, bool vbSkipQuotedText, 69 bool &vrwbNotFoundClosedQuote, size_t vnPos = 0) const; 70 size_t FindFirstNot(const CMIUtilString &vrPattern, size_t vnPos = 0) const; 71 CMIUtilString Escape(bool vbEscapeQuotes = false) const; 72 CMIUtilString AddSlashes() const; 73 CMIUtilString StripSlashes() const; 74 // 75 CMIUtilString &operator=(const char *vpRhs); 76 CMIUtilString &operator=(const std::string &vrRhs); 77 78 // Overrideable: 79 public: 80 /* dtor */ virtual ~CMIUtilString(); 81 82 // Static method: 83 private: 84 static CMIUtilString FormatPriv(const CMIUtilString &vrFormat, va_list vArgs); 85 static CMIUtilString ConvertCharValueToPrintableASCII(char vChar, 86 bool bEscapeQuotes); 87 88 // Methods: 89 private: 90 bool ExtractNumberFromHexadecimal(MIint64 &vwrNumber) const; 91 CMIUtilString RemoveRepeatedCharacters(size_t vnPos, const char vChar); 92 size_t FindFirstQuote(size_t vnPos) const; 93 }; 94