38 typedef unsigned char uchar;
39 typedef unsigned short ushort;
40 typedef unsigned uint;
41 typedef unsigned long ulong;
42 typedef int64_t int64;
43 typedef uint64_t uint64;
44 #define ASSERT(x) if ( !(x) )\ 45 fprintf(stderr,"ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__) 52 void *qmemmove(
void *dst,
const void *src,
size_t len );
54 #if defined(_OS_WIN32_) 55 #define qsnprintf _snprintf 57 #define qsnprintf snprintf 60 char *qstrdup(
const char * );
62 inline uint cstrlen(
const char *str )
63 {
return static_cast<uint
>(strlen(str)); }
65 inline uint qstrlen(
const char *str )
66 {
return str ?
static_cast<uint
>(strlen(str)) : 0; }
68 inline char *cstrcpy(
char *dst,
const char *src )
69 {
return strcpy(dst,src); }
71 inline char *qstrcpy(
char *dst,
const char *src )
72 {
return src ? strcpy(dst, src) : 0; }
74 char * qstrncpy(
char *dst,
const char *src,
size_t len);
76 inline int cstrcmp(
const char *str1,
const char *str2 )
77 {
return strcmp(str1,str2); }
79 inline bool qisempty(
const char *s)
80 {
return s==0 || *s==0; }
82 inline int qstrcmp(
const char *str1,
const char *str2 )
83 {
return (str1 && str2) ? strcmp(str1,str2) :
84 (qisempty(str1) && qisempty(str2)) ? 0 :
85 qisempty(str1) ? -1 : 1;
88 inline int cstrncmp(
const char *str1,
const char *str2,
size_t len )
89 {
return strncmp(str1,str2,len); }
91 inline int qstrncmp(
const char *str1,
const char *str2,
size_t len )
92 {
return (str1 && str2) ? strncmp(str1,str2,len) :
93 (qisempty(str1) && qisempty(str2)) ? 0 :
94 qisempty(str1) ? -1 : 1;
97 inline bool qisspace(
char c)
98 {
return c==
' ' || c==
'\t' || c==
'\n' || c==
'\r'; }
100 int qstricmp(
const char *str1,
const char *str2 );
102 int qstrnicmp(
const char *str1,
const char *str2,
size_t len );
118 explicit QCString(
const std::string &s ) : m_rep(s) {}
120 QCString( std::string &&s) : m_rep(std::move(s)) {}
125 explicit QCString(
size_t size ) { m_rep.resize(size>0 ? size-1 : 0); }
133 QCString(
const char *str,
size_t maxlen ) : m_rep(str?str:
"") { m_rep.resize(maxlen); }
138 QCString &operator=(
const std::string &s) { m_rep = s;
return *
this; }
141 bool isNull()
const {
return m_rep.empty(); }
144 bool isEmpty()
const {
return m_rep.empty(); }
147 uint
length()
const {
return static_cast<uint
>(m_rep.size()); }
150 uint
size()
const {
return static_cast<uint
>(m_rep.size()); }
153 const char *
data()
const {
return m_rep.c_str(); }
164 bool resize(
size_t newlen ) { m_rep.resize( newlen>0 ? newlen-1 : 0 );
return TRUE; }
175 bool fill(
char c,
int len = -1 )
177 int l = len==-1 ?
static_cast<int>(m_rep.size()) : len;
178 m_rep = std::string(l,c);
182 QCString &sprintf(
const char *format, ... );
184 int find(
char c,
int index=0,
bool cs=TRUE )
const;
185 int find(
const char *str,
int index=0,
bool cs=TRUE )
const;
186 int find(
const QCString &str,
int index=0,
bool cs=TRUE )
const;
189 int findRev(
char c,
int index=-1,
bool cs=TRUE)
const;
190 int findRev(
const char *str,
int index=-1,
bool cs=TRUE)
const;
193 int contains(
char c,
bool cs=TRUE )
const;
194 int contains(
const char *str,
bool cs=TRUE )
const;
197 bool stripPrefix(
const QCString &prefix)
199 if (prefix.
isEmpty() || m_rep.empty())
return FALSE;
200 if (m_rep.rfind(prefix.
data(),0)==0)
202 m_rep.erase(0,prefix.
length());
207 bool stripPrefix(
const char *prefix)
209 return stripPrefix(
QCString(prefix));
220 len<m_rep.size() ?
QCString(m_rep.substr(m_rep.size()-len,len)) :
224 QCString mid(
size_t index,
size_t len=static_cast<size_t>(-1))
const 226 size_t slen = m_rep.size();
227 if (len==static_cast<uint>(-1)) len = slen-index;
228 return m_rep.empty() || index>slen || len==0 ?
QCString() :
245 size_t sl = m_rep.size();
246 if (sl==0 || (!qisspace(m_rep[0]) && !qisspace(m_rep[sl-1])))
return *
this;
247 size_t start=0,end=sl-1;
248 while (start<sl && qisspace(m_rep[start])) start++;
250 while (end>start && qisspace(m_rep[end])) end--;
251 return QCString(m_rep.substr(start,1+end-start));
258 size_t start=0, sl=m_rep.size(), end=sl-1;
259 while (start<sl && qisspace(m_rep[start])) start++;
261 while (end>start && qisspace(m_rep[end])) end--;
262 bool needsQuotes=
false;
264 if (i<end && m_rep[i]!=
'"')
266 while (i<end && !needsQuotes)
268 needsQuotes = qisspace(m_rep[i++]);
271 QCString result(m_rep.substr(start,1+end-start));
274 result.prepend(
"\"");
283 size_t sl = m_rep.size();
284 if (sl==0)
return *
this;
285 std::string result = m_rep;
289 if (!qisspace(m_rep[src])) result[dst++]=m_rep[src];
292 if (dst<m_rep.size()) result.resize(dst);
304 size_t ol = m_rep.size();
307 m_rep.resize(index+s.
length());
308 std::memset(&m_rep[ol],
' ',index-ol);
309 std::memcpy(&m_rep[index],s.
data(),s.
length()+1);
313 m_rep.insert(index,s.str());
318 QCString &insert(
size_t index,
const char *s )
320 size_t len = s ? qstrlen(s) : 0;
323 size_t ol = m_rep.size();
326 m_rep.resize(index+len);
327 std::memset(&m_rep[ol],
' ',index-ol);
328 std::memcpy(&m_rep[index],s,len+1);
332 m_rep.insert(index,s);
338 QCString &insert(
size_t index,
char c)
340 char s[2] = { c,
'\0' };
341 return insert(index,s);
352 return operator+=(s);
357 return operator+=(s);
360 QCString &append(
const std::string &s )
362 return operator+=(s);
372 return insert(0,s.
data());
375 QCString &prepend(
const std::string &s )
377 return insert(0,s.c_str());
380 QCString &
remove(
size_t index,
size_t len )
382 size_t ol = m_rep.size();
383 if (index<ol && len>0) m_rep.erase(index,index+len>=ol ? std::string::npos : len);
387 QCString &replace(
size_t index,
size_t len,
const char *s);
390 short toShort(
bool *ok=0,
int base=10 )
const;
391 ushort toUShort(
bool *ok=0,
int base=10 )
const;
392 int toInt(
bool *ok=0,
int base=10 )
const;
393 uint toUInt(
bool *ok=0,
int base=10 )
const;
394 long toLong(
bool *ok=0,
int base=10 )
const;
395 ulong toULong(
bool *ok=0,
int base=10 )
const;
396 uint64 toUInt64(
bool *ok=0,
int base=10 )
const;
400 m_rep = std::to_string(n);
406 m_rep = std::to_string(n);
412 m_rep = std::to_string(n);
418 m_rep = std::to_string(n);
424 m_rep = std::to_string(n);
430 m_rep = std::to_string(n);
434 bool startsWith(
const char *s )
const 436 if (m_rep.empty() || s==0)
return s==0;
437 return m_rep.rfind(s,0)==0;
440 bool startsWith(
const QCString &s )
const 443 return m_rep.rfind(s.str(),0)==0;
446 bool endsWith(
const char *s)
const 448 if (m_rep.empty() || s==0)
return s==0;
449 size_t l = strlen(s);
450 return m_rep.length()>=l && m_rep.compare(m_rep.length()-l, l, s, l)==0;
453 bool endsWith(
const QCString &s)
const 456 return m_rep.length()>=l && m_rep.compare(m_rep.length()-l, l, s.str())==0;
459 #define HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING 0 460 #if HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING 462 operator const char *()
const 468 const std::string &str()
const 479 QCString &operator+=(
const std::string &s)
492 #define HAS_CHARACTER_APPEND_OPERATOR 1 493 #if HAS_CHARACTER_APPEND_OPERATOR 508 const char &
at(
size_t i)
const 533 {
return s1.str() == s2.str(); }
535 inline bool operator==(
const QCString &s1,
const char *s2 )
536 {
return qstrcmp(s1.
data(),s2) == 0; }
538 inline bool operator==(
const char *s1,
const QCString &s2 )
539 {
return qstrcmp(s1,s2.
data()) == 0; }
542 {
return s1.str() != s2.str(); }
544 inline bool operator!=(
const QCString &s1,
const char *s2 )
545 {
return qstrcmp(s1.
data(),s2) != 0; }
547 inline bool operator!=(
const char *s1,
const QCString &s2 )
548 {
return qstrcmp(s1,s2.
data()) != 0; }
551 {
return qstrcmp(s1.
data(),s2.
data()) < 0; }
553 inline bool operator<(
const QCString &s1,
const char *s2 )
554 {
return qstrcmp(s1.
data(),s2) < 0; }
556 inline bool operator<(
const char *s1,
const QCString &s2 )
557 {
return qstrcmp(s1,s2.
data()) < 0; }
559 inline bool operator<=(
const QCString &s1,
const char *s2 )
560 {
return qstrcmp(s1.
data(),s2) <= 0; }
562 inline bool operator<=(
const char *s1,
const QCString &s2 )
563 {
return qstrcmp(s1,s2.
data()) <= 0; }
565 inline bool operator>(
const QCString &s1,
const char *s2 )
566 {
return qstrcmp(s1.
data(),s2) > 0; }
568 inline bool operator>(
const char *s1,
const QCString &s2 )
569 {
return qstrcmp(s1,s2.
data()) > 0; }
571 inline bool operator>=(
const QCString &s1,
const char *s2 )
572 {
return qstrcmp(s1.
data(),s2) >= 0; }
574 inline bool operator>=(
const char *s1,
const QCString &s2 )
575 {
return qstrcmp(s1,s2.
data()) >= 0; }
597 #define HAD_PLUS_OPERATOR_FOR_CHAR 0 598 #if HAS_PLUS_OPERATOR_FOR_CHAR 615 inline const char *qPrint(
const char *s)
617 if (s)
return s;
else return "";
620 inline const char *qPrint(
const QCString &s)
625 inline const char *qPrint(
const std::string &s)
630 inline std::string toStdString(
const QCString &s)
637 inline int qstricmp(
const QCString &str1,
const char *str2 )
639 return qstricmp(str1.
data(),str2);
642 inline int qstricmp(
const char *str1,
const QCString &str2 )
644 return qstricmp(str1,str2.
data());
649 return qstricmp(str1.
data(),str2.
data());
652 inline int qstrnicmp(
const QCString &str1,
const char *str2,
size_t len )
654 return qstrnicmp(str1.
data(),str2,len);
657 inline int qstrnicmp(
const char *str1,
const QCString &str2,
size_t len )
659 return qstrnicmp(str1,str2.
data(),len);
662 inline int qstrnicmp(
const QCString &str1,
const QCString &str2,
size_t len )
664 return qstrnicmp(str1.
data(),str2.
data(),len);
669 inline QCString substitute(
const QCString &str,
const char *find,
const char *replace)
677 std::string ss = s.str();
678 std::replace(ss.begin(),ss.end(),srcChar,dstChar);
682 inline std::ostream& operator<<(std::ostream& os,
const QCString& s)
QCString & operator+=(char c)
Appends character c to this string and returns a reference to the result.
Definition: qcstring.h:495
QCString removeWhiteSpace() const
returns a copy of this string with all whitespace removed
Definition: qcstring.h:281
uint size() const
Returns the length of the string, not counting the 0-terminator.
Definition: qcstring.h:150
QCString & operator=(const char *str)
replaces the contents by that of C string str.
Definition: qcstring.h:136
uint length() const
Returns the length of the string, not counting the 0-terminator.
Definition: qcstring.h:147
Various UTF8 related helper functions.
QCString(const char *str)
creates a string from a plain C string.
Definition: qcstring.h:130
QCString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple whitespace cha...
Definition: qcstring.cpp:185
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition: qcstring.h:243
bool truncate(size_t pos)
Truncates the string at position pos.
Definition: qcstring.h:167
char & at(size_t i)
Returns a reference to the character at index i.
Definition: qcstring.h:503
std::string convertUTF8ToLower(const std::string &input)
Converts the input string into a lower case version, also taking into account non-ASCII characters th...
Definition: utf8.cpp:187
char * rawData()
Returns a writable pointer to the data.
Definition: qcstring.h:157
bool resize(size_t newlen)
Resizes the string to hold newlen characters (this value should also count the 0-terminator).
Definition: qcstring.h:164
bool isNull() const
Returns TRUE iff the string is empty.
Definition: qcstring.h:141
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition: qcstring.h:153
char & operator[](int i)
Indexing operator.
Definition: qcstring.h:514
QCString & operator+=(const char *s)
Appends string str to this string and returns a reference to the result.
Definition: qcstring.h:486
QCString(size_t size)
creates a string with room for size characters
Definition: qcstring.h:125
std::string convertUTF8ToUpper(const std::string &input)
Converts the input string into a upper case version, also taking into account non-ASCII characters th...
Definition: utf8.cpp:192
bool fill(char c, int len=-1)
Fills a string with a predefined character.
Definition: qcstring.h:175
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition: qcstring.h:144
This is an alternative implementation of QCString.
Definition: qcstring.h:108
QCString(const char *str, size_t maxlen)
creates a string from str and copies over the first maxlen characters.
Definition: qcstring.h:133