2001-08-25 02:03:53 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2014-02-25 21:21:49 +00:00
|
|
|
* Copyright (C) 2001-2014 IBM and others. All rights reserved.
|
2001-08-25 02:03:53 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 03/22/2000 helena Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2008-06-20 22:53:25 +00:00
|
|
|
#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
|
2002-09-20 01:54:48 +00:00
|
|
|
|
2001-11-30 00:06:13 +00:00
|
|
|
#include "unicode/stsearch.h"
|
2002-07-12 21:42:24 +00:00
|
|
|
#include "usrchimp.h"
|
|
|
|
#include "cmemory.h"
|
2001-08-25 02:03:53 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2003-08-31 20:53:46 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(StringSearch)
|
2002-06-29 00:04:16 +00:00
|
|
|
|
2001-08-25 02:03:53 +00:00
|
|
|
// public constructors and destructors -----------------------------------
|
|
|
|
|
2006-08-19 21:27:08 +00:00
|
|
|
StringSearch::StringSearch(const UnicodeString &pattern,
|
2001-08-25 02:03:53 +00:00
|
|
|
const UnicodeString &text,
|
2006-08-19 21:27:08 +00:00
|
|
|
const Locale &locale,
|
2001-08-25 02:03:53 +00:00
|
|
|
BreakIterator *breakiter,
|
|
|
|
UErrorCode &status) :
|
2006-08-19 21:27:08 +00:00
|
|
|
SearchIterator(text, breakiter),
|
2001-08-25 02:03:53 +00:00
|
|
|
m_pattern_(pattern)
|
|
|
|
{
|
2001-11-09 22:42:20 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
m_strsrch_ = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-08-19 21:27:08 +00:00
|
|
|
m_strsrch_ = usearch_open(m_pattern_.getBuffer(), m_pattern_.length(),
|
|
|
|
m_text_.getBuffer(), m_text_.length(),
|
|
|
|
locale.getName(), (UBreakIterator *)breakiter,
|
2002-03-19 21:50:15 +00:00
|
|
|
&status);
|
2001-08-25 02:03:53 +00:00
|
|
|
uprv_free(m_search_);
|
|
|
|
m_search_ = NULL;
|
|
|
|
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
// m_search_ has been created by the base SearchIterator class
|
|
|
|
m_search_ = m_strsrch_->search;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-19 21:27:08 +00:00
|
|
|
StringSearch::StringSearch(const UnicodeString &pattern,
|
2001-08-25 02:03:53 +00:00
|
|
|
const UnicodeString &text,
|
2006-08-19 21:27:08 +00:00
|
|
|
RuleBasedCollator *coll,
|
2001-08-25 02:03:53 +00:00
|
|
|
BreakIterator *breakiter,
|
|
|
|
UErrorCode &status) :
|
2006-08-19 21:27:08 +00:00
|
|
|
SearchIterator(text, breakiter),
|
2001-08-25 02:03:53 +00:00
|
|
|
m_pattern_(pattern)
|
|
|
|
{
|
2001-11-09 22:42:20 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
m_strsrch_ = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
if (coll == NULL) {
|
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
m_strsrch_ = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2006-08-19 21:27:08 +00:00
|
|
|
m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
|
|
|
|
m_pattern_.length(),
|
|
|
|
m_text_.getBuffer(),
|
2014-02-25 21:21:49 +00:00
|
|
|
m_text_.length(), coll->toUCollator(),
|
2006-08-19 21:27:08 +00:00
|
|
|
(UBreakIterator *)breakiter,
|
2002-03-19 21:50:15 +00:00
|
|
|
&status);
|
2001-08-25 02:03:53 +00:00
|
|
|
uprv_free(m_search_);
|
|
|
|
m_search_ = NULL;
|
|
|
|
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
// m_search_ has been created by the base SearchIterator class
|
|
|
|
m_search_ = m_strsrch_->search;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-19 21:27:08 +00:00
|
|
|
StringSearch::StringSearch(const UnicodeString &pattern,
|
2001-08-25 02:03:53 +00:00
|
|
|
CharacterIterator &text,
|
2006-08-19 21:27:08 +00:00
|
|
|
const Locale &locale,
|
2001-08-25 02:03:53 +00:00
|
|
|
BreakIterator *breakiter,
|
|
|
|
UErrorCode &status) :
|
2006-08-19 21:27:08 +00:00
|
|
|
SearchIterator(text, breakiter),
|
2001-08-25 02:03:53 +00:00
|
|
|
m_pattern_(pattern)
|
|
|
|
{
|
2001-11-09 22:42:20 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
m_strsrch_ = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2006-08-19 21:27:08 +00:00
|
|
|
m_strsrch_ = usearch_open(m_pattern_.getBuffer(), m_pattern_.length(),
|
|
|
|
m_text_.getBuffer(), m_text_.length(),
|
|
|
|
locale.getName(), (UBreakIterator *)breakiter,
|
2002-03-19 21:50:15 +00:00
|
|
|
&status);
|
2001-08-25 02:03:53 +00:00
|
|
|
uprv_free(m_search_);
|
|
|
|
m_search_ = NULL;
|
|
|
|
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
// m_search_ has been created by the base SearchIterator class
|
|
|
|
m_search_ = m_strsrch_->search;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringSearch::StringSearch(const UnicodeString &pattern,
|
|
|
|
CharacterIterator &text,
|
2006-08-19 21:27:08 +00:00
|
|
|
RuleBasedCollator *coll,
|
2001-08-25 02:03:53 +00:00
|
|
|
BreakIterator *breakiter,
|
|
|
|
UErrorCode &status) :
|
2006-08-19 21:27:08 +00:00
|
|
|
SearchIterator(text, breakiter),
|
2001-08-25 02:03:53 +00:00
|
|
|
m_pattern_(pattern)
|
|
|
|
{
|
2001-11-09 22:42:20 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
m_strsrch_ = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
if (coll == NULL) {
|
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
m_strsrch_ = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2006-08-19 21:27:08 +00:00
|
|
|
m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
|
|
|
|
m_pattern_.length(),
|
|
|
|
m_text_.getBuffer(),
|
2014-02-25 21:21:49 +00:00
|
|
|
m_text_.length(), coll->toUCollator(),
|
2006-08-19 21:27:08 +00:00
|
|
|
(UBreakIterator *)breakiter,
|
2002-03-19 21:50:15 +00:00
|
|
|
&status);
|
2001-08-25 02:03:53 +00:00
|
|
|
uprv_free(m_search_);
|
|
|
|
m_search_ = NULL;
|
|
|
|
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
// m_search_ has been created by the base SearchIterator class
|
|
|
|
m_search_ = m_strsrch_->search;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringSearch::StringSearch(const StringSearch &that) :
|
|
|
|
SearchIterator(that.m_text_, that.m_breakiterator_),
|
|
|
|
m_pattern_(that.m_pattern_)
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2006-04-02 19:07:50 +00:00
|
|
|
|
|
|
|
// Free m_search_ from the superclass
|
|
|
|
uprv_free(m_search_);
|
|
|
|
m_search_ = NULL;
|
|
|
|
|
2001-08-25 02:03:53 +00:00
|
|
|
if (that.m_strsrch_ == NULL) {
|
2006-04-02 19:07:50 +00:00
|
|
|
// This was not a good copy
|
2001-08-25 02:03:53 +00:00
|
|
|
m_strsrch_ = NULL;
|
|
|
|
}
|
|
|
|
else {
|
2006-04-02 19:07:50 +00:00
|
|
|
// Make a deep copy
|
2006-08-19 21:27:08 +00:00
|
|
|
m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
|
|
|
|
m_pattern_.length(),
|
|
|
|
m_text_.getBuffer(),
|
|
|
|
m_text_.length(),
|
|
|
|
that.m_strsrch_->collator,
|
|
|
|
(UBreakIterator *)that.m_breakiterator_,
|
2002-03-19 21:50:15 +00:00
|
|
|
&status);
|
2006-04-02 19:07:50 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
// m_search_ has been created by the base SearchIterator class
|
|
|
|
m_search_ = m_strsrch_->search;
|
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringSearch::~StringSearch()
|
|
|
|
{
|
2001-08-30 02:58:23 +00:00
|
|
|
if (m_strsrch_ != NULL) {
|
|
|
|
usearch_close(m_strsrch_);
|
|
|
|
m_search_ = NULL;
|
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
|
|
|
|
2003-11-05 21:59:41 +00:00
|
|
|
StringSearch *
|
|
|
|
StringSearch::clone() const {
|
|
|
|
return new StringSearch(*this);
|
|
|
|
}
|
|
|
|
|
2001-08-25 02:03:53 +00:00
|
|
|
// operator overloading ---------------------------------------------
|
|
|
|
StringSearch & StringSearch::operator=(const StringSearch &that)
|
|
|
|
{
|
|
|
|
if ((*this) != that) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
m_text_ = that.m_text_;
|
|
|
|
m_breakiterator_ = that.m_breakiterator_;
|
|
|
|
m_pattern_ = that.m_pattern_;
|
|
|
|
// all m_search_ in the parent class is linked up with m_strsrch_
|
|
|
|
usearch_close(m_strsrch_);
|
2006-08-19 21:27:08 +00:00
|
|
|
m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
|
|
|
|
m_pattern_.length(),
|
|
|
|
m_text_.getBuffer(),
|
|
|
|
m_text_.length(),
|
|
|
|
that.m_strsrch_->collator,
|
2001-08-25 02:03:53 +00:00
|
|
|
NULL, &status);
|
2008-01-16 17:00:55 +00:00
|
|
|
// Check null pointer
|
|
|
|
if (m_strsrch_ != NULL) {
|
2014-02-25 21:21:49 +00:00
|
|
|
m_search_ = m_strsrch_->search;
|
2008-01-16 17:00:55 +00:00
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool StringSearch::operator==(const SearchIterator &that) const
|
|
|
|
{
|
|
|
|
if (this == &that) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (SearchIterator::operator ==(that)) {
|
|
|
|
StringSearch &thatsrch = (StringSearch &)that;
|
|
|
|
return (this->m_pattern_ == thatsrch.m_pattern_ &&
|
|
|
|
this->m_strsrch_->collator == thatsrch.m_strsrch_->collator);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// public get and set methods ----------------------------------------
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
void StringSearch::setOffset(int32_t position, UErrorCode &status)
|
2001-08-25 02:03:53 +00:00
|
|
|
{
|
2001-11-09 22:42:20 +00:00
|
|
|
// status checked in usearch_setOffset
|
2001-08-25 02:03:53 +00:00
|
|
|
usearch_setOffset(m_strsrch_, position, &status);
|
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t StringSearch::getOffset(void) const
|
2001-08-25 02:03:53 +00:00
|
|
|
{
|
|
|
|
return usearch_getOffset(m_strsrch_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StringSearch::setText(const UnicodeString &text, UErrorCode &status)
|
|
|
|
{
|
2001-11-09 22:42:20 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
m_text_ = text;
|
2002-03-13 03:18:11 +00:00
|
|
|
usearch_setText(m_strsrch_, text.getBuffer(), text.length(), &status);
|
2001-11-09 22:42:20 +00:00
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
2006-08-19 21:27:08 +00:00
|
|
|
|
2001-08-25 02:03:53 +00:00
|
|
|
void StringSearch::setText(CharacterIterator &text, UErrorCode &status)
|
|
|
|
{
|
2001-11-09 22:42:20 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
text.getText(m_text_);
|
2002-03-13 03:18:11 +00:00
|
|
|
usearch_setText(m_strsrch_, m_text_.getBuffer(), m_text_.length(), &status);
|
2001-11-09 22:42:20 +00:00
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RuleBasedCollator * StringSearch::getCollator() const
|
|
|
|
{
|
2014-02-25 21:21:49 +00:00
|
|
|
// Note the const_cast. It would be cleaner if this const method returned a const collator.
|
|
|
|
return RuleBasedCollator::rbcFromUCollator(const_cast<UCollator *>(m_strsrch_->collator));
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
2006-08-19 21:27:08 +00:00
|
|
|
|
2001-08-25 02:03:53 +00:00
|
|
|
void StringSearch::setCollator(RuleBasedCollator *coll, UErrorCode &status)
|
|
|
|
{
|
2001-11-09 22:42:20 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
2014-02-25 21:21:49 +00:00
|
|
|
usearch_setCollator(m_strsrch_, coll->toUCollator(), &status);
|
2001-11-09 22:42:20 +00:00
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
2006-08-19 21:27:08 +00:00
|
|
|
|
|
|
|
void StringSearch::setPattern(const UnicodeString &pattern,
|
2001-08-25 02:03:53 +00:00
|
|
|
UErrorCode &status)
|
|
|
|
{
|
2001-11-09 22:42:20 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
m_pattern_ = pattern;
|
2002-03-13 03:18:11 +00:00
|
|
|
usearch_setPattern(m_strsrch_, m_pattern_.getBuffer(), m_pattern_.length(),
|
2001-11-09 22:42:20 +00:00
|
|
|
&status);
|
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
2006-08-19 21:27:08 +00:00
|
|
|
|
2001-08-25 02:03:53 +00:00
|
|
|
const UnicodeString & StringSearch::getPattern() const
|
|
|
|
{
|
|
|
|
return m_pattern_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// public methods ----------------------------------------------------
|
|
|
|
|
|
|
|
void StringSearch::reset()
|
|
|
|
{
|
|
|
|
usearch_reset(m_strsrch_);
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchIterator * StringSearch::safeClone(void) const
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2006-08-19 21:27:08 +00:00
|
|
|
StringSearch *result = new StringSearch(m_pattern_, m_text_,
|
2014-02-25 21:21:49 +00:00
|
|
|
getCollator(),
|
2001-08-25 02:03:53 +00:00
|
|
|
m_breakiterator_,
|
|
|
|
status);
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (result == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
result->setOffset(getOffset(), status);
|
|
|
|
result->setMatchStart(m_strsrch_->search->matchedIndex);
|
|
|
|
result->setMatchLength(m_strsrch_->search->matchedLength);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2006-08-19 21:27:08 +00:00
|
|
|
|
2001-08-25 02:03:53 +00:00
|
|
|
// protected method -------------------------------------------------
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t StringSearch::handleNext(int32_t position, UErrorCode &status)
|
2001-08-25 02:03:53 +00:00
|
|
|
{
|
|
|
|
// values passed here are already in the pre-shift position
|
|
|
|
if (U_SUCCESS(status)) {
|
2014-08-20 23:55:04 +00:00
|
|
|
if (m_strsrch_->pattern.cesLength == 0) {
|
2006-08-19 21:27:08 +00:00
|
|
|
m_search_->matchedIndex =
|
|
|
|
m_search_->matchedIndex == USEARCH_DONE ?
|
2001-08-25 02:03:53 +00:00
|
|
|
getOffset() : m_search_->matchedIndex + 1;
|
|
|
|
m_search_->matchedLength = 0;
|
2006-08-19 21:27:08 +00:00
|
|
|
ucol_setOffset(m_strsrch_->textIter, m_search_->matchedIndex,
|
2001-08-25 02:03:53 +00:00
|
|
|
&status);
|
|
|
|
if (m_search_->matchedIndex == m_search_->textLength) {
|
|
|
|
m_search_->matchedIndex = USEARCH_DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2006-08-19 21:27:08 +00:00
|
|
|
// looking at usearch.cpp, this part is shifted out to
|
2001-08-25 02:03:53 +00:00
|
|
|
// StringSearch instead of SearchIterator because m_strsrch_ is
|
|
|
|
// not accessible in SearchIterator
|
2008-05-23 04:22:28 +00:00
|
|
|
#if 0
|
2006-08-19 21:27:08 +00:00
|
|
|
if (position + m_strsrch_->pattern.defaultShiftSize
|
2004-11-11 23:34:58 +00:00
|
|
|
> m_search_->textLength) {
|
2001-08-25 02:03:53 +00:00
|
|
|
setMatchNotFound();
|
|
|
|
return USEARCH_DONE;
|
|
|
|
}
|
2008-05-23 04:22:28 +00:00
|
|
|
#endif
|
2003-07-08 02:02:17 +00:00
|
|
|
if (m_search_->matchedLength <= 0) {
|
2006-08-19 21:27:08 +00:00
|
|
|
// the flipping direction issue has already been handled
|
2003-07-08 02:02:17 +00:00
|
|
|
// in next()
|
|
|
|
// for boundary check purposes. this will ensure that the
|
|
|
|
// next match will not preceed the current offset
|
|
|
|
// note search->matchedIndex will always be set to something
|
|
|
|
// in the code
|
|
|
|
m_search_->matchedIndex = position - 1;
|
|
|
|
}
|
|
|
|
|
2004-11-11 23:34:58 +00:00
|
|
|
ucol_setOffset(m_strsrch_->textIter, position, &status);
|
2008-05-23 04:22:28 +00:00
|
|
|
|
|
|
|
#if 0
|
2006-12-19 06:06:30 +00:00
|
|
|
for (;;) {
|
2001-08-25 02:03:53 +00:00
|
|
|
if (m_search_->isCanonicalMatch) {
|
|
|
|
// can't use exact here since extra accents are allowed.
|
|
|
|
usearch_handleNextCanonical(m_strsrch_, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usearch_handleNextExact(m_strsrch_, &status);
|
|
|
|
}
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return USEARCH_DONE;
|
|
|
|
}
|
2002-09-20 01:54:48 +00:00
|
|
|
if (m_breakiterator_ == NULL
|
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
2006-08-19 21:27:08 +00:00
|
|
|
||
|
2001-08-25 02:03:53 +00:00
|
|
|
m_search_->matchedIndex == USEARCH_DONE ||
|
|
|
|
(m_breakiterator_->isBoundary(m_search_->matchedIndex) &&
|
2006-08-19 21:27:08 +00:00
|
|
|
m_breakiterator_->isBoundary(m_search_->matchedIndex +
|
2002-09-20 01:54:48 +00:00
|
|
|
m_search_->matchedLength))
|
|
|
|
#endif
|
|
|
|
) {
|
2003-08-31 20:53:46 +00:00
|
|
|
if (m_search_->matchedIndex == USEARCH_DONE) {
|
2006-08-19 21:27:08 +00:00
|
|
|
ucol_setOffset(m_strsrch_->textIter,
|
2003-08-31 20:53:46 +00:00
|
|
|
m_search_->textLength, &status);
|
|
|
|
}
|
|
|
|
else {
|
2006-08-19 21:27:08 +00:00
|
|
|
ucol_setOffset(m_strsrch_->textIter,
|
2003-08-31 20:53:46 +00:00
|
|
|
m_search_->matchedIndex, &status);
|
|
|
|
}
|
2001-08-25 02:03:53 +00:00
|
|
|
return m_search_->matchedIndex;
|
|
|
|
}
|
|
|
|
}
|
2008-05-23 04:22:28 +00:00
|
|
|
#else
|
|
|
|
// if m_strsrch_->breakIter is always the same as m_breakiterator_
|
|
|
|
// then we don't need to check the match boundaries here because
|
|
|
|
// usearch_handleNextXXX will already have done it.
|
|
|
|
if (m_search_->isCanonicalMatch) {
|
|
|
|
// *could* actually use exact here 'cause no extra accents allowed...
|
|
|
|
usearch_handleNextCanonical(m_strsrch_, &status);
|
|
|
|
} else {
|
|
|
|
usearch_handleNextExact(m_strsrch_, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return USEARCH_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_search_->matchedIndex == USEARCH_DONE) {
|
|
|
|
ucol_setOffset(m_strsrch_->textIter, m_search_->textLength, &status);
|
|
|
|
} else {
|
|
|
|
ucol_setOffset(m_strsrch_->textIter, m_search_->matchedIndex, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_search_->matchedIndex;
|
|
|
|
#endif
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return USEARCH_DONE;
|
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t StringSearch::handlePrev(int32_t position, UErrorCode &status)
|
2001-08-25 02:03:53 +00:00
|
|
|
{
|
|
|
|
// values passed here are already in the pre-shift position
|
|
|
|
if (U_SUCCESS(status)) {
|
2014-08-20 23:55:04 +00:00
|
|
|
if (m_strsrch_->pattern.cesLength == 0) {
|
2006-08-19 21:27:08 +00:00
|
|
|
m_search_->matchedIndex =
|
|
|
|
(m_search_->matchedIndex == USEARCH_DONE ? getOffset() :
|
2001-08-25 02:03:53 +00:00
|
|
|
m_search_->matchedIndex);
|
|
|
|
if (m_search_->matchedIndex == 0) {
|
|
|
|
setMatchNotFound();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_search_->matchedIndex --;
|
2006-08-19 21:27:08 +00:00
|
|
|
ucol_setOffset(m_strsrch_->textIter, m_search_->matchedIndex,
|
2001-08-25 02:03:53 +00:00
|
|
|
&status);
|
|
|
|
m_search_->matchedLength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2006-08-19 21:27:08 +00:00
|
|
|
// looking at usearch.cpp, this part is shifted out to
|
2001-08-25 02:03:53 +00:00
|
|
|
// StringSearch instead of SearchIterator because m_strsrch_ is
|
|
|
|
// not accessible in SearchIterator
|
2008-05-23 04:22:28 +00:00
|
|
|
#if 0
|
2006-08-19 21:27:08 +00:00
|
|
|
if (!m_search_->isOverlap &&
|
2001-08-25 02:03:53 +00:00
|
|
|
position - m_strsrch_->pattern.defaultShiftSize < 0) {
|
|
|
|
setMatchNotFound();
|
|
|
|
return USEARCH_DONE;
|
|
|
|
}
|
2008-05-23 04:22:28 +00:00
|
|
|
|
2006-12-19 06:06:30 +00:00
|
|
|
for (;;) {
|
2001-08-25 02:03:53 +00:00
|
|
|
if (m_search_->isCanonicalMatch) {
|
|
|
|
// can't use exact here since extra accents are allowed.
|
|
|
|
usearch_handlePreviousCanonical(m_strsrch_, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
usearch_handlePreviousExact(m_strsrch_, &status);
|
|
|
|
}
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return USEARCH_DONE;
|
|
|
|
}
|
2002-09-20 01:54:48 +00:00
|
|
|
if (m_breakiterator_ == NULL
|
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
2006-08-19 21:27:08 +00:00
|
|
|
||
|
2001-08-25 02:03:53 +00:00
|
|
|
m_search_->matchedIndex == USEARCH_DONE ||
|
|
|
|
(m_breakiterator_->isBoundary(m_search_->matchedIndex) &&
|
2006-08-19 21:27:08 +00:00
|
|
|
m_breakiterator_->isBoundary(m_search_->matchedIndex +
|
2002-09-20 01:54:48 +00:00
|
|
|
m_search_->matchedLength))
|
|
|
|
#endif
|
|
|
|
) {
|
2001-08-25 02:03:53 +00:00
|
|
|
return m_search_->matchedIndex;
|
|
|
|
}
|
|
|
|
}
|
2008-05-23 04:22:28 +00:00
|
|
|
#else
|
|
|
|
ucol_setOffset(m_strsrch_->textIter, position, &status);
|
|
|
|
|
|
|
|
if (m_search_->isCanonicalMatch) {
|
|
|
|
// *could* use exact match here since extra accents *not* allowed!
|
|
|
|
usearch_handlePreviousCanonical(m_strsrch_, &status);
|
|
|
|
} else {
|
|
|
|
usearch_handlePreviousExact(m_strsrch_, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return USEARCH_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_search_->matchedIndex;
|
|
|
|
#endif
|
2001-08-25 02:03:53 +00:00
|
|
|
}
|
2006-08-19 21:27:08 +00:00
|
|
|
|
2001-08-25 02:03:53 +00:00
|
|
|
return m_search_->matchedIndex;
|
|
|
|
}
|
|
|
|
return USEARCH_DONE;
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
2001-08-25 02:03:53 +00:00
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_COLLATION */
|