2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2004-08-26 22:51:40 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 1999-2011, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2004-08-26 22:51:40 +00:00
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: unistr_props.cpp
|
2017-02-03 18:57:23 +00:00
|
|
|
* encoding: UTF-8
|
2004-08-26 22:51:40 +00:00
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:2
|
|
|
|
*
|
|
|
|
* created on: 2004aug25
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* Character property dependent functions moved here from unistr.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uchar.h"
|
|
|
|
#include "unicode/unistr.h"
|
2011-07-27 05:53:56 +00:00
|
|
|
#include "unicode/utf16.h"
|
2004-08-26 22:51:40 +00:00
|
|
|
|
2006-09-03 17:06:48 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2004-08-26 22:51:40 +00:00
|
|
|
UnicodeString&
|
|
|
|
UnicodeString::trim()
|
|
|
|
{
|
|
|
|
if(isBogus()) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2007-09-28 04:50:25 +00:00
|
|
|
UChar *array = getArrayStart();
|
2004-08-26 22:51:40 +00:00
|
|
|
UChar32 c;
|
2007-09-28 04:50:25 +00:00
|
|
|
int32_t oldLength = this->length();
|
|
|
|
int32_t i = oldLength, length;
|
2004-08-26 22:51:40 +00:00
|
|
|
|
|
|
|
// first cut off trailing white space
|
|
|
|
for(;;) {
|
|
|
|
length = i;
|
|
|
|
if(i <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
2007-09-28 04:50:25 +00:00
|
|
|
U16_PREV(array, 0, i, c);
|
2004-08-26 22:51:40 +00:00
|
|
|
if(!(c == 0x20 || u_isWhitespace(c))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-09-28 04:50:25 +00:00
|
|
|
if(length < oldLength) {
|
|
|
|
setLength(length);
|
2004-08-26 22:51:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// find leading white space
|
|
|
|
int32_t start;
|
|
|
|
i = 0;
|
|
|
|
for(;;) {
|
|
|
|
start = i;
|
|
|
|
if(i >= length) {
|
|
|
|
break;
|
|
|
|
}
|
2007-09-28 04:50:25 +00:00
|
|
|
U16_NEXT(array, i, length, c);
|
2004-08-26 22:51:40 +00:00
|
|
|
if(!(c == 0x20 || u_isWhitespace(c))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// move string forward over leading white space
|
|
|
|
if(start > 0) {
|
|
|
|
doReplace(0, start, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2006-09-03 17:06:48 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|