📄 q3cstring.cpp
字号:
goto bye; val = 10*val + (*p++ - '0'); } if (neg) val = -val; while (isspace((uchar) *p)) // skip trailing space p++; if (*p == '\0') is_ok = true;bye: if (ok) *ok = is_ok; return is_ok ? val : 0;}/*! Returns the string converted to an \c{unsigned long} value. If \a ok is not 0: *\a ok is set to false if the string is not a number, or if it has trailing garbage; otherwise *\a ok is set to true.*/ulong Q3CString::toULong(bool *ok) const{ const char *p = constData(); ulong val=0; const ulong max_mult = 429496729; bool is_ok = false; if (!p) goto bye; while (isspace((uchar) *p)) // skip leading space p++; if (*p == '+') p++; if (!isdigit((uchar) *p)) goto bye; while (isdigit((uchar) *p)) { if (val > max_mult || (val == max_mult && (*p-'0') > 5)) goto bye; val = 10*val + (*p++ - '0'); } while (isspace((uchar) *p)) // skip trailing space p++; if (*p == '\0') is_ok = true;bye: if (ok) *ok = is_ok; return is_ok ? val : 0;}/*! Returns the string converted to a \c{short} value. If \a ok is not 0: *\a ok is set to false if the string is not a number, is out of range, or if it has trailing garbage; otherwise *\a ok is set to true.*/short Q3CString::toShort(bool *ok) const{ long v = toLong(ok); if (ok && *ok && (v < -32768 || v > 32767)) *ok = false; return (short)v;}/*! Returns the string converted to an \c{unsigned short} value. If \a ok is not 0: *\a ok is set to false if the string is not a number, is out of range, or if it has trailing garbage; otherwise *\a ok is set to true.*/ushort Q3CString::toUShort(bool *ok) const{ ulong v = toULong(ok); if (ok && *ok && (v > 65535)) *ok = false; return (ushort)v;}/*! Returns the string converted to a \c{int} value. If \a ok is not 0: *\a ok is set to false if the string is not a number, or if it has trailing garbage; otherwise *\a ok is set to true.*/int Q3CString::toInt(bool *ok) const{ return (int)toLong(ok);}/*! Returns the string converted to an \c{unsigned int} value. If \a ok is not 0: *\a ok is set to false if the string is not a number, or if it has trailing garbage; otherwise *\a ok is set to true.*/uint Q3CString::toUInt(bool *ok) const{ return (uint)toULong(ok);}/*! Returns the string converted to a \c{double} value. If \a ok is not 0: *\a ok is set to false if the string is not a number, or if it has trailing garbage; otherwise *\a ok is set to true.*/double Q3CString::toDouble(bool *ok) const{ char *end; double val = strtod(constData() ? constData() : "", &end); if (ok) *ok = (constData() && *constData() && (end == 0 || *end == '\0')); return val;}/*! Returns the string converted to a \c{float} value. If \a ok is not 0: *\a ok is set to false if the string is not a number, or if it has trailing garbage; otherwise *\a ok is set to true.*/float Q3CString::toFloat(bool *ok) const{ return (float)toDouble(ok);}/*! \fn Q3CString &Q3CString::setStr(const char *str) Makes a deep copy of \a str. Returns a reference to the string.*//*! \overload Sets the string to the string representation of the number \a n and returns a reference to the string.*/Q3CString &Q3CString::setNum(long n){ data(); char buf[20]; register char *p = &buf[19]; bool neg; if (n < 0) { neg = true; n = -n; } else { neg = false; } *p = '\0'; do { *--p = ((int)(n%10)) + '0'; n /= 10; } while (n); if (neg) *--p = '-'; *this = p; return *this;}/*! \overload Sets the string to the string representation of the number \a n and returns a reference to the string.*/Q3CString &Q3CString::setNum(ulong n){ data(); char buf[20]; register char *p = &buf[19]; *p = '\0'; do { *--p = ((int)(n%10)) + '0'; n /= 10; } while (n); *this = p; return *this;}/*! \fn Q3CString &Q3CString::setNum(int n) \overload Sets the string to the string representation of the number \a n and returns a reference to the string.*//*! \fn Q3CString &Q3CString::setNum(uint n) \overload Sets the string to the string representation of the number \a n and returns a reference to the string.*//*! \fn Q3CString &Q3CString::setNum(short n) \overload Sets the string to the string representation of the number \a n and returns a reference to the string.*//*! \fn Q3CString &Q3CString::setNum(ushort n) \overload Sets the string to the string representation of the number \a n and returns a reference to the string.*//*! Sets the string to the string representation of the number \a n and returns a reference to the string. The format of the string representation is specified by the format character \a f, and the precision (number of digits after the decimal point) is specified with \a prec. The valid formats for \a f are 'e', 'E', 'f', 'g' and 'G'. The formats are the same as for sprintf(); they are explained in \l QString::arg().*/Q3CString &Q3CString::setNum(double n, char f, int prec){#ifndef QT_NO_DEBUG if (!(f=='f' || f=='F' || f=='e' || f=='E' || f=='g' || f=='G')) qWarning("Q3CString::setNum: Invalid format char '%c'", f);#endif char format[20]; register char *fs = format; // generate format string *fs++ = '%'; // "%.<prec>l<f>" if (prec > 99) prec = 99; *fs++ = '.'; if (prec >= 10) { *fs++ = prec / 10 + '0'; *fs++ = prec % 10 + '0'; } else { *fs++ = prec + '0'; } *fs++ = 'l'; *fs++ = f; *fs = '\0'; return sprintf(format, n);}/*! \fn Q3CString &Q3CString::setNum(float n, char f, int prec) \overload*//*! Sets the character at position \a index to \a c and expands the string if necessary, padding with spaces. Returns false if \a index was out of range and the string could not be expanded; otherwise returns true.*/bool Q3CString::setExpand(uint index, char c){ uint oldlen = length(); if (index >= oldlen) { resize(index+1); if (index > oldlen) memset(data() + oldlen, ' ', index - oldlen); } *(data() + index) = c; return true;}/* \fn Q3CString::operator const char *() const Returns the string data.*//*! \fn Q3CString& Q3CString::append(const char *str) Appends string \a str to the string and returns a reference to the string. Equivalent to operator+=().*//*! \fn QDataStream &operator<<(QDataStream &s, const Q3CString &str) \relates Q3CString Writes string \a str to the stream \a s. \sa \link datastreamformat.html Format of the QDataStream operators \endlink*//*! \fn QDataStream &operator>>(QDataStream &s, Q3CString &str) \relates Q3CString Reads a string into \a str from the stream \a s. \sa \link datastreamformat.html Format of the QDataStream operators \endlink*//***************************************************************************** Documentation for related functions *****************************************************************************//*! \fn bool operator==(const Q3CString &s1, const Q3CString &s2) \relates Q3CString Returns true if \a s1 and \a s2 are equal; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) == 0.*//*! \fn bool operator==(const Q3CString &s1, const char *s2) \overload \relates Q3CString Returns true if \a s1 and \a s2 are equal; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) == 0.*//*! \fn bool operator==(const char *s1, const Q3CString &s2) \overload \relates Q3CString Returns true if \a s1 and \a s2 are equal; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) == 0.*//*! \fn bool operator!=(const Q3CString &s1, const Q3CString &s2) \relates Q3CString Returns true if \a s1 and \a s2 are different; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) != 0.*//*! \fn bool operator!=(const Q3CString &s1, const char *s2) \overload \relates Q3CString Returns true if \a s1 and \a s2 are different; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) != 0.*//*! \fn bool operator!=(const char *s1, const Q3CString &s2) \overload \relates Q3CString Returns true if \a s1 and \a s2 are different; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) != 0.*//*! \fn bool operator<(const Q3CString &s1, const char *s2) \relates Q3CString Returns true if \a s1 is less than \a s2; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) \< 0.*//*! \fn bool operator<(const char *s1, const Q3CString &s2) \overload \relates Q3CString Returns true if \a s1 is less than \a s2; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) \< 0.*//*! \fn bool operator<=(const Q3CString &s1, const char *s2) \relates Q3CString Returns true if \a s1 is less than or equal to \a s2; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) \<= 0.*//*! \fn bool operator<=(const char *s1, const Q3CString &s2) \overload \relates Q3CString Returns true if \a s1 is less than or equal to \a s2; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) \<= 0.*//*! \fn bool operator>(const Q3CString &s1, const char *s2) \relates Q3CString Returns true if \a s1 is greater than \a s2; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) \> 0.*//*! \fn bool operator>(const char *s1, const Q3CString &s2) \overload \relates Q3CString Returns true if \a s1 is greater than \a s2; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) \> 0.*//*! \fn bool operator>=(const Q3CString &s1, const char *s2) \relates Q3CString Returns true if \a s1 is greater than or equal to \a s2; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) \>= 0.*//*! \fn bool operator>=(const char *s1, const Q3CString &s2) \overload \relates Q3CString Returns true if \a s1 is greater than or equal to \a s2; otherwise returns false. Equivalent to qstrcmp(\a s1, \a s2) \>= 0.*//*! \fn const Q3CString operator+(const Q3CString &s1, const Q3CString &s2) \relates Q3CString Returns a string which consists of the concatenation of \a s1 and \a s2.*//*! \fn const Q3CString operator+(const Q3CString &s1, const char *s2) \overload \relates Q3CString Returns a string which consists of the concatenation of \a s1 and \a s2.*//*! \fn const Q3CString operator+(const char *s1, const Q3CString &s2) \overload \relates Q3CString Returns a string which consists of the concatenation of \a s1 and \a s2.*//*! \fn const Q3CString operator+(const Q3CString &s, char c) \overload \relates Q3CString Returns a string which consists of the concatenation of \a s and \a c.*//*! \fn const Q3CString operator+(char c, const Q3CString &s) \overload \relates Q3CString Returns a string which consists of the concatenation of \a c and \a s.*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -