annotate modules/javafx.web/src/main/native/Source/ThirdParty/icu/source/common/unistr_props.cpp @ 11038:20a8447c71c6

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