Changeset 11196

Show
Ignore:
Timestamp:
04/03/07 19:18:17 (2 years ago)
Author:
mloskot
Message:

Backported CPLString::Trim() function introduced recently in trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/gdal/port/cpl_string.h

    r10646 r11196  
    170170{ 
    171171public: 
     172     
    172173    CPLString(void) {} 
    173174    CPLString( const std::string &oStr ) : std_string( oStr ) {} 
     
    178179    CPLString &Printf( const char *pszFormat, ... ); 
    179180    CPLString &vPrintf( const char *pszFormat, va_list args ); 
     181    CPLString &Trim(); 
    180182}; 
    181183 
  • branches/1.4/gdal/port/cplstring.cpp

    r10646 r11196  
    2929 
    3030#include "cpl_string.h" 
     31#include <string> 
    3132 
    3233CPL_CVSID("$Id$"); 
     
    130131    return *this; 
    131132} 
     133 
     134/************************************************************************/ 
     135/*                                Trim()                                */ 
     136/************************************************************************/ 
     137 
     138/** 
     139 * Trim white space. 
     140 * 
     141 * Trims white space off the let and right of the string.  White space 
     142 * is any of a space, a tab, a newline ('\n') or a carriage control ('\r'). 
     143 * 
     144 * @return a reference to the CPLString.  
     145 */ 
     146 
     147CPLString &CPLString::Trim() 
     148 
     149{ 
     150    size_t iLeft, iRight; 
     151    static const char szWhitespace[] = " \t\r\n"; 
     152 
     153    iLeft = find_first_not_of( szWhitespace ); 
     154    iRight = find_last_not_of( szWhitespace ); 
     155 
     156    if( iLeft == std::string::npos ) 
     157    { 
     158        erase(); 
     159        return *this; 
     160    } 
     161     
     162    assign( substr( iLeft, iRight - iLeft + 1 ) ); 
     163 
     164    return *this; 
     165}