⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qcstring.cpp

📁 doxygen(一个自动从源代码生成文档的工具)的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    int padlen = width - len;    if ( padlen > 0 ) {	result.QByteArray::resize( len+padlen+1 );	memcpy( result.data(), data(), len );	memset( result.data()+len, fill, padlen );	result[len+padlen] = '\0';    } else {	if ( truncate )	    result = left( width );	else	    result = copy();    }    return result;}/*!  Returns a string of length \e width (plus '\0') that contains pad  characters followed by the string.  If the length of the string exceeds \e width and \e truncate is FALSE,  then the returned string is a copy of the string.  If the length of the string exceeds \e width and \e truncate is TRUE,  then the returned string is a left(\e width).  Example:  \code    QCString s("pie");    QCString t = s.rightJustify(8, '.');		// t == ".....pie"  \endcode  \sa leftJustify()*/QCString QCString::rightJustify( uint width, char fill, bool truncate ) const{    QCString result;    int len = qstrlen(data());    int padlen = width - len;    if ( padlen > 0 ) {	result.QByteArray::resize( len+padlen+1 );	memset( result.data(), fill, padlen );	memcpy( result.data()+padlen, data(), len );	result[len+padlen] = '\0';    } else {	if ( truncate )	    result = left( width );	else	    result = copy();    }    return result;}/*!  Returns a new string that is the string converted to lower case.  Presently it only handles 7-bit ASCII, or whatever tolower()  handles (if $LC_CTYPE is set, most UNIX systems do the Right Thing).  Example:  \code    QCString s("TeX");    QCString t = s.lower();			// t == "tex"  \endcode  \sa upper()*/QCString QCString::lower() const{    QCString s( data() );    register char *p = s.data();    if ( p ) {	while ( *p ) {	    *p = tolower((uchar) *p);	    p++;	}    }    return s;}/*!  Returns a new string that is the string converted to upper case.  Presently it only handles 7-bit ASCII, or whatever toupper()  handles (if $LC_CTYPE is set, most UNIX systems do the Right Thing).  Example:  \code    QCString s("TeX");    QCString t = s.upper();			// t == "TEX"  \endcode  \sa lower()*/QCString QCString::upper() const{    QCString s( data() );    register char *p = s.data();    if ( p ) {	while ( *p ) {	    *p = toupper((uchar)*p);	    p++;	}    }    return s;}/*!  Returns a new string that has white space removed from the start and the end.  White space means any ASCII code 9, 10, 11, 12, 13 or 32.  Example:  \code    QCString s = " space ";    QCString t = s.stripWhiteSpace();		// t == "space"  \endcode  \sa simplifyWhiteSpace()*/QCString QCString::stripWhiteSpace() const{    if ( isEmpty() )				// nothing to do	return copy();    register char *s = data();    QCString result = s;    int reslen = result.length();    if ( !isspace((uchar) s[0]) && !isspace((uchar) s[reslen-1]) )	return result;				// returns a copy    s = result.data();    int start = 0;    int end = reslen - 1;    while ( isspace((uchar) s[start]) )			// skip white space from start	start++;    if ( s[start] == '\0' ) {			// only white space	result.resize( 1 );	return result;    }    while ( end && isspace((uchar) s[end]) )		// skip white space from end	end--;    end -= start - 1;    memmove( result.data(), &s[start], end );    result.resize( end + 1 );    return result;}/*!  Returns a new string that has white space removed from the start and the end,  plus any sequence of internal white space replaced with a single space  (ASCII 32).  White space means any ASCII code 9, 10, 11, 12, 13 or 32.  \code    QCString s = "  lots\t of\nwhite    space ";    QCString t = s.simplifyWhiteSpace();		// t == "lots of white space"  \endcode  \sa stripWhiteSpace()*/QCString QCString::simplifyWhiteSpace() const{    if ( isEmpty() )				// nothing to do	return copy();    QCString result( size() );    char *from	= data();    char *to	= result.data();    char *first = to;    while ( TRUE ) {	while ( *from && isspace((uchar) *from) )	    from++;	while ( *from && !isspace((uchar)*from) )	    *to++ = *from++;	if ( *from )	    *to++ = 0x20;			// ' '	else	    break;    }    if ( to > first && *(to-1) == 0x20 )	to--;    *to = '\0';    result.resize( (int)((long)to - (long)result.data()) + 1 );    return result;}/*!  Insert \e s into the string before position \e index.  If \e index is beyond the end of the string, the string is extended with  spaces (ASCII 32) to length \e index and \e s is then appended.  \code    QCString s = "I like fish";    s.insert( 2, "don't ");			// s == "I don't like fish"    s = "x";    s.insert( 3, "yz" );			// s == "x  yz"  \endcode*/QCString &QCString::insert( uint index, const char *s ){    int len = qstrlen(s);    if ( len == 0 )	return *this;    uint olen = length();    int nlen = olen + len;    if ( index >= olen ) {			// insert after end of string	detach();	if ( QByteArray::resize(nlen+index-olen+1) ) {	    memset( data()+olen, ' ', index-olen );	    memcpy( data()+index, s, len+1 );	}    } else if ( QByteArray::resize(nlen+1) ) {	// normal insert	detach();	memmove( data()+index+len, data()+index, olen-index+1 );	memcpy( data()+index, s, len );    }    return *this;}/*!  Insert \e c into the string at (before) position \e index and returns  a reference to the string.  If \e index is beyond the end of the string, the string is extended with  spaces (ASCII 32) to length \e index and \e c is then appended.  Example:  \code    QCString s = "Yes";    s.insert( 3, '!');				// s == "Yes!"  \endcode  \sa remove(), replace()*/QCString &QCString::insert( uint index, char c )	// insert char{    char buf[2];    buf[0] = c;    buf[1] = '\0';    return insert( index, buf );}/*!  \fn QCString &QCString::prepend( const char *s )  Prepend \a s to the string. Equivalent to insert(0,s).  \sa insert()*//*!  Removes \e len characters starting at position \e index from the  string and returns a reference to the string.  If \e index is too big, nothing happens.  If \e index is valid, but  \e len is too large, the rest of the string is removed.  \code    QCString s = "Montreal";    s.remove( 1, 4 );    // s == "Meal"  \endcode  \sa insert(), replace()*/QCString &QCString::remove( uint index, uint len ){    uint olen = length();    if ( index + len >= olen ) {		// range problems	if ( index < olen ) {			// index ok	    detach();	    resize( index+1 );	}    } else if ( len != 0 ) {	detach();	memmove( data()+index, data()+index+len, olen-index-len+1 );	QByteArray::resize(olen-len+1);    }    return *this;}/*!  Replaces \e len characters starting at position \e index from the  string with \e s, and returns a reference to the string.  If \e index is too big, nothing is deleted and \e s is inserted at the  end of the string.  If \e index is valid, but \e len is too large, \e  str replaces the rest of the string.  \code    QCString s = "Say yes!";    s.replace( 4, 3, "NO" );			// s == "Say NO!"  \endcode  \sa insert(), remove()*/QCString &QCString::replace( uint index, uint len, const char *s ){    remove( index, len );    insert( index, s );    return *this;}/*!  Finds the first occurrence of the regular expression \e rx, starting at  position \e index.  Returns the position of the next match, or -1 if \e rx was not found.*/int QCString::find( const QRegExp &rx, int index ) const{    QString d = QString::fromLatin1( data() );    return d.find( rx, index );}/*!  Finds the first occurrence of the regular expression \e rx, starting at  position \e index and searching backwards.  The search will start from the end of the string if \e index is negative.  Returns the position of the next match (backwards), or -1 if \e rx was not  found.*/int QCString::findRev( const QRegExp &rx, int index ) const{    QString d = QString::fromLatin1( data() );    return d.findRev( rx, index );}/*!  Counts the number of overlapping occurrences of \e rx in the string.  Example:  \code    QString s = "banana and panama";    QRegExp r = QRegExp("a[nm]a", TRUE, FALSE);    s.contains( r );				// 4 matches  \endcode  \sa find(), findRev()*/int QCString::contains( const QRegExp &rx ) const{    QString d = QString::fromLatin1( data() );    return d.contains( rx );}/*!  Replaces every occurrence of \e rx in the string with \e str.  Returns a reference to the string.  Example:  \code    QString s = "banana";    s.replace( QRegExp("a.*a"), "" );		// becomes "b"    QString s = "banana";    s.replace( QRegExp("^[bn]a"), " " );	// becomes " nana"    QString s = "banana";    s.replace( QRegExp("^[bn]a"), "" );		// NOTE! becomes ""  \endcode*/QCString &QCString::replace( const QRegExp &rx, const char *str ){    QString d = QString::fromLatin1( data() );    QString r = QString::fromLatin1( str );    d.replace( rx, r );    setStr( d.ascii() );    return *this;}/*!  Returns the string converted to a <code>long</code> value.  If \e ok is non-null, \e *ok is set to TRUE if there are no  conceivable errors, and FALSE if the string is not a number at all, or if  it has trailing garbage.*/long QCString::toLong( bool *ok ) const{    char *p = data();    long val=0;    const long max_mult = 214748364;    bool is_ok = FALSE;    int neg = 0;    if ( !p )	goto bye;    while ( isspace((uchar)*p) )			// skip leading space	p++;    if ( *p == '-' ) {	p++;	neg = 1;    } else if ( *p == '+' ) {	p++;    }    if ( !isdigit((uchar)*p) )	goto bye;    while ( isdigit((uchar)*p) ) {	if ( val > max_mult || (val == max_mult && (*p-'0') > 7+neg) )	    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 <code>unsigned long</code>  value.  If \e ok is non-null, \e *ok is set to TRUE if there are no  conceivable errors, and FALSE if the string is not a number at all,  or if it has trailing garbage.*/ulong QCString::toULong( bool *ok ) const{    char *p = data();    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 <code>short</code> value.  If \e ok is non-null, \e *ok is set to TRUE if there are no  conceivable errors, and FALSE if the string is not a number at all, or if  it has trailing garbage.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -