+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
-* Copyright (C) 2001-2008 IBM and others. All rights reserved.
+* Copyright (C) 2001-2014 IBM and others. All rights reserved.
**********************************************************************
* Date Name Description
* 03/22/2000 helena Creation.
BreakIterator *breakiter,
UErrorCode &status) :
SearchIterator(text, breakiter),
- m_collator_(),
m_pattern_(pattern)
{
if (U_FAILURE(status)) {
uprv_free(m_search_);
m_search_ = NULL;
- // !!! dlf m_collator_ is an odd beast. basically it is an aliasing
- // wrapper around the internal collator and rules, which (here) are
- // owned by this stringsearch object. this means 1) it's destructor
- // _should not_ delete the ucollator or rules, and 2) changes made
- // to the exposed collator (setStrength etc) _should_ modify the
- // ucollator. thus the collator is not a copy-on-write alias, and it
- // needs to distinguish itself not merely from 'stand alone' colators
- // but also from copy-on-write ones. it needs additional state, which
- // setUCollator should set.
-
if (U_SUCCESS(status)) {
- // Alias the collator
- m_collator_.setUCollator((UCollator *)m_strsrch_->collator);
// m_search_ has been created by the base SearchIterator class
m_search_ = m_strsrch_->search;
}
BreakIterator *breakiter,
UErrorCode &status) :
SearchIterator(text, breakiter),
- m_collator_(),
m_pattern_(pattern)
{
if (U_FAILURE(status)) {
m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
m_pattern_.length(),
m_text_.getBuffer(),
- m_text_.length(), coll->ucollator,
+ m_text_.length(), coll->toUCollator(),
(UBreakIterator *)breakiter,
&status);
uprv_free(m_search_);
m_search_ = NULL;
if (U_SUCCESS(status)) {
- // Alias the collator
- m_collator_.setUCollator((UCollator *)m_strsrch_->collator);
// m_search_ has been created by the base SearchIterator class
m_search_ = m_strsrch_->search;
}
BreakIterator *breakiter,
UErrorCode &status) :
SearchIterator(text, breakiter),
- m_collator_(),
m_pattern_(pattern)
{
if (U_FAILURE(status)) {
m_search_ = NULL;
if (U_SUCCESS(status)) {
- // Alias the collator
- m_collator_.setUCollator((UCollator *)m_strsrch_->collator);
// m_search_ has been created by the base SearchIterator class
m_search_ = m_strsrch_->search;
}
BreakIterator *breakiter,
UErrorCode &status) :
SearchIterator(text, breakiter),
- m_collator_(),
m_pattern_(pattern)
{
if (U_FAILURE(status)) {
m_strsrch_ = usearch_openFromCollator(m_pattern_.getBuffer(),
m_pattern_.length(),
m_text_.getBuffer(),
- m_text_.length(), coll->ucollator,
+ m_text_.length(), coll->toUCollator(),
(UBreakIterator *)breakiter,
&status);
uprv_free(m_search_);
m_search_ = NULL;
if (U_SUCCESS(status)) {
- // Alias the collator
- m_collator_.setUCollator((UCollator *)m_strsrch_->collator);
// 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_collator_(),
m_pattern_(that.m_pattern_)
{
UErrorCode status = U_ZERO_ERROR;
(UBreakIterator *)that.m_breakiterator_,
&status);
if (U_SUCCESS(status)) {
- // Alias the collator
- m_collator_.setUCollator((UCollator *)m_strsrch_->collator);
// m_search_ has been created by the base SearchIterator class
m_search_ = m_strsrch_->search;
}
NULL, &status);
// Check null pointer
if (m_strsrch_ != NULL) {
- // Alias the collator
- m_collator_.setUCollator((UCollator *)m_strsrch_->collator);
- m_search_ = m_strsrch_->search;
+ m_search_ = m_strsrch_->search;
}
}
return *this;
RuleBasedCollator * StringSearch::getCollator() const
{
- return (RuleBasedCollator *)&m_collator_;
+ // 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));
}
void StringSearch::setCollator(RuleBasedCollator *coll, UErrorCode &status)
{
if (U_SUCCESS(status)) {
- usearch_setCollator(m_strsrch_, coll->getUCollator(), &status);
- // Alias the collator
- m_collator_.setUCollator((UCollator *)m_strsrch_->collator);
+ usearch_setCollator(m_strsrch_, coll->toUCollator(), &status);
}
}
{
UErrorCode status = U_ZERO_ERROR;
StringSearch *result = new StringSearch(m_pattern_, m_text_,
- (RuleBasedCollator *)&m_collator_,
+ getCollator(),
m_breakiterator_,
status);
/* test for NULL */
{
// values passed here are already in the pre-shift position
if (U_SUCCESS(status)) {
- if (m_strsrch_->pattern.CELength == 0) {
+ if (m_strsrch_->pattern.cesLength == 0) {
m_search_->matchedIndex =
m_search_->matchedIndex == USEARCH_DONE ?
getOffset() : m_search_->matchedIndex + 1;
{
// values passed here are already in the pre-shift position
if (U_SUCCESS(status)) {
- if (m_strsrch_->pattern.CELength == 0) {
+ if (m_strsrch_->pattern.cesLength == 0) {
m_search_->matchedIndex =
(m_search_->matchedIndex == USEARCH_DONE ? getOffset() :
m_search_->matchedIndex);