26 return c>=
'A' && c<=
'Z' ? c|0x20 : c;
32 va_start( ap, format );
33 const size_t minlen=256;
35 if (l<minlen) {
resize(minlen+1); l=minlen; }
36 int n=vsnprintf(
rawData(), l+1, format, ap);
37 if (n<0) n=
static_cast<int>(l);
45 if (index<0 || index>=
static_cast<int>(
length()))
return -1;
46 const char *pos =
nullptr;
49 pos = strchr(
data()+index,c);
56 if (!*pos && c) pos=
nullptr;
58 return pos ?
static_cast<int>(pos -
data()) : -1;
63 int l =
static_cast<int>(
length());
64 if (index<0 || index>=l)
return -1;
66 if (!*
str)
return index;
67 const char *pos =
nullptr;
81 if (!*pos) pos =
nullptr;
83 return pos ?
static_cast<int>(pos -
data()) : -1;
88 return find(
str.data(),index,cs);
93 const char *b =
data();
94 const char *pos =
nullptr;
95 int len =
static_cast<int>(
length());
96 if (len==0)
return -1;
102 return pos ?
static_cast<int>(pos - b) : -1;
113 while ( pos>=b && *pos!=c) pos--;
120 return pos>=b ?
static_cast<int>(pos - b) : -1;
126 int len =
static_cast<int>(
length());
127 if (index<0) index = len-slen;
128 else if (index>len)
return -1;
129 else if (index+slen>len) index=len-slen;
130 if (index<0)
return -1;
131 const char *pos =
data()+index;
134 for (
int i=index; i>=0; i--)
if (
qstrncmp(pos--,
str,slen)==0)
return i;
138 for (
int i=index; i>=0; i--)
if (
qstrnicmp(pos,
str,slen)==0)
return i;
145 if (
length()==0)
return 0;
147 const char *pos =
data();
150 while (*pos)
if (*pos++ == c) count++;
166 if (
str==
nullptr ||
length()==0)
return 0;
168 const char *pos =
data();
191 const char *from =
data();
205 if ( to > first && *(to-1) == 0x20 )
208 result.
resize(
static_cast<int>(to - result.
data()) );
222 return c>=
'0' && c<=
'9' && (c-
'0') < base;
224 return (c>=
'0' && c<=
'9') ||
225 (c >=
'a' && c < char(
'a'+base-10)) ||
226 (c >=
'A' && c <
char(
'A'+base-10));
231 long v =
toLong( ok, base );
232 if ( ok && *ok && (v < -32768 || v > 32767) ) {
236 return static_cast<short>(v);
241 unsigned long v =
toULong( ok, base );
242 if ( ok && *ok && (v > 65535) ) {
246 return static_cast<uint16_t
>(v);
251 return static_cast<int>(
toLong( ok, base ));
256 return static_cast<uint32_t
>(
toULong( ok, base ));
262 const char *p =
data();
264 int l =
static_cast<int>(
length());
265 const long max_mult = INT_MAX / base;
272 if ( l && *p ==
'-' ) {
276 }
else if ( *p ==
'+' ) {
287 if ( *p>=
'0' && *p<=
'9' ) {
290 if ( *p >=
'a' && *p <=
'z' )
295 if ( val > max_mult || (val == max_mult && dv > (INT_MAX%base)+neg) )
309 return is_ok ? val : 0;
314 const char *p =
data();
316 int l =
static_cast<int>(
length());
317 const unsigned long max_mult = 429496729;
332 if ( *p>=
'0' && *p<=
'9' ) {
335 if ( *p >=
'a' && *p <=
'z' )
340 if ( val > max_mult || (val == max_mult && dv > (UINT_MAX%base)) )
353 return is_ok ? val : 0;
358 const char *p =
data();
360 int l =
static_cast<int>(
length());
361 const uint64_t max_mult = 1844674407370955161ULL;
376 if ( *p>=
'0' && *p<=
'9' ) {
379 if ( *p >=
'a' && *p <=
'z' )
384 if ( val > max_mult || (val == max_mult && dv > (ULLONG_MAX%base)) )
397 return is_ok ? val : 0;
402void *
qmemmove(
void *dst,
const void *src,
size_t len )
405 char *d =
static_cast<char *
>(dst) + len - 1;
406 const char *s =
static_cast<const char *
>(src) + len - 1;
410 else if ( dst < src ) {
411 char *d =
static_cast<char *
>(dst);
412 const char *s =
static_cast<const char *
>(src);
423 char *dst =
new char[
qstrlen(str)+1];
424 return strcpy( dst, str );
432char *
qstrncpy(
char *dst,
const char *src,
size_t len )
436 strncpy( dst, src, len );
446 return s1 == s2 ? 0 :
static_cast<int>(s2 - s1);
458int qstrnicmp(
const char *s1,
const char *s2,
size_t len )
462 return static_cast<int>(s2 - s1);
464 for ( ; len--; s1++, s2++ )
480 const char *q =
nullptr, *p =
nullptr;
481 size_t srcLen = src.
length();
482 size_t dstLen = dst.
length();
487 for (p = s.
data(); (q=strstr(p,src.
data()))!=
nullptr; p=q+srcLen) count++;
488 resLen = s.
length()+count*(dstLen-srcLen);
496 for (p = s.
data(); (q=strstr(p,src.
data()))!=
nullptr; p=q+srcLen)
498 int l =
static_cast<int>(q-p);
502 if (dstLen>0) memcpy(r,dst.
data(),dstLen);
521 const char *p =
nullptr, *q =
nullptr;
522 size_t srcLen = src.
length();
523 size_t dstLen = dst.
length();
528 for (p=s.
data(); (q=strstr(p,src.
data()))!=
nullptr; p=q+srcLen) count++;
529 resLen = s.
length()+count*(dstLen-srcLen);
537 for (p = s.
data(); (q=strstr(p,src.
data()))!=
nullptr; p=q+srcLen)
540 int seq = 0, skip = 0;
543 for (
const char *n=q+srcLen;
qstrncmp(n,src.
data(),srcLen)==0; seq=1+skip, n+=srcLen)
547 if (skip_seq > 0 && skip_seq != seq)
552 int l =
static_cast<int>((q + seq * srcLen)-p);
564 if (dstLen>0) memcpy(r,dst.
data(),dstLen);
576 const std::string &s =
m_rep;
577 int end=
static_cast<int>(s.length());
583 while ((c=s[p]) && (c==
' ' || c==
'\t')) p++;
595 if (p>=start && s.at(p)==
'\n') p--;
599 while ((c=s[p]) && (c==
' ' || c==
'\t')) p--;
611 return s.substr(start,
end-start);
This is an alternative implementation of QCString.
int find(char c, int index=0, bool cs=TRUE) const
int toInt(bool *ok=nullptr, int base=10) const
size_t length() const
Returns the length of the string, not counting the 0-terminator.
uint64_t toUInt64(bool *ok=nullptr, int base=10) 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 stripLeadingAndTrailingEmptyLines() const
QCString & remove(size_t index, size_t len)
void resize(size_t newlen)
const std::string & str() const
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 & sprintf(const char *format,...)
long toLong(bool *ok=nullptr, int base=10) const
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)
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
QCString & insert(size_t index, const QCString &s)
int contains(char c, bool cs=TRUE) const
short toShort(bool *ok=nullptr, int base=10) const
DirIterator end(const DirIterator &) noexcept
char * qstrdup(const char *str)
Returns a copy of a string s.
char * qstrncpy(char *dst, const char *src, size_t len)
static bool ok_in_base(char c, int base)
int qstricmp(const char *s1, const char *s2)
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
void qstrfree(const char *str)
Frees the memory allocated using qstrdup().
void * qmemmove(void *dst, const void *src, size_t len)
int qstrnicmp(const char *s1, const char *s2, size_t len)
int qstrncmp(const char *str1, const char *str2, size_t len)
int qstrnicmp(const char *str1, const char *str2, size_t len)
uint32_t qstrlen(const char *str)
Returns the length of string str, or 0 if a null pointer is passed.
char * qstrcpy(char *dst, const char *src)