mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-12 16:33:23 +00:00
ICU-1004
jitterbug 1030: Cleaned code. Commented where error status is bing checked in. X-SVN-Rev: 6717
This commit is contained in:
parent
8aa90802ac
commit
3878e1780a
4 changed files with 61 additions and 13 deletions
|
@ -161,6 +161,9 @@ UBool SearchIterator::operator==(const SearchIterator &that) const
|
|||
|
||||
UTextOffset SearchIterator::first(UErrorCode &status)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
return USEARCH_DONE;
|
||||
}
|
||||
setOffset(0, status);
|
||||
return handleNext(0, status);
|
||||
}
|
||||
|
@ -168,12 +171,18 @@ UTextOffset SearchIterator::first(UErrorCode &status)
|
|||
UTextOffset SearchIterator::following(UTextOffset position,
|
||||
UErrorCode &status)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
return USEARCH_DONE;
|
||||
}
|
||||
setOffset(position, status);
|
||||
return handleNext(position, status);
|
||||
}
|
||||
|
||||
UTextOffset SearchIterator::last(UErrorCode &status)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
return USEARCH_DONE;
|
||||
}
|
||||
setOffset(m_search_->textLength, status);
|
||||
return handlePrev(m_search_->textLength, status);
|
||||
}
|
||||
|
@ -181,6 +190,9 @@ UTextOffset SearchIterator::last(UErrorCode &status)
|
|||
UTextOffset SearchIterator::preceding(UTextOffset position,
|
||||
UErrorCode &status)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
return USEARCH_DONE;
|
||||
}
|
||||
setOffset(position, status);
|
||||
return handlePrev(position, status);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,11 @@ StringSearch::StringSearch(const UnicodeString &pattern,
|
|||
m_collator_(),
|
||||
m_pattern_(pattern)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
m_strsrch_ = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
m_strsrch_ = usearch_open(m_pattern_.fArray, m_pattern_.fLength,
|
||||
m_text_.fArray, m_text_.fLength,
|
||||
locale.getName(), NULL, &status);
|
||||
|
@ -50,6 +55,10 @@ StringSearch::StringSearch(const UnicodeString &pattern,
|
|||
m_collator_(),
|
||||
m_pattern_(pattern)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
m_strsrch_ = NULL;
|
||||
return;
|
||||
}
|
||||
if (coll == NULL) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
m_strsrch_ = NULL;
|
||||
|
@ -82,6 +91,10 @@ StringSearch::StringSearch(const UnicodeString &pattern,
|
|||
m_collator_(),
|
||||
m_pattern_(pattern)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
m_strsrch_ = NULL;
|
||||
return;
|
||||
}
|
||||
m_strsrch_ = usearch_open(m_pattern_.fArray, m_pattern_.fLength,
|
||||
m_text_.fArray, m_text_.fLength,
|
||||
locale.getName(), NULL, &status);
|
||||
|
@ -108,6 +121,10 @@ StringSearch::StringSearch(const UnicodeString &pattern,
|
|||
m_collator_(),
|
||||
m_pattern_(pattern)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
m_strsrch_ = NULL;
|
||||
return;
|
||||
}
|
||||
if (coll == NULL) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
m_strsrch_ = NULL;
|
||||
|
@ -152,7 +169,7 @@ StringSearch::StringSearch(const StringSearch &that) :
|
|||
m_search_ = NULL;
|
||||
|
||||
if (U_SUCCESS(status)) {
|
||||
int32_t length;
|
||||
int32_t length;
|
||||
const UChar *rules = ucol_getRules(m_strsrch_->collator, &length);
|
||||
m_collation_rules_.setTo(rules, length);
|
||||
m_collator_.setUCollator((UCollator *)m_strsrch_->collator,
|
||||
|
@ -214,6 +231,7 @@ UBool StringSearch::operator==(const SearchIterator &that) const
|
|||
|
||||
void StringSearch::setOffset(UTextOffset position, UErrorCode &status)
|
||||
{
|
||||
// status checked in usearch_setOffset
|
||||
usearch_setOffset(m_strsrch_, position, &status);
|
||||
}
|
||||
|
||||
|
@ -224,14 +242,18 @@ UTextOffset StringSearch::getOffset(void) const
|
|||
|
||||
void StringSearch::setText(const UnicodeString &text, UErrorCode &status)
|
||||
{
|
||||
m_text_ = text;
|
||||
usearch_setText(m_strsrch_, text.fArray, text.fLength, &status);
|
||||
if (U_SUCCESS(status)) {
|
||||
m_text_ = text;
|
||||
usearch_setText(m_strsrch_, text.fArray, text.fLength, &status);
|
||||
}
|
||||
}
|
||||
|
||||
void StringSearch::setText(CharacterIterator &text, UErrorCode &status)
|
||||
{
|
||||
text.getText(m_text_);
|
||||
usearch_setText(m_strsrch_, m_text_.fArray, m_text_.fLength, &status);
|
||||
if (U_SUCCESS(status)) {
|
||||
text.getText(m_text_);
|
||||
usearch_setText(m_strsrch_, m_text_.fArray, m_text_.fLength, &status);
|
||||
}
|
||||
}
|
||||
|
||||
RuleBasedCollator * StringSearch::getCollator() const
|
||||
|
@ -241,18 +263,22 @@ RuleBasedCollator * StringSearch::getCollator() const
|
|||
|
||||
void StringSearch::setCollator(RuleBasedCollator *coll, UErrorCode &status)
|
||||
{
|
||||
usearch_setCollator(m_strsrch_, coll->getUCollator(), &status);
|
||||
m_collation_rules_.setTo(coll->getRules());
|
||||
m_collator_.setUCollator((UCollator *)m_strsrch_->collator,
|
||||
&m_collation_rules_);
|
||||
if (U_SUCCESS(status)) {
|
||||
usearch_setCollator(m_strsrch_, coll->getUCollator(), &status);
|
||||
m_collation_rules_.setTo(coll->getRules());
|
||||
m_collator_.setUCollator((UCollator *)m_strsrch_->collator,
|
||||
&m_collation_rules_);
|
||||
}
|
||||
}
|
||||
|
||||
void StringSearch::setPattern(const UnicodeString &pattern,
|
||||
UErrorCode &status)
|
||||
{
|
||||
m_pattern_ = pattern;
|
||||
usearch_setPattern(m_strsrch_, m_pattern_.fArray, m_pattern_.fLength,
|
||||
&status);
|
||||
if (U_SUCCESS(status)) {
|
||||
m_pattern_ = pattern;
|
||||
usearch_setPattern(m_strsrch_, m_pattern_.fArray, m_pattern_.fLength,
|
||||
&status);
|
||||
}
|
||||
}
|
||||
|
||||
const UnicodeString & StringSearch::getPattern() const
|
||||
|
|
|
@ -445,6 +445,8 @@ protected:
|
|||
* @param position The index in the target text at which the search
|
||||
* should start.
|
||||
* @param status for error codes if it occurs.
|
||||
* @return index at which the match starts, else if match is not found
|
||||
* USEARCH_DONE is returned
|
||||
*/
|
||||
virtual UTextOffset handleNext(UTextOffset position, UErrorCode &status)
|
||||
= 0;
|
||||
|
@ -463,6 +465,8 @@ protected:
|
|||
* @param position The index in the target text at which the search
|
||||
* should start.
|
||||
* @param status for error codes if it occurs.
|
||||
* @return index at which the match starts, else if match is not found
|
||||
* USEARCH_DONE is returned
|
||||
*/
|
||||
virtual UTextOffset handlePrev(UTextOffset position, UErrorCode &status)
|
||||
= 0;
|
||||
|
|
|
@ -2343,6 +2343,9 @@ U_CAPI UStringSearch * U_EXPORT2 usearch_open(const UChar *pattern,
|
|||
UBreakIterator *breakiter,
|
||||
UErrorCode *status)
|
||||
{
|
||||
if (U_FAILURE(*status)) {
|
||||
return NULL;
|
||||
}
|
||||
if (locale) {
|
||||
// ucol_open internally checks for status
|
||||
UCollator *collator = ucol_open(locale, status);
|
||||
|
@ -2375,6 +2378,9 @@ U_CAPI UStringSearch * U_EXPORT2 usearch_openFromCollator(
|
|||
UBreakIterator *breakiter,
|
||||
UErrorCode *status)
|
||||
{
|
||||
if (U_FAILURE(*status)) {
|
||||
return NULL;
|
||||
}
|
||||
if (pattern == NULL || text == NULL || collator == NULL) {
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
}
|
||||
|
@ -2614,7 +2620,7 @@ U_CAPI void U_EXPORT2 usearch_setBreakIterator(UStringSearch *strsrch,
|
|||
UBreakIterator *breakiter,
|
||||
UErrorCode *status)
|
||||
{
|
||||
if (strsrch) {
|
||||
if (U_SUCCESS(*status) && strsrch) {
|
||||
strsrch->search->breakIter = breakiter;
|
||||
if (breakiter) {
|
||||
ubrk_setText(breakiter, strsrch->search->text,
|
||||
|
|
Loading…
Add table
Reference in a new issue