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 std::string &s) const
499 {
500 return m_rep.rfind(s,0)==0; // looking "backward" starting and ending at index 0
501 }
502
503 bool startsWith( const QCString &s ) const
504 {
505 if (m_rep.empty() || s.isEmpty()) return s.isEmpty();
506 return m_rep.rfind(s.str(),0)==0; // looking "backward" starting and ending at index 0
507 }
508
509 bool endsWith(const char *s) const
510 {
511 if (m_rep.empty() || s==nullptr) return s==nullptr;
512 size_t l = strlen(s);
513 return m_rep.length()>=l && m_rep.compare(m_rep.length()-l, l, s, l)==0;
514 }
515
516 bool endsWith(const std::string &s) const
517 {
518 size_t l = s.length();
519 return m_rep.length()>=l && m_rep.compare(m_rep.length()-l, l, s)==0;
520 }
521
522 bool endsWith(const QCString &s) const
523 {
524 size_t l = s.length();
525 return m_rep.length()>=l && m_rep.compare(m_rep.length()-l, l, s.str())==0;
526 }
527
528#define HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING 0
529#if HAS_IMPLICIT_CAST_TO_PLAIN_C_STRING
530 /** Converts the string to a plain C string */
531 operator const char *() const
532 {
533 return data();
534 }
535#endif
536
537 const std::string &str() const
538 {
539 return m_rep;
540 }
541
543 {
544 m_rep+=s.str();
545 return *this;
546 }
547
548 QCString &operator+=( const std::string &s)
549 {
550 m_rep+=s;
551 return *this;
552 }
553
554 QCString &operator+=(std::string_view s)
555 {
556 m_rep+=s;
557 return *this;
558 }
559
560 /** Appends string \a str to this string and returns a reference to the result. */
561 QCString &operator+=( const char *s )
562 {
563 if (s) m_rep+=s;
564 return *this;
565 }
566
567#define HAS_CHARACTER_APPEND_OPERATOR 1
568#if HAS_CHARACTER_APPEND_OPERATOR
569 /** Appends character \a c to this string and returns a reference to the result. */
570 QCString &operator+=( char c )
571 {
572 m_rep+=c;
573 return *this;
574 }
575#endif
576
577 /** Returns a reference to the character at index \a i. */
578 char &at( size_t i)
579 {
580 return m_rep[i];
581 }
582
583 const char &at( size_t i) const
584 {
585 return m_rep[i];
586 }
587
588 /** Indexing operator. Equivalent to at(). */
589 char &operator[]( size_t i )
590 {
591 return m_rep[i];
592 }
593
594 const char &operator[]( size_t i ) const
595 {
596 return m_rep[i];
597 }
598
599 private:
600 std::string m_rep;
601};
602
603/*****************************************************************************
604 QCString non-member operators
605 *****************************************************************************/
606
607inline bool operator==( const QCString &s1, const QCString &s2 )
608{ return s1.str() == s2.str(); }
609
610inline bool operator==( const QCString &s1, const char *s2 )
611{ return qstrcmp(s1.data(),s2) == 0; }
612
613inline bool operator==( const char *s1, const QCString &s2 )
614{ return qstrcmp(s1,s2.data()) == 0; }
615
616inline bool operator!=( const QCString &s1, const QCString &s2 )
617{ return s1.str() != s2.str(); }
618
619inline bool operator!=( const QCString &s1, const char *s2 )
620{ return qstrcmp(s1.data(),s2) != 0; }
621
622inline bool operator!=( const char *s1, const QCString &s2 )
623{ return qstrcmp(s1,s2.data()) != 0; }
624
625inline bool operator<( const QCString &s1, const QCString& s2 )
626{ return qstrcmp(s1.data(),s2.data()) < 0; }
627
628inline bool operator<( const QCString &s1, const char *s2 )
629{ return qstrcmp(s1.data(),s2) < 0; }
630
631inline bool operator<( const char *s1, const QCString &s2 )
632{ return qstrcmp(s1,s2.data()) < 0; }
633
634inline bool operator<=( const QCString &s1, const char *s2 )
635{ return qstrcmp(s1.data(),s2) <= 0; }
636
637inline bool operator<=( const char *s1, const QCString &s2 )
638{ return qstrcmp(s1,s2.data()) <= 0; }
639
640inline bool operator>( const QCString &s1, const char *s2 )
641{ return qstrcmp(s1.data(),s2) > 0; }
642
643inline bool operator>( const char *s1, const QCString &s2 )
644{ return qstrcmp(s1,s2.data()) > 0; }
645
646inline bool operator>=( const QCString &s1, const char *s2 )
647{ return qstrcmp(s1.data(),s2) >= 0; }
648
649inline bool operator>=( const char *s1, const QCString &s2 )
650{ return qstrcmp(s1,s2.data()) >= 0; }
651
652inline QCString operator+( const QCString &s1, const QCString &s2 )
653{
654 return QCString(s1.str()+s2.str());
655}
656
657
658inline QCString operator+( const QCString &s1, const char *s2 )
659{
660 QCString tmp(s1);
661 tmp.append(s2);
662 return tmp;
663}
664
665inline QCString operator+( const char *s1, const QCString &s2 )
666{
667 QCString tmp(s1);
668 tmp.append(s2);
669 return tmp;
670}
671
672inline const char *qPrint(const char *s)
673{
674 if (s) return s; else return "";
675}
676
677inline const char *qPrint(const QCString &s)
678{
679 if (!s.isEmpty()) return s.data(); else return "";
680}
681
682inline const char *qPrint(const std::string &s)
683{
684 return s.c_str();
685}
686
687inline std::string toStdString(const QCString &s)
688{
689 return s.str();
690}
691
692//---- overloads
693
694inline int qstrcmp( const QCString &str1, const char *str2 )
695{
696 return qstrcmp(str1.data(),str2);
697}
698
699inline int qstrcmp( const char *str1, const QCString &str2 )
700{
701 return qstrcmp(str1,str2.data());
702}
703
704inline int qstrcmp( const QCString &str1, const QCString &str2 )
705{
706 return qstrcmp(str1.data(),str2.data());
707}
708
709inline int qstricmp( const QCString &str1, const char *str2 )
710{
711 return qstricmp(str1.data(),str2);
712}
713
714inline int qstricmp( const char *str1, const QCString &str2 )
715{
716 return qstricmp(str1,str2.data());
717}
718
719inline int qstricmp( const QCString &str1, const QCString &str2 )
720{
721 return qstricmp(str1.data(),str2.data());
722}
723
724inline int qstricmp_sort( const QCString &str1, const char *str2 )
725{
726 return qstricmp_sort(str1.data(),str2);
727}
728
729inline int qstricmp_sort( const char *str1, const QCString &str2 )
730{
731 return qstricmp_sort(str1,str2.data());
732}
733
734inline int qstricmp_sort( const QCString &str1, const QCString &str2 )
735{
736 return qstricmp_sort(str1.data(),str2.data());
737}
738
739
740inline int qstrnicmp( const QCString &str1, const char *str2, size_t len )
741{
742 return qstrnicmp(str1.data(),str2,len);
743}
744
745inline int qstrnicmp( const char *str1, const QCString &str2, size_t len )
746{
747 return qstrnicmp(str1,str2.data(),len);
748}
749
750inline int qstrnicmp( const QCString &str1, const QCString &str2, size_t len )
751{
752 return qstrnicmp(str1.data(),str2.data(),len);
753}
754
755// helper functions
756QCString substitute(const QCString &str,const QCString &find,const QCString &replace);
757inline QCString substitute(const QCString &str,const char *find,const char *replace)
758{
759 return substitute(str,QCString(find),QCString(replace));
760}
761QCString substitute(const QCString &s,const QCString &src,const QCString &dst,int skip_seq);
762
763inline QCString substitute(const QCString &s,char srcChar,char dstChar)
764{
765 std::string ss = s.str();
766 std::replace(ss.begin(),ss.end(),srcChar,dstChar);
767 return QCString(ss);
768}
769
770inline std::ostream& operator<<(std::ostream& os, const QCString& s)
771{
772 os << s.str();
773 return os;
774}
775
776#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:522
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:548
QCString & operator+=(const QCString &s)
Definition qcstring.h:542
bool endsWith(const char *s) const
Definition qcstring.h:509
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:578
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:594
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:554
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
bool endsWith(const std::string &s) const
Definition qcstring.h:516
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:600
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:561
bool startsWith(const QCString &s) const
Definition qcstring.h:503
QCString(int)=delete
const std::string & str() const
Definition qcstring.h:537
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:589
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:583
QCString(size_t size, SizeTag t)
Definition qcstring.h:134
bool startsWith(const std::string &s) const
Definition qcstring.h:498
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:640
bool operator>=(const QCString &s1, const char *s2)
Definition qcstring.h:646
int qstricmp(const char *str1, const char *str2)
Definition qcstring.cpp:442
std::ostream & operator<<(std::ostream &os, const QCString &s)
Definition qcstring.h:770
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:672
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
bool operator<=(const QCString &s1, const char *s2)
Definition qcstring.h:634
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:687
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:607
QCString operator+(const QCString &s1, const QCString &s2)
Definition qcstring.h:652
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:625
bool operator!=(const QCString &s1, const QCString &s2)
Definition qcstring.h:616
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.