intl/icu/source/common/unistr_props.cpp

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 1999-2011, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 *******************************************************************************
michael@0 8 * file name: unistr_props.cpp
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:2
michael@0 12 *
michael@0 13 * created on: 2004aug25
michael@0 14 * created by: Markus W. Scherer
michael@0 15 *
michael@0 16 * Character property dependent functions moved here from unistr.cpp
michael@0 17 */
michael@0 18
michael@0 19 #include "unicode/utypes.h"
michael@0 20 #include "unicode/uchar.h"
michael@0 21 #include "unicode/unistr.h"
michael@0 22 #include "unicode/utf16.h"
michael@0 23
michael@0 24 U_NAMESPACE_BEGIN
michael@0 25
michael@0 26 UnicodeString&
michael@0 27 UnicodeString::trim()
michael@0 28 {
michael@0 29 if(isBogus()) {
michael@0 30 return *this;
michael@0 31 }
michael@0 32
michael@0 33 UChar *array = getArrayStart();
michael@0 34 UChar32 c;
michael@0 35 int32_t oldLength = this->length();
michael@0 36 int32_t i = oldLength, length;
michael@0 37
michael@0 38 // first cut off trailing white space
michael@0 39 for(;;) {
michael@0 40 length = i;
michael@0 41 if(i <= 0) {
michael@0 42 break;
michael@0 43 }
michael@0 44 U16_PREV(array, 0, i, c);
michael@0 45 if(!(c == 0x20 || u_isWhitespace(c))) {
michael@0 46 break;
michael@0 47 }
michael@0 48 }
michael@0 49 if(length < oldLength) {
michael@0 50 setLength(length);
michael@0 51 }
michael@0 52
michael@0 53 // find leading white space
michael@0 54 int32_t start;
michael@0 55 i = 0;
michael@0 56 for(;;) {
michael@0 57 start = i;
michael@0 58 if(i >= length) {
michael@0 59 break;
michael@0 60 }
michael@0 61 U16_NEXT(array, i, length, c);
michael@0 62 if(!(c == 0x20 || u_isWhitespace(c))) {
michael@0 63 break;
michael@0 64 }
michael@0 65 }
michael@0 66
michael@0 67 // move string forward over leading white space
michael@0 68 if(start > 0) {
michael@0 69 doReplace(0, start, 0, 0, 0);
michael@0 70 }
michael@0 71
michael@0 72 return *this;
michael@0 73 }
michael@0 74
michael@0 75 U_NAMESPACE_END

mercurial