michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 1999-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: unistr_props.cpp michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:2 michael@0: * michael@0: * created on: 2004aug25 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * Character property dependent functions moved here from unistr.cpp michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uchar.h" michael@0: #include "unicode/unistr.h" michael@0: #include "unicode/utf16.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: UnicodeString& michael@0: UnicodeString::trim() michael@0: { michael@0: if(isBogus()) { michael@0: return *this; michael@0: } michael@0: michael@0: UChar *array = getArrayStart(); michael@0: UChar32 c; michael@0: int32_t oldLength = this->length(); michael@0: int32_t i = oldLength, length; michael@0: michael@0: // first cut off trailing white space michael@0: for(;;) { michael@0: length = i; michael@0: if(i <= 0) { michael@0: break; michael@0: } michael@0: U16_PREV(array, 0, i, c); michael@0: if(!(c == 0x20 || u_isWhitespace(c))) { michael@0: break; michael@0: } michael@0: } michael@0: if(length < oldLength) { michael@0: setLength(length); michael@0: } michael@0: michael@0: // find leading white space michael@0: int32_t start; michael@0: i = 0; michael@0: for(;;) { michael@0: start = i; michael@0: if(i >= length) { michael@0: break; michael@0: } michael@0: U16_NEXT(array, i, length, c); michael@0: if(!(c == 0x20 || u_isWhitespace(c))) { michael@0: break; michael@0: } michael@0: } michael@0: michael@0: // move string forward over leading white space michael@0: if(start > 0) { michael@0: doReplace(0, start, 0, 0, 0); michael@0: } michael@0: michael@0: return *this; michael@0: } michael@0: michael@0: U_NAMESPACE_END