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