33#define ASSERT(x) if ( !(x) )\
34 fprintf(stderr,"ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__)
41void *
qmemmove(
void *dst,
const void *src,
size_t len );
43#define qsnprintf snprintf
53{
return str ?
static_cast<uint32_t
>(strlen(str)) : 0; }
55inline char *
qstrcpy(
char *dst,
const char *src )
56{
return src ? strcpy(dst, src) :
nullptr; }
58char *
qstrncpy(
char *dst,
const char *src,
size_t len);
61{
return s==
nullptr || *s==
'\0'; }
63inline int qstrcmp(
const char *str1,
const char *str2 )
64{
return (str1 && str2) ? strcmp(str1,str2) :
69inline int qstrncmp(
const char *str1,
const char *str2,
size_t len )
70{
return (str1 && str2) ? strncmp(str1,str2,len) :
76{
return c==
' ' || c==
'\t' || c==
'\n' || c==
'\r'; }
78int qstricmp(
const char *str1,
const char *str2 );
83 return result==0 ?
qstrcmp(str1,str2) : result;
87int qstrnicmp(
const char *str1,
const char *str2,
size_t len );
127#ifndef DISABLE_JAVACC
130 m_rep.resize(s.size());
131 std::memcpy(
m_rep.data(),s.data(),s.size());
135 m_rep.resize(s.size());
136 std::memcpy(
m_rep.data(),s.data(),s.size());
193 int l = len==-1 ?
static_cast<int>(
m_rep.size()) : len;
194 m_rep = std::string(l,c);
200 int find(
char c,
int index=0,
bool cs=
true )
const;
201 int find(
const char *
str,
int index=0,
bool cs=
true )
const;
202 int find(
const std::string &
str,
int index=0,
bool cs=
true )
const;
205 int findRev(
char c,
int index=-1,
bool cs=
true)
const;
206 int findRev(
const char *
str,
int index=-1,
bool cs=
true)
const;
208 int contains(
char c,
bool cs=
true )
const;
209 int contains(
const char *
str,
bool cs=
true )
const;
213 if (
prefix.isEmpty() ||
m_rep.empty())
return false;
239 QCString mid(
size_t index,
size_t len=
static_cast<size_t>(-1) )
const
241 size_t slen =
m_rep.size();
242 if (len==
static_cast<uint32_t
>(-1)) len = slen-index;
260 size_t sl =
m_rep.size();
262 size_t start=0,
end=sl-1;
275 size_t start=0, sl=
m_rep.size(),
end=sl-1;
279 bool needsQuotes=
false;
283 while (i<
end && !needsQuotes)
285 needsQuotes =
m_rep[i] ==
'-';
301 size_t sl =
m_rep.size();
302 if (sl==0)
return *
this;
303 std::string result =
m_rep;
310 if (dst<
m_rep.size()) result.resize(dst);
323 for (offset = 0; offset < n *
size(); offset +=
size())
334 size_t ol =
m_rep.size();
338 std::memset(&
m_rep[ol],
' ',index-ol);
353 size_t ol =
m_rep.size();
356 m_rep.resize(index+s.length());
357 std::memset(&
m_rep[ol],
' ',index-ol);
358 std::memcpy(&
m_rep[index],s.data(),s.length()+1);
362 m_rep.insert(index,s);
370 size_t len = s ?
qstrlen(s) : 0;
373 size_t ol =
m_rep.size();
376 m_rep.resize(index+len);
377 std::memset(&
m_rep[ol],
' ',index-ol);
378 std::memcpy(&
m_rep[index],s,len+1);
382 m_rep.insert(index,s);
390 char s[2] = { c,
'\0' };
432 return insert(0,s.c_str());
442 size_t ol =
m_rep.size();
443 if (index<ol && len>0)
m_rep.erase(index,index+len>=ol ? std::string::npos : len);
449 short toShort(
bool *ok=
nullptr,
int base=10 )
const;
450 uint16_t
toUShort(
bool *ok=
nullptr,
int base=10 )
const;
451 int toInt(
bool *ok=
nullptr,
int base=10 )
const;
452 uint32_t
toUInt(
bool *ok=
nullptr,
int base=10 )
const;
453 long toLong(
bool *ok=
nullptr,
int base=10 )
const;
454 unsigned long toULong(
bool *ok=
nullptr,
int base=10 )
const;
455 uint64_t
toUInt64(
bool *ok=
nullptr,
int base=10 )
const;
459 m_rep = std::to_string(n);
465 m_rep = std::to_string(n);
471 m_rep = std::to_string(n);
477 m_rep = std::to_string(n);
483 m_rep = std::to_string(n);
489 m_rep = std::to_string(n);
495 m_rep = std::to_string(n);
501 m_rep = std::to_string(n);
507 if (
m_rep.empty() || s==
nullptr)
return s==
nullptr;
508 return m_rep.rfind(s,0)==0;
513 return m_rep.rfind(s,0)==0;
524 if (
m_rep.empty() || s==
nullptr)
return s==
nullptr;
525 size_t l = strlen(s);
526 return m_rep.length()>=l &&
m_rep.compare(
m_rep.length()-l, l, s, l)==0;
531 size_t l = s.length();
541#define HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING 0
542#if HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING
544 operator const char *()
const
550 const std::string &
str()
const
580#define HAS_CHARACTER_APPEND_OPERATOR 1
581#if HAS_CHARACTER_APPEND_OPERATOR
596 const char &
at(
size_t i)
const
621{
return s1.
str() == s2.
str(); }
630{
return s1.
str() != s2.
str(); }
687 if (s)
return s;
else return "";
695inline const char *
qPrint(
const std::string &s)
778 std::string ss = s.
str();
779 std::replace(ss.begin(),ss.end(),srcChar,dstChar);
This is an alternative implementation of QCString.
QCString & prepend(const char *s)
QCString & insert(size_t index, const char *s)
QCString(std::string_view sv)
int toInt(bool *ok=nullptr, int base=10) const
QCString & setNum(uint32_t n)
QCString & operator=(QCString &&)=default
size_t length() const
Returns the length of the string, not counting the 0-terminator.
QCString & operator=(const QCString &)=default
QCString & operator=(std::string_view sv)
bool startsWith(const char *s) const
QCString(const char *str)
creates a string from a plain C string.
QCString(const JavaCCString &s)
For converting a JavaCC string.
QCString & setNum(long n)
QCString & setNum(uint16_t n)
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
QCString & operator=(const JavaCCString &s)
QCString & append(const char *s)
bool endsWith(const QCString &s) const
bool stripPrefix(const char *prefix)
QCString & operator+=(const std::string &s)
QCString & operator+=(const QCString &s)
bool endsWith(const char *s) const
char & at(size_t i)
Returns a reference to the character at index i.
int find(char c, int index=0, bool cs=true) const
QCString & append(const QCString &s)
uint64_t toUInt64(bool *ok=nullptr, int base=10) const
QCString & operator=(const std::string &s)
const char & operator[](size_t i) const
unsigned long toULong(bool *ok=nullptr, int base=10) const
char * rawData()
Returns a writable pointer to the data.
bool isEmpty() const
Returns true iff the string is empty.
QCString & operator+=(std::string_view s)
QCString stripLeadingAndTrailingEmptyLines() const
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
QCString & remove(size_t index, size_t len)
QCString repeat(unsigned int n) const
QCString & append(std::string_view s)
bool endsWith(const std::string &s) const
QCString(std::string &&s)
void resize(size_t newlen)
QCString & append(const std::string &s)
QCString fill(char c, int len=-1)
Fills a string with a predefined character.
QCString & prepend(const std::string &s)
QCString(QCString &&)=default
QCString & prepend(std::string_view s)
QCString & operator+=(const char *s)
Appends string str to this string and returns a reference to the result.
bool startsWith(const QCString &s) const
const std::string & str() const
QCString & setNum(short n)
uint16_t toUShort(bool *ok=nullptr, int base=10) const
QCString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple whitespace cha...
QCString & append(char c)
QCString right(size_t len) const
QCString & setNum(unsigned long long n)
QCString & operator=(std::string &&s)
size_t size() const
Returns the length of the string, not counting the 0-terminator.
QCString & setNum(long long n)
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
QCString & setNum(unsigned long n)
QCString(const QCString &)=default
char & operator[](size_t i)
Indexing operator.
QCString & sprintf(const char *format,...)
long toLong(bool *ok=nullptr, int base=10) const
SizeTag
creates a string with room for size characters
uint32_t toUInt(bool *ok=nullptr, int base=10) const
QCString & replace(size_t index, size_t len, const char *s)
QCString(const char *str, size_t maxlen)
creates a string from str and copies over the first maxlen characters.
QCString & insert(size_t index, char c)
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
std::string_view view() const
const char & at(size_t i) const
QCString(size_t size, SizeTag t)
bool startsWith(const std::string &s) const
QCString & prepend(const QCString &s)
int contains(char c, bool cs=true) const
QCString & insert(size_t index, const QCString &s)
QCString removeWhiteSpace() const
returns a copy of this string with all whitespace removed
int findRev(char c, int index=-1, bool cs=true) const
QCString left(size_t len) const
bool stripPrefix(const QCString &prefix)
QCString(const std::string &s)
QCString & operator=(const char *str)
replaces the contents by that of C string str.
QCString & insert(size_t index, std::string_view s)
short toShort(bool *ok=nullptr, int base=10) const
DirIterator end(const DirIterator &) noexcept
int qstricmp_sort(const char *str1, const char *str2)
char * qstrncpy(char *dst, const char *src, size_t len)
int qstrncmp(const char *str1, const char *str2, size_t len)
bool operator>(const QCString &s1, const char *s2)
bool operator>=(const QCString &s1, const char *s2)
int qstricmp(const char *str1, const char *str2)
std::ostream & operator<<(std::ostream &os, const QCString &s)
QCString substitute(const QCString &str, const QCString &find, const QCString &replace)
substitute all occurrences of src in s by dst
int qstrnicmp(const char *str1, const char *str2, size_t len)
const char * qPrint(const char *s)
bool operator<=(const QCString &s1, const char *s2)
uint32_t qstrlen(const char *str)
Returns the length of string str, or 0 if a null pointer is passed.
void qstrfree(const char *s)
Frees the memory allocated using qstrdup().
char * qstrcpy(char *dst, const char *src)
std::string toStdString(const QCString &s)
bool qisempty(const char *s)
int qstrcmp(const char *str1, const char *str2)
bool operator==(const QCString &s1, const QCString &s2)
QCString operator+(const QCString &s1, const QCString &s2)
void * qmemmove(void *dst, const void *src, size_t len)
bool operator<(const QCString &s1, const QCString &s2)
bool operator!=(const QCString &s1, const QCString &s2)
std::basic_string< JAVACC_CHAR_TYPE > JavaCCString
char * qstrdup(const char *s)
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.