ICU-12140 Pass StringPiece by value, return value.
R=markus.icu@gmail.com Review URL: https://codereview.appspot.com/305010043 . X-SVN-Rev: 39276
This commit is contained in:
parent
f82d62a85c
commit
0b2bbde810
@ -141,7 +141,6 @@ BytesTrie::Iterator::next(UErrorCode &errorCode) {
|
||||
} else {
|
||||
pos_=skipValue(pos, node);
|
||||
}
|
||||
sp_.set(str_->data(), str_->length());
|
||||
return TRUE;
|
||||
}
|
||||
if(maxLength_>0 && str_->length()==maxLength_) {
|
||||
@ -169,10 +168,14 @@ BytesTrie::Iterator::next(UErrorCode &errorCode) {
|
||||
}
|
||||
}
|
||||
|
||||
StringPiece
|
||||
BytesTrie::Iterator::getString() const {
|
||||
return str_ == NULL ? StringPiece() : str_->toStringPiece();
|
||||
}
|
||||
|
||||
UBool
|
||||
BytesTrie::Iterator::truncateAndStop() {
|
||||
pos_=NULL;
|
||||
sp_.set(str_->data(), str_->length());
|
||||
value_=-1; // no real value for str
|
||||
return TRUE;
|
||||
}
|
||||
@ -201,7 +204,6 @@ BytesTrie::Iterator::branchNext(const uint8_t *pos, int32_t length, UErrorCode &
|
||||
str_->append((char)trieByte, errorCode);
|
||||
if(isFinal) {
|
||||
pos_=NULL;
|
||||
sp_.set(str_->data(), str_->length());
|
||||
value_=value;
|
||||
return NULL;
|
||||
} else {
|
||||
|
@ -308,7 +308,7 @@ public:
|
||||
* @return The NUL-terminated byte sequence for the last successful next().
|
||||
* @stable ICU 4.8
|
||||
*/
|
||||
const StringPiece &getString() const { return sp_; }
|
||||
StringPiece getString() const;
|
||||
/**
|
||||
* @return The value for the last successful next().
|
||||
* @stable ICU 4.8
|
||||
@ -327,7 +327,6 @@ public:
|
||||
int32_t initialRemainingMatchLength_;
|
||||
|
||||
CharString *str_;
|
||||
StringPiece sp_;
|
||||
int32_t maxLength_;
|
||||
int32_t value_;
|
||||
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
void TestTruncatingIteratorFromLinearMatchShort();
|
||||
void TestTruncatingIteratorFromLinearMatchLong();
|
||||
void TestIteratorFromBytes();
|
||||
void TestFailedIterator();
|
||||
|
||||
void checkData(const StringAndValue data[], int32_t dataLength);
|
||||
void checkData(const StringAndValue data[], int32_t dataLength, UStringTrieBuildOption buildOption);
|
||||
@ -107,6 +108,7 @@ void BytesTrieTest::runIndexedTest(int32_t index, UBool exec, const char *&name,
|
||||
TESTCASE_AUTO(TestTruncatingIteratorFromLinearMatchShort);
|
||||
TESTCASE_AUTO(TestTruncatingIteratorFromLinearMatchLong);
|
||||
TESTCASE_AUTO(TestIteratorFromBytes);
|
||||
TESTCASE_AUTO(TestFailedIterator);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
@ -587,6 +589,15 @@ void BytesTrieTest::TestIteratorFromBytes() {
|
||||
checkIterator(iter, data, UPRV_LENGTHOF(data));
|
||||
}
|
||||
|
||||
void BytesTrieTest::TestFailedIterator() {
|
||||
UErrorCode failure = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
BytesTrie::Iterator iter(NULL, 0, failure);
|
||||
StringPiece sp = iter.getString();
|
||||
if (!sp.empty()) {
|
||||
errln("failed iterator returned garbage data");
|
||||
}
|
||||
}
|
||||
|
||||
void BytesTrieTest::checkData(const StringAndValue data[], int32_t dataLength) {
|
||||
logln("checkData(dataLength=%d, fast)", (int)dataLength);
|
||||
checkData(data, dataLength, USTRINGTRIE_BUILD_FAST);
|
||||
|
Loading…
Reference in New Issue
Block a user