| 1303 | //----------------------------------------------------------------------------- |
| 1304 | |
| 1305 | String String::trim() const |
| 1306 | { |
| 1307 | if( isEmpty() ) |
| 1308 | return *this; |
| 1309 | |
| 1310 | const StringChar* start = _string->utf8(); |
| 1311 | while( *start && dIsspace( *start ) ) |
| 1312 | start ++; |
| 1313 | |
| 1314 | const StringChar* end = _string->utf8() + length() - 1; |
| 1315 | while( end > start && dIsspace( *end ) ) |
| 1316 | end --; |
| 1317 | end ++; |
| 1318 | |
| 1319 | const U32 len = end - start; |
| 1320 | if( len == length() ) |
| 1321 | return *this; |
| 1322 | |
| 1323 | StringData* sub; |
| 1324 | if( !len ) |
| 1325 | sub = StringData::Empty(); |
| 1326 | else |
| 1327 | sub = StringData::Create(start, len); |
| 1328 | |
| 1329 | return sub; |
| 1330 | } |
| 1331 | |
| 1332 | //----------------------------------------------------------------------------- |
| 1333 | |