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