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 );
133 m_rep.resize(s.size());
134 memcpy(
m_rep.data(),s.data(),s.size());
138 m_rep.resize(s.size());
139 memcpy(
m_rep.data(),s.data(),s.size());
195 int l = len==-1 ?
static_cast<int>(
m_rep.size()) : len;
196 m_rep = std::string(l,c);
202 int find(
char c,
int index=0,
bool cs=
TRUE )
const;
203 int find(
const char *
str,
int index=0,
bool cs=
TRUE )
const;
204 int find(
const std::string &
str,
int index=0,
bool cs=
TRUE )
const;
207 int findRev(
char c,
int index=-1,
bool cs=
TRUE)
const;
241 QCString mid(
size_t index,
size_t len=
static_cast<size_t>(-1) )
const
243 size_t slen =
m_rep.size();
244 if (len==
static_cast<uint32_t
>(-1)) len = slen-index;
262 size_t sl =
m_rep.size();
264 size_t start=0,
end=sl-1;
277 size_t start=0, sl=
m_rep.size(),
end=sl-1;
281 bool needsQuotes=
false;
285 while (i<
end && !needsQuotes)
287 needsQuotes =
m_rep[i] ==
'-';
303 size_t sl =
m_rep.size();
304 if (sl==0)
return *
this;
305 std::string result =
m_rep;
312 if (dst<
m_rep.size()) result.resize(dst);
325 for (offset = 0; offset < n *
size(); offset +=
size())
336 size_t ol =
m_rep.size();
340 std::memset(&
m_rep[ol],
' ',index-ol);
355 size_t ol =
m_rep.size();
358 m_rep.resize(index+s.length());
359 std::memset(&
m_rep[ol],
' ',index-ol);
360 std::memcpy(&
m_rep[index],s.data(),s.length()+1);
364 m_rep.insert(index,s);
372 size_t len = s ?
qstrlen(s) : 0;
375 size_t ol =
m_rep.size();
378 m_rep.resize(index+len);
379 std::memset(&
m_rep[ol],
' ',index-ol);
380 std::memcpy(&
m_rep[index],s,len+1);
384 m_rep.insert(index,s);
392 char s[2] = { c,
'\0' };
434 return insert(0,s.c_str());
444 size_t ol =
m_rep.size();
445 if (index<ol && len>0)
m_rep.erase(index,index+len>=ol ? std::string::npos : len);
451 short toShort(
bool *ok=
nullptr,
int base=10 )
const;
452 uint16_t
toUShort(
bool *ok=
nullptr,
int base=10 )
const;
453 int toInt(
bool *ok=
nullptr,
int base=10 )
const;
454 uint32_t
toUInt(
bool *ok=
nullptr,
int base=10 )
const;
455 long toLong(
bool *ok=
nullptr,
int base=10 )
const;
456 unsigned long toULong(
bool *ok=
nullptr,
int base=10 )
const;
457 uint64_t
toUInt64(
bool *ok=
nullptr,
int base=10 )
const;
461 m_rep = std::to_string(n);
467 m_rep = std::to_string(n);
473 m_rep = std::to_string(n);
479 m_rep = std::to_string(n);
485 m_rep = std::to_string(n);
491 m_rep = std::to_string(n);
497 m_rep = std::to_string(n);
503 m_rep = std::to_string(n);
509 if (
m_rep.empty() || s==
nullptr)
return s==
nullptr;
510 return m_rep.rfind(s,0)==0;
515 return m_rep.rfind(s,0)==0;
526 if (
m_rep.empty() || s==
nullptr)
return s==
nullptr;
527 size_t l = strlen(s);
528 return m_rep.length()>=l &&
m_rep.compare(
m_rep.length()-l, l, s, l)==0;
533 size_t l = s.length();
543#define HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING 0
544#if HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING
546 operator const char *()
const
552 const std::string &
str()
const
582#define HAS_CHARACTER_APPEND_OPERATOR 1
583#if HAS_CHARACTER_APPEND_OPERATOR
598 const char &
at(
size_t i)
const
623{
return s1.
str() == s2.
str(); }
632{
return s1.
str() != s2.
str(); }
689 if (s)
return s;
else return "";
697inline const char *
qPrint(
const std::string &s)
780 std::string ss = s.
str();
781 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
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.
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
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)
bool startsWith(const std::string &s) const
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)
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.