| | 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 | |
|---|
| | 147 | CPLString &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 | } |
|---|