40{
return str ?
static_cast<uint32_t
>(strlen(str)) : 0; }
42inline char *
dstrcpy(
char *dst,
const char *src )
43{
return src ? strcpy(dst, src) :
nullptr; }
45char *
dstrncpy(
char *dst,
const char *src,
size_t len);
48{
return s==
nullptr || *s==
'\0'; }
50inline int dstrcmp(
const char *str1,
const char *str2 )
51{
return (str1 && str2) ? strcmp(str1,str2) :
56inline int dstrncmp(
const char *str1,
const char *str2,
size_t len )
57{
return (str1 && str2) ? strncmp(str1,str2,len) :
63{
return c==
' ' || c==
'\t' || c==
'\n' || c==
'\r'; }
65int dstricmp(
const char *str1,
const char *str2 );
70 return result==0 ?
dstrcmp(str1,str2) : result;
73int dstrnicmp(
const char *str1,
const char *str2,
size_t len );
114#ifndef DISABLE_JAVACC
117 m_rep.resize(s.size());
118 std::memcpy(
m_rep.data(),s.data(),s.size());
122 m_rep.resize(s.size());
123 std::memcpy(
m_rep.data(),s.data(),s.size());
178 static constexpr size_t npos = std::string::npos;
226 size_t copy(
char *dest,
size_t count,
size_t pos=0 )
const {
return m_rep.copy(dest,count,pos); }
239 size_t find(
char c,
size_t pos=0 )
const {
return m_rep.find(c,pos); }
240 size_t find(
const char *s,
size_t pos=0 )
const {
return s?
m_rep.find(s,pos):
npos; }
242 size_t find(
const std::string &s,
size_t pos=0 )
const {
return m_rep.find(s,pos); }
247 size_t rfind(
const std::string &s,
size_t pos=
npos )
const {
return m_rep.rfind(s,pos); }
255 size_t find_first_of(
const std::string &s,
size_t pos=0 )
const {
return m_rep.find_first_of(s,pos); }
281 m_rep = std::string(len,c);
287 int contains(
char c,
bool cs=
true )
const;
288 int contains(
const char *
str,
bool cs=
true )
const;
320 size_t slen =
m_rep.size();
321 if (len==
npos) len = slen-index;
322 return m_rep.empty() || index>slen || len==0 ?
DString() :
339 size_t sl =
m_rep.size();
341 size_t start=0,
end=sl-1;
343 if (start==sl)
return DString();
354 size_t start=0, sl=
m_rep.size(),
end=sl-1;
356 if (start==sl)
return DString();
358 bool needsQuotes=
false;
362 while (i<
end && !needsQuotes)
364 needsQuotes =
m_rep[i] ==
'-';
380 size_t sl =
m_rep.size();
381 if (sl==0)
return *
this;
382 std::string result =
m_rep;
389 if (dst<
m_rep.size()) result.resize(dst);
418 for (offset = 0; offset < n *
size(); offset +=
size())
429 size_t ol =
m_rep.size();
433 std::memset(&
m_rep[ol],
' ',index-ol);
448 size_t ol =
m_rep.size();
451 m_rep.resize(index+s.length());
452 std::memset(&
m_rep[ol],
' ',index-ol);
453 std::memcpy(&
m_rep[index],s.data(),s.length()+1);
457 m_rep.insert(index,s);
465 size_t len = s ?
dstrlen(s) : 0;
468 size_t ol =
m_rep.size();
471 m_rep.resize(index+len);
472 std::memset(&
m_rep[ol],
' ',index-ol);
473 std::memcpy(&
m_rep[index],s,len+1);
477 m_rep.insert(index,s);
485 char s[2] = { c,
'\0' };
527 return insert(0,s.c_str());
537 size_t ol =
m_rep.size();
538 if (index<ol && len>0)
m_rep.erase(index,index+len>=ol ? std::string::npos : len);
544 short toShort(
bool *ok=
nullptr,
int base=10 )
const;
545 uint16_t
toUShort(
bool *ok=
nullptr,
int base=10 )
const;
546 int toInt(
bool *ok=
nullptr,
int base=10 )
const;
547 uint32_t
toUInt(
bool *ok=
nullptr,
int base=10 )
const;
548 long toLong(
bool *ok=
nullptr,
int base=10 )
const;
549 unsigned long toULong(
bool *ok=
nullptr,
int base=10 )
const;
550 uint64_t
toUInt64(
bool *ok=
nullptr,
int base=10 )
const;
554 m_rep = std::to_string(n);
560 m_rep = std::to_string(n);
566 m_rep = std::to_string(n);
572 m_rep = std::to_string(n);
578 m_rep = std::to_string(n);
584 m_rep = std::to_string(n);
590 m_rep = std::to_string(n);
596 m_rep = std::to_string(n);
602 if (
m_rep.empty() || s==
nullptr)
return s==
nullptr;
603 return m_rep.rfind(s,0)==0;
608 return m_rep.rfind(s,0)==0;
619 if (
m_rep.empty() || s==
nullptr)
return s==
nullptr;
620 size_t l = strlen(s);
621 return m_rep.length()>=l &&
m_rep.compare(
m_rep.length()-l, l, s, l)==0;
626 size_t l = s.length();
636#define HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING 0
637#if HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING
639 operator const char *()
const
645 const std::string &
str()
const
675#define HAS_CHARACTER_APPEND_OPERATOR 1
676#if HAS_CHARACTER_APPEND_OPERATOR
691 const char &
at(
size_t i)
const
719{
return s1.
str() == s2.
str(); }
728{
return s1.
str() != s2.
str(); }
785 if (s)
return s;
else return "";
790 if (!s.
empty())
return s.
data();
else return "";
793inline const char *
qPrint(
const std::string &s)
876 std::string ss = s.
str();
877 std::replace(ss.begin(),ss.end(),srcChar,dstChar);
897 return c==
'_' ||
static_cast<signed char>(c)<0 || isalnum(c) || c==
'$';
906 const int maxMarkerStrLen = 20;
907 char result[maxMarkerStrLen];
908 snprintf(result,maxMarkerStrLen,
"@%d",
id);
918 return hash<std::string>{}(s.
str());
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
DString & assign(std::string_view s)
static DString integerToAlpha(int n, bool upper=true)
DString & setNum(short n)
DString & operator+=(std::string_view s)
int compare(const char *s) const
DString & assign(const DString &s)
void resize(size_t newlen)
std::string::const_reverse_iterator const_reverse_iterator
std::string::value_type value_type
const_reverse_iterator rbegin() const
DString stripLeadingAndTrailingEmptyLines() const
char & front()
Returns a reference to the first character.
DString & setNum(unsigned long long n)
DString & operator=(std::string_view sv)
DString(const char *str)
creates a string from a plain C string.
DString & setNum(uint16_t n)
unsigned long toULong(bool *ok=nullptr, int base=10) const
DString & append(std::string_view s)
bool endsWith(const DString &s) const
DString & insert(size_t index, const char *s)
void resize(size_t newlen, char c)
Resizes the string to newlen characters, filling any new characters with c.
std::string::const_reference const_reference
size_t rfind(char c, size_t pos=npos) const
DString(const DString &)=default
const char & back() const
DString fill(char c, size_t len)
Fills a string with a predefined character.
size_t find_first_not_of(char c, size_t pos=0) const
std::string::reverse_iterator reverse_iterator
uint16_t toUShort(bool *ok=nullptr, int base=10) const
DString mid(size_t index, size_t len=npos) const
const_iterator cend() const
DString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple internal white...
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
size_t find_last_not_of(char c, size_t pos=npos) const
DString & replace(size_t index, size_t len, const char *s)
uint32_t toUInt(bool *ok=nullptr, int base=10) const
bool containsWord(const char *word) const
returns true if this string contains word as a whole word, false otherwise.
DString substr(size_t pos=0, size_t count=npos) const
Returns a substring of length count starting at pos.
static DString integerToRoman(int n, bool upper=true)
DString(size_t size, SizeTag t)
DString & operator+=(const char *s)
Appends string str to this string and returns a reference to the result.
bool startsWith(const DString &s) const
uint64_t toUInt64(bool *ok=nullptr, int base=10) const
DString & assign(const char *s)
DString(DString &&)=default
char * rawData()
Returns a writable pointer to the data.
short toShort(bool *ok=nullptr, int base=10) const
size_t find(const char *s, size_t pos=0) const
const char * c_str() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
std::string_view view() const
DString(const JavaCCString &s)
For converting a JavaCC string.
size_t find(const DString &s, size_t pos=0) const
DString & remove(size_t index, size_t len)
size_t find_first_of(const char *s, size_t pos=0) const
DString & operator=(const std::string &s)
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
const_reverse_iterator crbegin() const
DString & append(const std::string &s)
char & at(size_t i)
Returns a reference to the character at index i.
int compare(const std::string &s) const
const char & operator[](size_t i) const
std::string::size_type size_type
DString & prepend(const DString &s)
DString & operator=(const char *str)
replaces the contents by that of C string str.
size_t find_first_of(char c, size_t pos=0) const
bool findAndRemoveWord(const char *word)
removes occurrences of whole word from this string, while keeping internal spaces and reducing multip...
size_t find_last_not_of(const std::string &s, size_t pos=npos) const
DString & setNum(uint32_t n)
const_iterator begin() const
const char & at(size_t i) const
DString & append(const char *s)
DString & operator=(DString &&)=default
size_t find_last_not_of(const char *s, size_t pos=npos) const
size_t rfind_insensitive(char c, size_t pos=npos) const
bool endsWith(const std::string &s) const
size_t rfind(const std::string &s, size_t pos=npos) const
const_iterator cbegin() const
DString right(size_t len) const
DString & operator=(const DString &)=default
size_t find_first_not_of(const DString &s, size_t pos=0) const
DString & insert(size_t index, char c)
size_t find_last_of(char c, size_t pos=npos) const
size_t find(const std::string &s, size_t pos=0) const
DString repeat(unsigned int n) const
bool startsWith(const std::string &s) const
size_t size() const
Returns the length of the string, not counting the 0-terminator.
size_t copy(char *dest, size_t count, size_t pos=0) const
Copies (up to) count characters into dest, starting at pos.
size_t find_first_not_of(const char *s, size_t pos=0) const
DString & prepend(std::string_view s)
bool stripPrefix(const char *prefix)
size_t find_first_of(const DString &s, size_t pos=0) const
size_t rfind(const char *s, size_t pos=npos) const
DString & prepend(const char *s)
DString & insert(size_t index, std::string_view s)
int contains(char c, bool cs=true) const
size_t find_last_not_of(const DString &s, size_t pos=npos) const
size_t find(char c, size_t pos=0) const
DString removeWhiteSpace() const
returns a copy of this string with all whitespace removed
DString & sprintf(const char *format,...)
DString & operator=(std::string &&s)
DString & append(const DString &s)
char & operator[](size_t i)
Indexing operator.
DString(const std::string &s)
const_reverse_iterator crend() const
DString(const char *str, size_t maxlen)
creates a string from str and copies over the first maxlen characters.
std::string::reference reference
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
DString & setNum(long long n)
size_t find_first_of(const std::string &s, size_t pos=0) const
DString & operator+=(const std::string &s)
DString & erase(size_t index=0, size_t count=npos)
int toInt(bool *ok=nullptr, int base=10) const
char & back()
Returns a reference to the last character.
SizeTag
creates a string with room for size characters
long toLong(bool *ok=nullptr, int base=10) const
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
DString(std::string_view sv)
DString & operator+=(const DString &s)
void swap(DString &other)
Swaps the contents of this string with other.
size_t find_last_of(const std::string &s, size_t pos=npos) const
DString & prepend(const std::string &s)
DString left(size_t len) const
const std::string & str() const
bool stripPrefix(const DString &prefix)
int compare(const DString &s) const
const_iterator end() const
size_t find_first_not_of(const std::string &s, size_t pos=0) const
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
DString & setNum(unsigned long n)
DString & operator=(const JavaCCString &s)
bool startsWith(const char *s) const
const_reverse_iterator rend() const
size_t find_last_of(const DString &s, size_t pos=npos) const
std::string::iterator iterator
DString & assign(const std::string &s)
size_t find_last_of(const char *s, size_t pos=npos) const
size_t rfind(const DString &s, size_t pos=npos) const
reverse_iterator rbegin()
std::string::const_iterator const_iterator
bool endsWith(const char *s) const
const char & front() const
DString & insert(size_t index, const DString &s)
size_t length() const
Returns the length of the string, not counting the 0-terminator.
bool operator>(const DString &s1, const char *s2)
int dstricmp(const char *str1, const char *str2)
int dstrnicmp(const char *str1, const char *str2, size_t len)
std::string toStdString(const DString &s)
bool isId(char c)
Returns true if c is a valid character for an identifier.
char * dstrncpy(char *dst, const char *src, size_t len)
char * dstrcpy(char *dst, const char *src)
int dstrncmp(const char *str1, const char *str2, size_t len)
bool operator<=(const DString &s1, const char *s2)
DString substitute(const DString &str, const DString &find, const DString &replace)
substitute all occurrences of src in s by dst
bool disempty(const char *s)
uint32_t dstrlen(const char *str)
Returns the length of string str, or 0 if a null pointer is passed.
bool operator!=(const DString &s1, const DString &s2)
std::ostream & operator<<(std::ostream &os, const DString &s)
int dstricmp_sort(const char *str1, const char *str2)
int dstrcmp(const char *str1, const char *str2)
const char * qPrint(const char *s)
bool operator<(const DString &s1, const DString &s2)
bool operator==(const DString &s1, const DString &s2)
void swap(DString &s1, DString &s2)
char * dstrdup(const char *s)
void dstrfree(const char *s)
Frees the memory allocated using dstrdup().
DString operator+(const DString &s1, const DString &s2)
bool operator>=(const DString &s1, const char *s2)
std::basic_string< JAVACC_CHAR_TYPE > JavaCCString
DString generateMarker(int id)
size_t operator()(const DString &s) const
std::string convertUTF8ToUpper(const std::string &input)
Converts the input string into a upper case version, also taking into account non-ASCII characters th...
std::string convertUTF8ToLower(const std::string &input)
Converts the input string into a lower case version, also taking into account non-ASCII characters th...
Various UTF8 related helper functions.