39#define ASSERT(x) if ( !(x) )\
40 fprintf(stderr,"ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__)
47void *
qmemmove(
void *dst,
const void *src,
size_t len );
49#define qsnprintf snprintf
59{
return str ?
static_cast<uint32_t
>(strlen(str)) : 0; }
61inline char *
qstrcpy(
char *dst,
const char *src )
62{
return src ? strcpy(dst, src) :
nullptr; }
64char *
qstrncpy(
char *dst,
const char *src,
size_t len);
67{
return s==
nullptr || *s==
'\0'; }
69inline int qstrcmp(
const char *str1,
const char *str2 )
70{
return (str1 && str2) ? strcmp(str1,str2) :
75inline int qstrncmp(
const char *str1,
const char *str2,
size_t len )
76{
return (str1 && str2) ? strncmp(str1,str2,len) :
82{
return c==
' ' || c==
'\t' || c==
'\n' || c==
'\r'; }
84int qstricmp(
const char *str1,
const char *str2 );
89 return result==0 ?
qstrcmp(str1,str2) : result;
93int qstrnicmp(
const char *str1,
const char *str2,
size_t len );
120 m_rep.resize(s.size());
121 memcpy(
m_rep.data(),s.data(),s.size());
125 m_rep.resize(s.size());
126 memcpy(
m_rep.data(),s.data(),s.size());
180 void fill(
char c,
int len = -1 )
182 int l = len==-1 ?
static_cast<int>(
m_rep.size()) : len;
183 m_rep = std::string(l,c);
188 int find(
char c,
int index=0,
bool cs=
TRUE )
const;
189 int find(
const char *
str,
int index=0,
bool cs=
TRUE )
const;
192 int findRev(
char c,
int index=-1,
bool cs=
TRUE)
const;
226 QCString mid(
size_t index,
size_t len=
static_cast<size_t>(-1) )
const
228 size_t slen =
m_rep.size();
229 if (len==
static_cast<uint32_t
>(-1)) len = slen-index;
247 size_t sl =
m_rep.size();
249 size_t start=0,
end=sl-1;
262 size_t start=0, sl=
m_rep.size(),
end=sl-1;
266 bool needsQuotes=
false;
270 while (i<
end && !needsQuotes)
272 needsQuotes =
m_rep[i] ==
'-';
288 size_t sl =
m_rep.size();
289 if (sl==0)
return *
this;
290 std::string result =
m_rep;
297 if (dst<
m_rep.size()) result.resize(dst);
310 for (offset = 0; offset < n *
size(); offset +=
size())
321 size_t ol =
m_rep.size();
325 std::memset(&
m_rep[ol],
' ',index-ol);
340 size_t ol =
m_rep.size();
343 m_rep.resize(index+s.length());
344 std::memset(&
m_rep[ol],
' ',index-ol);
345 std::memcpy(&
m_rep[index],s.data(),s.length()+1);
349 m_rep.insert(index,s);
357 size_t len = s ?
qstrlen(s) : 0;
360 size_t ol =
m_rep.size();
363 m_rep.resize(index+len);
364 std::memset(&
m_rep[ol],
' ',index-ol);
365 std::memcpy(&
m_rep[index],s,len+1);
369 m_rep.insert(index,s);
377 char s[2] = { c,
'\0' };
419 return insert(0,s.c_str());
429 size_t ol =
m_rep.size();
430 if (index<ol && len>0)
m_rep.erase(index,index+len>=ol ? std::string::npos : len);
436 short toShort(
bool *ok=
nullptr,
int base=10 )
const;
437 uint16_t
toUShort(
bool *ok=
nullptr,
int base=10 )
const;
438 int toInt(
bool *ok=
nullptr,
int base=10 )
const;
439 uint32_t
toUInt(
bool *ok=
nullptr,
int base=10 )
const;
440 long toLong(
bool *ok=
nullptr,
int base=10 )
const;
441 unsigned long toULong(
bool *ok=
nullptr,
int base=10 )
const;
442 uint64_t
toUInt64(
bool *ok=
nullptr,
int base=10 )
const;
446 m_rep = std::to_string(n);
452 m_rep = std::to_string(n);
458 m_rep = std::to_string(n);
464 m_rep = std::to_string(n);
470 m_rep = std::to_string(n);
476 m_rep = std::to_string(n);
482 m_rep = std::to_string(n);
488 m_rep = std::to_string(n);
494 if (
m_rep.empty() || s==
nullptr)
return s==
nullptr;
495 return m_rep.rfind(s,0)==0;
506 if (
m_rep.empty() || s==
nullptr)
return s==
nullptr;
507 size_t l = strlen(s);
508 return m_rep.length()>=l &&
m_rep.compare(
m_rep.length()-l, l, s, l)==0;
517#define HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING 0
518#if HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING
520 operator const char *()
const
526 const std::string &
str()
const
556#define HAS_CHARACTER_APPEND_OPERATOR 1
557#if HAS_CHARACTER_APPEND_OPERATOR
572 const char &
at(
size_t i)
const
597{
return s1.
str() == s2.
str(); }
606{
return s1.
str() != s2.
str(); }
663 if (s)
return s;
else return "";
671inline const char *
qPrint(
const std::string &s)
754 std::string ss = s.
str();
755 std::replace(ss.begin(),ss.end(),srcChar,dstChar);
This is an alternative implementation of QCString.
int find(char c, int index=0, bool cs=TRUE) const
void fill(char c, int len=-1)
Fills a string with a predefined character.
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)
size_t length() const
Returns the length of the string, not counting the 0-terminator.
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.
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)
QCString(std::string &&s)
void resize(size_t newlen)
QCString & append(const std::string &s)
QCString & prepend(const std::string &s)
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)
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)
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
int findRev(char c, int index=-1, bool cs=TRUE) 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)
QCString & prepend(const QCString &s)
QCString & insert(size_t index, const QCString &s)
QCString removeWhiteSpace() const
returns a copy of this string with all whitespace removed
QCString left(size_t len) const
int contains(char c, bool cs=TRUE) 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)
Returns a copy of a string 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.