1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/unistr_props.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +/* 1.5 +******************************************************************************* 1.6 +* 1.7 +* Copyright (C) 1999-2011, International Business Machines 1.8 +* Corporation and others. All Rights Reserved. 1.9 +* 1.10 +******************************************************************************* 1.11 +* file name: unistr_props.cpp 1.12 +* encoding: US-ASCII 1.13 +* tab size: 8 (not used) 1.14 +* indentation:2 1.15 +* 1.16 +* created on: 2004aug25 1.17 +* created by: Markus W. Scherer 1.18 +* 1.19 +* Character property dependent functions moved here from unistr.cpp 1.20 +*/ 1.21 + 1.22 +#include "unicode/utypes.h" 1.23 +#include "unicode/uchar.h" 1.24 +#include "unicode/unistr.h" 1.25 +#include "unicode/utf16.h" 1.26 + 1.27 +U_NAMESPACE_BEGIN 1.28 + 1.29 +UnicodeString& 1.30 +UnicodeString::trim() 1.31 +{ 1.32 + if(isBogus()) { 1.33 + return *this; 1.34 + } 1.35 + 1.36 + UChar *array = getArrayStart(); 1.37 + UChar32 c; 1.38 + int32_t oldLength = this->length(); 1.39 + int32_t i = oldLength, length; 1.40 + 1.41 + // first cut off trailing white space 1.42 + for(;;) { 1.43 + length = i; 1.44 + if(i <= 0) { 1.45 + break; 1.46 + } 1.47 + U16_PREV(array, 0, i, c); 1.48 + if(!(c == 0x20 || u_isWhitespace(c))) { 1.49 + break; 1.50 + } 1.51 + } 1.52 + if(length < oldLength) { 1.53 + setLength(length); 1.54 + } 1.55 + 1.56 + // find leading white space 1.57 + int32_t start; 1.58 + i = 0; 1.59 + for(;;) { 1.60 + start = i; 1.61 + if(i >= length) { 1.62 + break; 1.63 + } 1.64 + U16_NEXT(array, i, length, c); 1.65 + if(!(c == 0x20 || u_isWhitespace(c))) { 1.66 + break; 1.67 + } 1.68 + } 1.69 + 1.70 + // move string forward over leading white space 1.71 + if(start > 0) { 1.72 + doReplace(0, start, 0, 0, 0); 1.73 + } 1.74 + 1.75 + return *this; 1.76 +} 1.77 + 1.78 +U_NAMESPACE_END