28 #if !defined(_OS_WIN32_) || defined(__MINGW32__) 32 #if defined(_OS_SUN_) && defined(_CC_GNU_) 44 #if defined(_OS_HPUX_) 49 inline char *hack_strstr(
const char *s1,
const char *s2 )
50 {
return (
char *)strstr(s1, s2); }
51 inline char *hack_strchr(
const char *s,
int c )
52 {
return (
char *)strchr(s, c); }
53 inline char *hack_strrchr(
const char *s,
int c )
54 {
return (
char *)strrchr(s, c); }
55 #define strstr(s1,s2) hack_strstr((s1),(s2)) 56 #define strchr(s,c) hack_strchr((s),(c)) 57 #define strrchr(s,c) hack_strrchr((s),(c)) 64 Q_EXPORT
void *qmemmove(
void *dst,
const void *src, uint len );
66 #if defined(_OS_SUN_) || defined(_CC_OC_) 67 #define memmove(s1,s2,n) qmemmove((s1),(s2),(n)) 70 #if defined(_OS_WIN32_) 71 #define qsnprintf _snprintf 73 #define qsnprintf snprintf 76 Q_EXPORT
char *qstrdup(
const char * );
78 Q_EXPORT
inline uint cstrlen(
const char *str )
79 {
return (uint)strlen(str); }
81 Q_EXPORT
inline uint qstrlen(
const char *str )
82 {
return str ? (uint)strlen(str) : 0; }
84 Q_EXPORT
inline char *cstrcpy(
char *dst,
const char *src )
85 {
return strcpy(dst,src); }
87 Q_EXPORT
inline char *qstrcpy(
char *dst,
const char *src )
88 {
return src ? strcpy(dst, src) : 0; }
90 Q_EXPORT
char * qstrncpy(
char *src,
const char *dst, uint len);
92 Q_EXPORT
inline int cstrcmp(
const char *str1,
const char *str2 )
93 {
return strcmp(str1,str2); }
95 Q_EXPORT
inline int qstrcmp(
const char *str1,
const char *str2 )
96 {
return (str1 && str2) ? strcmp(str1,str2) : (int)((intptr_t)str2 - (intptr_t)str1); }
98 Q_EXPORT
inline int cstrncmp(
const char *str1,
const char *str2, uint len )
99 {
return strncmp(str1,str2,len); }
101 Q_EXPORT
inline int qstrncmp(
const char *str1,
const char *str2, uint len )
102 {
return (str1 && str2) ? strncmp(str1,str2,len) :
103 (int)((intptr_t)str2 - (intptr_t)str1); }
105 Q_EXPORT
int qstricmp(
const char *str1,
const char *str2 );
107 Q_EXPORT
int qstrnicmp(
const char *str1,
const char *str2, uint len );
113 #if defined(Q_TEMPLATEDLL) 121 #ifndef QT_NO_DATASTREAM 164 QCString(
const char *str, uint maxlen ) : m_rep(str,maxlen)
185 return m_rep.isEmpty();
191 return m_rep.isEmpty();
197 return m_rep.length();
203 return m_rep.length();
218 return m_rep.rawData();
227 m_rep.resize(newlen);
234 return resize(pos+1);
243 bool fill(
char c,
int len = -1 )
254 memcpy(cs.
rawData(),data(),length());
258 QCString &sprintf(
const char *format, ... );
259 int find(
char c,
int index=0,
bool cs=TRUE )
const;
260 int find(
const char *str,
int index=0,
bool cs=TRUE )
const;
261 int find(
const QCString &str,
int index=0,
bool cs=TRUE )
const;
262 int find(
const QRegExp &rx,
int index=0 )
const;
263 int findRev(
char c,
int index=-1,
bool cs=TRUE)
const;
264 int findRev(
const char *str,
int index=-1,
bool cs=TRUE)
const;
265 int findRev(
const QRegExp &rx,
int index=-1 )
const;
266 int contains(
char c,
bool cs=TRUE )
const;
267 int contains(
const char *str,
bool cs=TRUE )
const;
268 int contains(
const QRegExp &rx )
const;
269 bool stripPrefix(
const char *prefix);
272 QCString mid( uint index, uint len=0xffffffff)
const;
276 QCString simplifyWhiteSpace()
const;
277 QCString &assign(
const char *str );
278 QCString &insert( uint index,
const char *s );
279 QCString &insert( uint index,
char c);
282 QCString &
remove( uint index, uint len );
283 QCString &replace( uint index, uint len,
const char *s);
285 short toShort(
bool *ok=0 )
const;
286 ushort toUShort(
bool *ok=0 )
const;
287 int toInt(
bool *ok=0 )
const;
288 uint toUInt(
bool *ok=0 )
const;
289 long toLong(
bool *ok=0 )
const;
290 ulong toULong(
bool *ok=0 )
const;
291 uint64 toUInt64(
bool *ok=0 )
const;
300 operator const char *()
const 302 return (
const char *)data();
308 if (!str)
return *
this;
310 int len2 = (int)strlen(str);
312 memcpy(rawData()+len1,str,len2);
326 char &
at( uint i)
const 334 return m_rep.at((uint)i);
349 #define SHORT_STR_CAPACITY ((int)sizeof(LongStringRep)-2) 350 #define SHORT_STR_MAX_LEN (SHORT_STR_CAPACITY-1) 353 struct ShortStringRep
357 char str[SHORT_STR_CAPACITY];
367 struct LSData :
public LSHeader
371 return (
char*)(
this+1);
376 static LSData *create(
int size)
379 data = (LSData*)malloc(
sizeof(LSHeader)+size);
382 data->toStr()[size-1] = 0;
388 if (--refCount<0) free(
this);
393 static LSData *resize(LSData *d,
int size)
395 if (d->len>0 && d->refCount==0)
397 d = (LSData*)realloc(d,
sizeof(LSHeader)+size);
399 d->toStr()[size-1] = 0;
404 LSData *newData = LSData::create(size);
406 if (len>=size) len=size-1;
407 memcpy(newData->toStr(),d->toStr(),len);
408 newData->toStr()[len]=0;
435 StringRep(
const StringRep &s)
439 u.s.isShort = s.u.s.isShort;
443 memcpy(u.s.str,s.u.s.str,s.u.s.len+1);
458 u.s.isShort = size<=SHORT_STR_CAPACITY;
459 if (size<=SHORT_STR_CAPACITY)
464 u.s.str[size-1]=
'\0';
473 u.l.d = LSData::create(size);
476 StringRep(
const char *str)
480 int len = (int)strlen(str);
481 u.s.isShort = len<SHORT_STR_CAPACITY;
482 if (len<SHORT_STR_CAPACITY)
485 qstrncpy(u.s.str,str,SHORT_STR_CAPACITY);
489 u.l.d = LSData::create(len+1);
490 memcpy(u.l.d->toStr(),str,u.l.d->len);
498 StringRep(
const char *str, uint maxlen )
502 uint len=(uint)strlen(str);
503 if (len>maxlen) len=maxlen;
504 u.s.isShort = len<=SHORT_STR_MAX_LEN;
508 memcpy(u.s.str,str,len);
513 u.l.d = LSData::create(len+1);
514 memcpy(u.l.d->toStr(),str,len);
522 StringRep &operator=(
const StringRep &s)
530 u.s.isShort = s.u.s.isShort;
534 memcpy(u.s.str,s.u.s.str,s.u.s.len+1);
548 StringRep &operator=(
const char *str)
556 int len = (int)strlen(str);
557 u.s.isShort = len<SHORT_STR_CAPACITY;
558 if (len<SHORT_STR_CAPACITY)
561 qstrncpy(u.s.str,str,SHORT_STR_CAPACITY);
565 u.l.d = LSData::create(len+1);
566 memcpy(u.l.d->toStr(),str,len);
577 return u.s.isShort && u.s.len==0;
581 uint l = u.s.isShort ? u.s.len : u.l.d->len;
584 const char *data()
const 588 return u.s.len==0 ? 0 : u.s.str;
592 return u.l.d->len==0 ? 0 : u.l.d->toStr();
595 char *rawData()
const 599 return u.s.len==0 ? 0 : (
char*)u.s.str;
604 return u.l.d->len==0 ? 0 : u.l.d->toStr();
607 char &at(
int i)
const 611 return (
char&)u.s.str[i];
615 return u.l.d->toStr()[i];
618 bool resize( uint newlen )
620 if (u.s.isShort && newlen<=SHORT_STR_CAPACITY)
625 u.s.str[newlen-1]=
'\0';
632 else if (u.s.isShort)
634 StringRep tmp = *
this;
636 u.l.d = LSData::create(newlen);
639 memcpy(u.l.d->toStr(),tmp.u.s.str,tmp.u.s.len+1);
643 u.l.d->toStr()[0]=
'\0';
646 else if (!u.s.isShort && newlen<=SHORT_STR_CAPACITY)
650 StringRep tmp(newlen);
651 memcpy(tmp.u.s.str,u.l.d->toStr(),newlen-1);
652 tmp.u.s.str[newlen-1]=
'\0';
664 u.l.d = u.l.d->resize(u.l.d,newlen);
668 bool fill(
char c,
int len )
670 if (len<0) len=length();
675 else if (len!=(
int)length())
684 memset(rawData(),c,len);
689 union ShortOrLongStringSelector
702 #ifndef QT_NO_DATASTREAM 712 {
return qstrcmp(s1.
data(),s2.
data()) == 0; }
715 {
return qstrcmp(s1.
data(),s2) == 0; }
718 {
return qstrcmp(s1,s2.
data()) == 0; }
721 {
return qstrcmp(s1.
data(),s2.
data()) != 0; }
724 {
return qstrcmp(s1.
data(),s2) != 0; }
727 {
return qstrcmp(s1,s2.
data()) != 0; }
730 {
return qstrcmp(s1.
data(),s2.
data()) < 0; }
733 {
return qstrcmp(s1.
data(),s2) < 0; }
736 {
return qstrcmp(s1,s2.
data()) < 0; }
739 {
return qstrcmp(s1.
data(),s2) <= 0; }
742 {
return qstrcmp(s1,s2.
data()) <= 0; }
745 {
return qstrcmp(s1.
data(),s2) > 0; }
748 {
return qstrcmp(s1,s2.
data()) > 0; }
751 {
return qstrcmp(s1.
data(),s2) >= 0; }
754 {
return qstrcmp(s1,s2.
data()) >= 0; }
797 inline const char *qPrint(
const char *s)
799 if (s)
return s;
else return "";
802 inline const char *qPrint(
const QCString &s)
int operator>(QChar c1, QChar c2)
Definition: qstring.h:329
bool resize(uint newlen)
Resizes the string to hold newlen characters (this value should include the 0-terminator).
Definition: qcstring.h:225
QDataStream & operator<<(QDataStream &s, const QString &str)
Definition: qstring.cpp:15066
QCString(const QCString &s)
makes a copy of a string.
Definition: qcstring.h:145
QCString & operator+=(const char *str)
Appends string str to this string and returns a reference to the result.
Definition: qcstring.h:306
The QRegExp class provides pattern matching using regular expressions or wildcards.
Definition: qregexp.h:46
QCString & operator+=(char c)
Appends character c to this string and returns a reference to the result.
Definition: qcstring.h:317
int operator<(QChar c1, QChar c2)
Definition: qstring.h:326
QCString()
creates an empty string
Definition: qcstring.h:135
uint size() const
Returns the length of the string, excluding the 0-terminator.
Definition: qcstring.h:201
QCString & operator=(const char *str)
replaces the contents by that of C string str.
Definition: qcstring.h:176
uint length() const
Returns the length of the string, excluding the 0-terminator.
Definition: qcstring.h:195
char & at(uint i) const
Returns a reference to the character at index i.
Definition: qcstring.h:326
QCString(const char *str)
creates a string from a plain C string.
Definition: qcstring.h:159
QCString & operator=(const QCString &s)
replaces the contents by that of string s.
Definition: qcstring.h:169
bool operator<=(const QString &s1, const char *s2)
Definition: qstring.cpp:14884
~QCString()
destroys the string
Definition: qcstring.h:140
QString operator+(const QString &s1, const QString &s2)
Definition: qstring.h:774
QCString(const char *str, uint maxlen)
creates a string from str and copies over the first maxlen characters.
Definition: qcstring.h:164
bool isNull() const
Returns TRUE iff the string is empty.
Definition: qcstring.h:183
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:207
int operator>=(QChar c1, QChar c2)
Definition: qstring.h:323
bool operator==(const QString &s1, const QString &s2)
Definition: qstring.cpp:14843
This is an alternative implementation of QCString.
Definition: qgstring.h:19
bool fill(char c, int len=-1)
Fills a string with a predefined character.
Definition: qcstring.h:243
bool truncate(uint pos)
Truncates the string at position pos.
Definition: qcstring.h:232
char * rawData() const
Returns a writable pointer to the data.
Definition: qcstring.h:216
bool operator!=(const QString &s1, const QString &s2)
Definition: qstring.cpp:14850
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:47
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition: qcstring.h:189
QCString(int size)
creates a string with room for size characters
Definition: qcstring.h:152
This is an alternative implementation of QCString.
Definition: qcstring.h:131
char & operator[](int i) const
Indexing operator.
Definition: qcstring.h:332
QCString copy() const
Returns a deep copy of the string.
Definition: qcstring.h:250