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