Doxygen
Loading...
Searching...
No Matches
qcstring.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 1997-2015 by Dimitri van Heesch.
4**
5** Permission to use, copy, modify, and distribute this software and its
6** documentation under the terms of the GNU General Public License is hereby
7** granted. No representations are made about the suitability of this software
8** for any purpose. It is provided "as is" without express or implied warranty.
9** See the GNU General Public License for more details.
10**
11** Note: this is a reimplementation of the qcstring.h that came with
12** an Qt version 2.2.3. For short strings it stores the string data inside
13** the object. For long strings it uses a separate array with reference counting.
14**
15**********************************************************************/
16
17#ifndef QCSTRING_H
18#define QCSTRING_H
19
20#include <string>
21#include <string_view>
22#include <algorithm>
23
24#include <cctype>
25#include <cstring>
26#include <cstdio>
27#include <cstdlib>
28#include <cstdint>
29#include <ostream>
30
31#include "utf8.h"
32
33#ifndef FALSE
34#define FALSE false
35#endif
36#ifndef TRUE
37#define TRUE true
38#endif
39#define ASSERT(x) if ( !(x) )\
40 fprintf(stderr,"ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__)
41
42
43/*****************************************************************************
44 Safe and portable C string functions; extensions to standard string.h
45 *****************************************************************************/
46
47void *qmemmove( void *dst, const void *src, size_t len );
48
49#define qsnprintf snprintf
50
51//! Returns a copy of a string \a s.
52//! Note that memory is passed to the caller, use qstrfree() to release.
53char *qstrdup( const char *s );
54//! Frees the memory allocated using qstrdup().
55void qstrfree( const char *s );
56
57//! Returns the length of string \a str, or 0 if a null pointer is passed.
58inline uint32_t qstrlen( const char *str )
59{ return str ? static_cast<uint32_t>(strlen(str)) : 0; }
60
61inline char *qstrcpy( char *dst, const char *src )
62{ return src ? strcpy(dst, src) : nullptr; }
63
64char *qstrncpy(char *dst,const char *src, size_t len);
65
66inline bool qisempty( const char *s)
67{ return s==nullptr || *s=='\0'; }
68
69inline int qstrcmp( const char *str1, const char *str2 )
70{ return (str1 && str2) ? strcmp(str1,str2) : // both non-empty
71 (qisempty(str1) && qisempty(str2)) ? 0 : // both empty
72 qisempty(str1) ? -1 : 1; // one empty, other non-empty
73}
74
75inline int qstrncmp( const char *str1, const char *str2, size_t len )
76{ return (str1 && str2) ? strncmp(str1,str2,len) : // both non-empty
77 (qisempty(str1) && qisempty(str2)) ? 0 : // both empty
78 qisempty(str1) ? -1 : 1; // one empty other non-empty
79}
80
81inline bool qisspace(char c)
82{ return c==' ' || c=='\t' || c=='\n' || c=='\r'; }
83
84int qstricmp( const char *str1, const char *str2 );
85
86inline int qstricmp_sort( const char *str1, const char *str2 )
87{
88 int result = qstricmp(str1,str2);
89 return result==0 ? qstrcmp(str1,str2) : result;
90}
91
92
93int qstrnicmp( const char *str1, const char *str2, size_t len );
94
95using JavaCCString = std::basic_string<JAVACC_CHAR_TYPE>;
96
97/** This is an alternative implementation of QCString. It provides basically
98 * the same functions but uses std::string as the underlying string type
99 */
101{
102 public:
103 QCString() = default;
104 explicit QCString( const std::string &s ) : m_rep(s) {}
105
106 QCString( std::string &&s) : m_rep(std::move(s)) {}
107
108 QCString( std::string_view sv) : m_rep(sv) {}
109
110 QCString &operator=(std::string_view sv) {
111 m_rep=sv;
112 return *this;
113 }
114
115 QCString( int ) = delete;
116
117 /** For converting a JavaCC string */
119 {
120 m_rep.resize(s.size());
121 memcpy(m_rep.data(),s.data(),s.size());
122 }
124 {
125 m_rep.resize(s.size());
126 memcpy(m_rep.data(),s.data(),s.size());
127 return *this;
128 }
129
130 /** creates a string with room for size characters
131 * @param[in] size the number of character to allocate (also counting the 0-terminator!)
132 */
134 explicit QCString( size_t size, SizeTag t) { m_rep.resize(size); }
135
136 /** creates a string from a plain C string.
137 * @param[in] str A zero terminated C string. When 0 an empty string is created.
138 */
139 QCString( const char *str ) : m_rep(str?str:"") {}
140
141 /** creates a string from \a str and copies over the first \a maxlen characters. */
142 QCString( const char *str, size_t maxlen ) : m_rep(str?str:"") { m_rep.resize(maxlen); }
143
144 /** replaces the contents by that of C string \a str. */
145 QCString &operator=( const char *str) { m_rep = str?str:""; return *this; }
146
147 QCString &operator=( const std::string &s) { m_rep = s; return *this; }
148
149 /** Returns TRUE iff the string is empty */
150 bool isEmpty() const { return m_rep.empty(); }
151
152 /** Returns the length of the string, not counting the 0-terminator. Equivalent to size(). */
153 size_t length() const { return m_rep.size(); }
154
155 /** Returns the length of the string, not counting the 0-terminator. */
156 size_t size() const { return m_rep.size(); }
157
158 /** Returns a pointer to the contents of the string in the form of a 0-terminated C string */
159 const char *data() const { return m_rep.c_str(); }
160
161 std::string_view view() const { return m_rep; }
162
163 /** Returns a writable pointer to the data.
164 */
165 char *rawData() { return &m_rep[0]; }
166
167 void resize( size_t newlen) { m_rep.resize(newlen); }
168
169 void clear() { m_rep.clear(); }
170
171 /** Reserve space for \a size bytes without changing the string contents */
172 void reserve( size_t size ) { m_rep.reserve(size); }
173
174 /** Fills a string with a predefined character
175 * @param[in] c the character used to fill the string with.
176 * @param[in] len the number of character to fill. Use -1 to fill the whole string.
177 * @note the string will be resized to contain \a len characters. The contents of the
178 * string will be lost.
179 */
180 void fill( char c, int len = -1 )
181 {
182 int l = len==-1 ? static_cast<int>(m_rep.size()) : len;
183 m_rep = std::string(l,c);
184 }
185
186 QCString &sprintf( const char *format, ... );
187
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;
190 int find( const QCString &str, int index=0, bool cs=TRUE ) const;
191
192 int findRev( char c, int index=-1, bool cs=TRUE) const;
193 int findRev( const char *str, int index=-1, bool cs=TRUE) const;
194
195 int contains( char c, bool cs=TRUE ) const;
196 int contains( const char *str, bool cs=TRUE ) const;
197
199 {
200 if (prefix.isEmpty() || m_rep.empty()) return FALSE;
201 if (m_rep.rfind(prefix.data(),0)==0) // string starts with prefix
202 {
203 m_rep.erase(0,prefix.length());
204 return TRUE;
205 }
206 return FALSE;
207 }
208
209 bool stripPrefix(const char *prefix)
210 {
211 return stripPrefix(QCString(prefix));
212 }
213
214 QCString left( size_t len ) const
215 {
216 return m_rep.empty() ? QCString() : QCString(m_rep.substr(0,len));
217 }
218
219 QCString right( size_t len ) const
220 {
221 return m_rep.empty() ? QCString() :
222 len<m_rep.size() ? QCString(m_rep.substr(m_rep.size()-len,len)) :
223 *this;
224 }
225
226 QCString mid( size_t index, size_t len=static_cast<size_t>(-1) ) const
227 {
228 size_t slen = m_rep.size();
229 if (len==static_cast<uint32_t>(-1)) len = slen-index;
230 return m_rep.empty() || index>slen || len==0 ? QCString() :
231 QCString(m_rep.substr(index,len));
232 }
233
235 {
237 }
238
240 {
242 }
243
244 /// returns a copy of this string with leading and trailing whitespace removed
246 {
247 size_t sl = m_rep.size();
248 if (sl==0 || (!qisspace(m_rep[0]) && !qisspace(m_rep[sl-1]))) return *this;
249 size_t start=0,end=sl-1;
250 while (start<sl && qisspace(m_rep[start])) start++;
251 if (start==sl) return QCString(); // only whitespace
252 while (end>start && qisspace(m_rep[end])) end--;
253 return QCString(m_rep.substr(start,1+end-start));
254 }
255
257
258 // Returns a quoted copy of this string, unless it is already quoted.
259 // Note that trailing and leading whitespace is removed.
261 {
262 size_t start=0, sl=m_rep.size(), end=sl-1;
263 while (start<sl && qisspace(m_rep[start])) start++; // skip over leading whitespace
264 if (start==sl) return QCString(); // only whitespace
265 while (end>start && qisspace(m_rep[end])) end--; // skip over trailing whitespace
266 bool needsQuotes=false;
267 size_t i=start;
268 if (i<end && m_rep[i]!='"') // stripped string has at least non-whitespace unquoted character
269 {
270 while (i<end && !needsQuotes) // check if the to be quoted part has at least one whitespace character
271 {
272 needsQuotes = m_rep[i] =='-';
273 needsQuotes |= qisspace(m_rep[i++]);
274 }
275 }
276 QCString result(m_rep.substr(start,1+end-start));
277 if (needsQuotes)
278 {
279 result.prepend("\"");
280 result.append("\"");
281 }
282 return result;
283 }
284
285 /// returns a copy of this string with all whitespace removed
287 {
288 size_t sl = m_rep.size();
289 if (sl==0) return *this;
290 std::string result = m_rep;
291 size_t src=0,dst=0;
292 while (src<sl)
293 {
294 if (!qisspace(m_rep[src])) result[dst++]=m_rep[src];
295 src++;
296 }
297 if (dst<m_rep.size()) result.resize(dst);
298 return QCString(result);
299 }
300
301 /// return a copy of this string with leading and trailing whitespace removed and multiple
302 /// whitespace characters replaced by a single space
304
305 // Returns a copy of this string repeated n times
306 QCString repeat(unsigned int n) const
307 {
308 QCString result(n * size(), ExplicitSize);
309 size_t offset = 0;
310 for (offset = 0; offset < n * size(); offset += size())
311 {
312 memcpy(result.rawData() + offset, data(), size());
313 }
314 return result;
315 }
316
317 QCString &insert( size_t index, const QCString &s )
318 {
319 if (s.length()>0)
320 {
321 size_t ol = m_rep.size();
322 if (index>ol) // insert beyond end of string and fill gap with spaces
323 {
324 m_rep.resize(index+s.length());
325 std::memset(&m_rep[ol],' ',index-ol);
326 std::memcpy(&m_rep[index],s.data(),s.length()+1);
327 }
328 else // insert inside the string
329 {
330 m_rep.insert(index,s.str());
331 }
332 }
333 return *this;
334 }
335
336 QCString &insert( size_t index, std::string_view s)
337 {
338 if (s.length()>0)
339 {
340 size_t ol = m_rep.size();
341 if (index>ol) // insert beyond end of string and fill gap with spaces
342 {
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);
346 }
347 else // insert inside the string
348 {
349 m_rep.insert(index,s);
350 }
351 }
352 return *this;
353 }
354
355 QCString &insert( size_t index, const char *s )
356 {
357 size_t len = s ? qstrlen(s) : 0;
358 if (len>0)
359 {
360 size_t ol = m_rep.size();
361 if (index>ol) // insert beyond end of string and fill gap with spaces
362 {
363 m_rep.resize(index+len);
364 std::memset(&m_rep[ol],' ',index-ol);
365 std::memcpy(&m_rep[index],s,len+1);
366 }
367 else // insert inside the string
368 {
369 m_rep.insert(index,s);
370 }
371 }
372 return *this;
373 }
374
375 QCString &insert( size_t index, char c)
376 {
377 char s[2] = { c, '\0' };
378 return insert(index,s);
379 }
380
381 QCString &append( char c)
382 {
383 m_rep+=c;
384 return *this;
385 }
386
387 QCString &append( const char *s )
388 {
389 return operator+=(s);
390 }
391
393 {
394 return operator+=(s);
395 }
396
397 QCString &append( const std::string &s )
398 {
399 return operator+=(s);
400 }
401
402 QCString &append( std::string_view s)
403 {
404 return operator+=(s);
405 }
406
407 QCString &prepend( const char *s )
408 {
409 return insert(0,s);
410 }
411
413 {
414 return insert(0,s.data());
415 }
416
417 QCString &prepend( const std::string &s )
418 {
419 return insert(0,s.c_str());
420 }
421
422 QCString &prepend( std::string_view s)
423 {
424 return insert(0,s);
425 }
426
427 QCString &remove( size_t index, size_t len )
428 {
429 size_t ol = m_rep.size();
430 if (index<ol && len>0) m_rep.erase(index,index+len>=ol ? std::string::npos : len);
431 return *this;
432 }
433
434 QCString &replace( size_t index, size_t len, const char *s);
435
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;
443
444 QCString &setNum(short n)
445 {
446 m_rep = std::to_string(n);
447 return *this;
448 }
449
450 QCString &setNum(uint16_t n)
451 {
452 m_rep = std::to_string(n);
453 return *this;
454 }
455
457 {
458 m_rep = std::to_string(n);
459 return *this;
460 }
461
462 QCString &setNum(uint32_t n)
463 {
464 m_rep = std::to_string(n);
465 return *this;
466 }
467
469 {
470 m_rep = std::to_string(n);
471 return *this;
472 }
473
474 QCString &setNum(long long n)
475 {
476 m_rep = std::to_string(n);
477 return *this;
478 }
479
480 QCString &setNum(unsigned long long n)
481 {
482 m_rep = std::to_string(n);
483 return *this;
484 }
485
486 QCString &setNum(unsigned long n)
487 {
488 m_rep = std::to_string(n);
489 return *this;
490 }
491
492 bool startsWith( const char *s ) const
493 {
494 if (m_rep.empty() || s==nullptr) return s==nullptr;
495 return m_rep.rfind(s,0)==0; // looking "backward" starting and ending at index 0
496 }
497
498 bool startsWith( const QCString &s ) const
499 {
500 if (m_rep.empty() || s.isEmpty()) return s.isEmpty();
501 return m_rep.rfind(s.str(),0)==0; // looking "backward" starting and ending at index 0
502 }
503
504 bool endsWith(const char *s) const
505 {
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;
509 }
510
511 bool endsWith(const QCString &s) const
512 {
513 size_t l = s.length();
514 return m_rep.length()>=l && m_rep.compare(m_rep.length()-l, l, s.str())==0;
515 }
516
517#define HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING 0
518#if HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING
519 /** Converts the string to a plain C string */
520 operator const char *() const
521 {
522 return data();
523 }
524#endif
525
526 const std::string &str() const
527 {
528 return m_rep;
529 }
530
532 {
533 m_rep+=s.str();
534 return *this;
535 }
536
537 QCString &operator+=( const std::string &s)
538 {
539 m_rep+=s;
540 return *this;
541 }
542
543 QCString &operator+=(std::string_view s)
544 {
545 m_rep+=s;
546 return *this;
547 }
548
549 /** Appends string \a str to this string and returns a reference to the result. */
550 QCString &operator+=( const char *s )
551 {
552 if (s) m_rep+=s;
553 return *this;
554 }
555
556#define HAS_CHARACTER_APPEND_OPERATOR 1
557#if HAS_CHARACTER_APPEND_OPERATOR
558 /** Appends character \a c to this string and returns a reference to the result. */
559 QCString &operator+=( char c )
560 {
561 m_rep+=c;
562 return *this;
563 }
564#endif
565
566 /** Returns a reference to the character at index \a i. */
567 char &at( size_t i)
568 {
569 return m_rep[i];
570 }
571
572 const char &at( size_t i) const
573 {
574 return m_rep[i];
575 }
576
577 /** Indexing operator. Equivalent to at(). */
578 char &operator[]( size_t i )
579 {
580 return m_rep[i];
581 }
582
583 const char &operator[]( size_t i ) const
584 {
585 return m_rep[i];
586 }
587
588 private:
589 std::string m_rep;
590};
591
592/*****************************************************************************
593 QCString non-member operators
594 *****************************************************************************/
595
596inline bool operator==( const QCString &s1, const QCString &s2 )
597{ return s1.str() == s2.str(); }
598
599inline bool operator==( const QCString &s1, const char *s2 )
600{ return qstrcmp(s1.data(),s2) == 0; }
601
602inline bool operator==( const char *s1, const QCString &s2 )
603{ return qstrcmp(s1,s2.data()) == 0; }
604
605inline bool operator!=( const QCString &s1, const QCString &s2 )
606{ return s1.str() != s2.str(); }
607
608inline bool operator!=( const QCString &s1, const char *s2 )
609{ return qstrcmp(s1.data(),s2) != 0; }
610
611inline bool operator!=( const char *s1, const QCString &s2 )
612{ return qstrcmp(s1,s2.data()) != 0; }
613
614inline bool operator<( const QCString &s1, const QCString& s2 )
615{ return qstrcmp(s1.data(),s2.data()) < 0; }
616
617inline bool operator<( const QCString &s1, const char *s2 )
618{ return qstrcmp(s1.data(),s2) < 0; }
619
620inline bool operator<( const char *s1, const QCString &s2 )
621{ return qstrcmp(s1,s2.data()) < 0; }
622
623inline bool operator<=( const QCString &s1, const char *s2 )
624{ return qstrcmp(s1.data(),s2) <= 0; }
625
626inline bool operator<=( const char *s1, const QCString &s2 )
627{ return qstrcmp(s1,s2.data()) <= 0; }
628
629inline bool operator>( const QCString &s1, const char *s2 )
630{ return qstrcmp(s1.data(),s2) > 0; }
631
632inline bool operator>( const char *s1, const QCString &s2 )
633{ return qstrcmp(s1,s2.data()) > 0; }
634
635inline bool operator>=( const QCString &s1, const char *s2 )
636{ return qstrcmp(s1.data(),s2) >= 0; }
637
638inline bool operator>=( const char *s1, const QCString &s2 )
639{ return qstrcmp(s1,s2.data()) >= 0; }
640
641inline QCString operator+( const QCString &s1, const QCString &s2 )
642{
643 return QCString(s1.str()+s2.str());
644}
645
646
647inline QCString operator+( const QCString &s1, const char *s2 )
648{
649 QCString tmp(s1);
650 tmp.append(s2);
651 return tmp;
652}
653
654inline QCString operator+( const char *s1, const QCString &s2 )
655{
656 QCString tmp(s1);
657 tmp.append(s2);
658 return tmp;
659}
660
661inline const char *qPrint(const char *s)
662{
663 if (s) return s; else return "";
664}
665
666inline const char *qPrint(const QCString &s)
667{
668 if (!s.isEmpty()) return s.data(); else return "";
669}
670
671inline const char *qPrint(const std::string &s)
672{
673 return s.c_str();
674}
675
676inline std::string toStdString(const QCString &s)
677{
678 return s.str();
679}
680
681//---- overloads
682
683inline int qstrcmp( const QCString &str1, const char *str2 )
684{
685 return qstrcmp(str1.data(),str2);
686}
687
688inline int qstrcmp( const char *str1, const QCString &str2 )
689{
690 return qstrcmp(str1,str2.data());
691}
692
693inline int qstrcmp( const QCString &str1, const QCString &str2 )
694{
695 return qstrcmp(str1.data(),str2.data());
696}
697
698inline int qstricmp( const QCString &str1, const char *str2 )
699{
700 return qstricmp(str1.data(),str2);
701}
702
703inline int qstricmp( const char *str1, const QCString &str2 )
704{
705 return qstricmp(str1,str2.data());
706}
707
708inline int qstricmp( const QCString &str1, const QCString &str2 )
709{
710 return qstricmp(str1.data(),str2.data());
711}
712
713inline int qstricmp_sort( const QCString &str1, const char *str2 )
714{
715 return qstricmp_sort(str1.data(),str2);
716}
717
718inline int qstricmp_sort( const char *str1, const QCString &str2 )
719{
720 return qstricmp_sort(str1,str2.data());
721}
722
723inline int qstricmp_sort( const QCString &str1, const QCString &str2 )
724{
725 return qstricmp_sort(str1.data(),str2.data());
726}
727
728
729inline int qstrnicmp( const QCString &str1, const char *str2, size_t len )
730{
731 return qstrnicmp(str1.data(),str2,len);
732}
733
734inline int qstrnicmp( const char *str1, const QCString &str2, size_t len )
735{
736 return qstrnicmp(str1,str2.data(),len);
737}
738
739inline int qstrnicmp( const QCString &str1, const QCString &str2, size_t len )
740{
741 return qstrnicmp(str1.data(),str2.data(),len);
742}
743
744// helper functions
745QCString substitute(const QCString &str,const QCString &find,const QCString &replace);
746inline QCString substitute(const QCString &str,const char *find,const char *replace)
747{
748 return substitute(str,QCString(find),QCString(replace));
749}
750QCString substitute(const QCString &s,const QCString &src,const QCString &dst,int skip_seq);
751
752inline QCString substitute(const QCString &s,char srcChar,char dstChar)
753{
754 std::string ss = s.str();
755 std::replace(ss.begin(),ss.end(),srcChar,dstChar);
756 return QCString(ss);
757}
758
759inline std::ostream& operator<<(std::ostream& os, const QCString& s)
760{
761 os << s.str();
762 return os;
763}
764
765#endif // QCSTRING_H
constexpr auto prefix
Definition anchor.cpp:44
This is an alternative implementation of QCString.
Definition qcstring.h:101
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
void fill(char c, int len=-1)
Fills a string with a predefined character.
Definition qcstring.h:180
QCString & prepend(const char *s)
Definition qcstring.h:407
QCString & insert(size_t index, const char *s)
Definition qcstring.h:355
QCString(std::string_view sv)
Definition qcstring.h:108
int toInt(bool *ok=nullptr, int base=10) const
Definition qcstring.cpp:249
QCString upper() const
Definition qcstring.h:239
QCString & setNum(uint32_t n)
Definition qcstring.h:462
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
QCString & operator=(std::string_view sv)
Definition qcstring.h:110
bool startsWith(const char *s) const
Definition qcstring.h:492
QCString(const char *str)
creates a string from a plain C string.
Definition qcstring.h:139
QCString(const JavaCCString &s)
For converting a JavaCC string.
Definition qcstring.h:118
QCString & setNum(long n)
Definition qcstring.h:468
QCString & setNum(uint16_t n)
Definition qcstring.h:450
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
QCString & operator=(const JavaCCString &s)
Definition qcstring.h:123
QCString & append(const char *s)
Definition qcstring.h:387
bool endsWith(const QCString &s) const
Definition qcstring.h:511
QCString lower() const
Definition qcstring.h:234
bool stripPrefix(const char *prefix)
Definition qcstring.h:209
QCString & operator+=(const std::string &s)
Definition qcstring.h:537
QCString & operator+=(const QCString &s)
Definition qcstring.h:531
bool endsWith(const char *s) const
Definition qcstring.h:504
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:567
QCString & append(const QCString &s)
Definition qcstring.h:392
uint64_t toUInt64(bool *ok=nullptr, int base=10) const
Definition qcstring.cpp:356
QCString & operator=(const std::string &s)
Definition qcstring.h:147
const char & operator[](size_t i) const
Definition qcstring.h:583
unsigned long toULong(bool *ok=nullptr, int base=10) const
Definition qcstring.cpp:312
char * rawData()
Returns a writable pointer to the data.
Definition qcstring.h:165
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
QCString & operator+=(std::string_view s)
Definition qcstring.h:543
QCString stripLeadingAndTrailingEmptyLines() const
Definition qcstring.cpp:573
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:245
QCString & remove(size_t index, size_t len)
Definition qcstring.h:427
QCString repeat(unsigned int n) const
Definition qcstring.h:306
QCString & append(std::string_view s)
Definition qcstring.h:402
QCString(std::string &&s)
Definition qcstring.h:106
void resize(size_t newlen)
Definition qcstring.h:167
QCString & append(const std::string &s)
Definition qcstring.h:397
std::string m_rep
Definition qcstring.h:589
QCString & prepend(const std::string &s)
Definition qcstring.h:417
QCString & prepend(std::string_view s)
Definition qcstring.h:422
QCString & operator+=(const char *s)
Appends string str to this string and returns a reference to the result.
Definition qcstring.h:550
bool startsWith(const QCString &s) const
Definition qcstring.h:498
QCString(int)=delete
const std::string & str() const
Definition qcstring.h:526
QCString & setNum(short n)
Definition qcstring.h:444
uint16_t toUShort(bool *ok=nullptr, int base=10) const
Definition qcstring.cpp:239
QCString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple whitespace cha...
Definition qcstring.cpp:185
QCString & append(char c)
Definition qcstring.h:381
QCString right(size_t len) const
Definition qcstring.h:219
QCString & setNum(unsigned long long n)
Definition qcstring.h:480
size_t size() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:156
QCString & setNum(long long n)
Definition qcstring.h:474
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
Definition qcstring.h:172
QCString & setNum(int n)
Definition qcstring.h:456
QCString & setNum(unsigned long n)
Definition qcstring.h:486
char & operator[](size_t i)
Indexing operator.
Definition qcstring.h:578
QCString & sprintf(const char *format,...)
Definition qcstring.cpp:29
long toLong(bool *ok=nullptr, int base=10) const
Definition qcstring.cpp:260
SizeTag
creates a string with room for size characters
Definition qcstring.h:133
@ ExplicitSize
Definition qcstring.h:133
uint32_t toUInt(bool *ok=nullptr, int base=10) const
Definition qcstring.cpp:254
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:91
QCString & replace(size_t index, size_t len, const char *s)
Definition qcstring.cpp:212
QCString(const char *str, size_t maxlen)
creates a string from str and copies over the first maxlen characters.
Definition qcstring.h:142
QCString & insert(size_t index, char c)
Definition qcstring.h:375
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:159
std::string_view view() const
Definition qcstring.h:161
const char & at(size_t i) const
Definition qcstring.h:572
QCString(size_t size, SizeTag t)
Definition qcstring.h:134
QCString & prepend(const QCString &s)
Definition qcstring.h:412
QCString()=default
QCString & insert(size_t index, const QCString &s)
Definition qcstring.h:317
QCString removeWhiteSpace() const
returns a copy of this string with all whitespace removed
Definition qcstring.h:286
QCString left(size_t len) const
Definition qcstring.h:214
int contains(char c, bool cs=TRUE) const
Definition qcstring.cpp:143
bool stripPrefix(const QCString &prefix)
Definition qcstring.h:198
QCString quoted() const
Definition qcstring.h:260
void clear()
Definition qcstring.h:169
QCString(const std::string &s)
Definition qcstring.h:104
QCString & operator=(const char *str)
replaces the contents by that of C string str.
Definition qcstring.h:145
QCString & insert(size_t index, std::string_view s)
Definition qcstring.h:336
short toShort(bool *ok=nullptr, int base=10) const
Definition qcstring.cpp:229
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
int qstricmp_sort(const char *str1, const char *str2)
Definition qcstring.h:86
char * qstrncpy(char *dst, const char *src, size_t len)
Definition qcstring.cpp:432
int qstrncmp(const char *str1, const char *str2, size_t len)
Definition qcstring.h:75
bool operator>(const QCString &s1, const char *s2)
Definition qcstring.h:629
bool operator>=(const QCString &s1, const char *s2)
Definition qcstring.h:635
int qstricmp(const char *str1, const char *str2)
Definition qcstring.cpp:442
std::ostream & operator<<(std::ostream &os, const QCString &s)
Definition qcstring.h:759
QCString substitute(const QCString &str, const QCString &find, const QCString &replace)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
bool qisspace(char c)
Definition qcstring.h:81
int qstrnicmp(const char *str1, const char *str2, size_t len)
Definition qcstring.cpp:458
const char * qPrint(const char *s)
Definition qcstring.h:661
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
bool operator<=(const QCString &s1, const char *s2)
Definition qcstring.h:623
uint32_t qstrlen(const char *str)
Returns the length of string str, or 0 if a null pointer is passed.
Definition qcstring.h:58
void qstrfree(const char *s)
Frees the memory allocated using qstrdup().
Definition qcstring.cpp:427
char * qstrcpy(char *dst, const char *src)
Definition qcstring.h:61
std::string toStdString(const QCString &s)
Definition qcstring.h:676
bool qisempty(const char *s)
Definition qcstring.h:66
int qstrcmp(const char *str1, const char *str2)
Definition qcstring.h:69
bool operator==(const QCString &s1, const QCString &s2)
Definition qcstring.h:596
QCString operator+(const QCString &s1, const QCString &s2)
Definition qcstring.h:641
void * qmemmove(void *dst, const void *src, size_t len)
Definition qcstring.cpp:402
bool operator<(const QCString &s1, const QCString &s2)
Definition qcstring.h:614
bool operator!=(const QCString &s1, const QCString &s2)
Definition qcstring.h:605
std::basic_string< JAVACC_CHAR_TYPE > JavaCCString
Definition qcstring.h:95
char * qstrdup(const char *s)
Returns a copy of a string s.
Definition qcstring.cpp:419
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
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
Various UTF8 related helper functions.