search.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (C) 2001-2011 IBM and others. All rights reserved.
**********************************************************************
* Date Name Description
* 03/22/2000 helena Creation.
**********************************************************************
*/
#ifndef SEARCH_H
#define SEARCH_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
#include "unicode/uobject.h"
#include "unicode/unistr.h"
#include "unicode/chariter.h"
#include "unicode/brkiter.h"
#include "unicode/usearch.h"
struct USearch;
typedef struct USearch USearch;
U_NAMESPACE_BEGIN
class U_I18N_API SearchIterator : public UObject {
public:
// public constructors and destructors -------------------------------
SearchIterator(const SearchIterator &other);
virtual ~SearchIterator();
// public get and set methods ----------------------------------------
virtual void setOffset(int32_t position, UErrorCode &status) = 0;
virtual int32_t getOffset(void) const = 0;
void setAttribute(USearchAttribute attribute,
USearchAttributeValue value,
UErrorCode &status);
USearchAttributeValue getAttribute(USearchAttribute attribute) const;
int32_t getMatchedStart(void) const;
int32_t getMatchedLength(void) const;
void getMatchedText(UnicodeString &result) const;
void setBreakIterator(BreakIterator *breakiter, UErrorCode &status);
const BreakIterator * getBreakIterator(void) const;
virtual void setText(const UnicodeString &text, UErrorCode &status);
virtual void setText(CharacterIterator &text, UErrorCode &status);
const UnicodeString & getText(void) const;
// operator overloading ----------------------------------------------
virtual bool operator==(const SearchIterator &that) const;
bool operator!=(const SearchIterator &that) const;
// public methods ----------------------------------------------------
virtual SearchIterator* safeClone(void) const = 0;
int32_t first(UErrorCode &status);
int32_t following(int32_t position, UErrorCode &status);
int32_t last(UErrorCode &status);
int32_t preceding(int32_t position, UErrorCode &status);
int32_t next(UErrorCode &status);
int32_t previous(UErrorCode &status);
virtual void reset();
protected:
// protected data members ---------------------------------------------
USearch *m_search_;
BreakIterator *m_breakiterator_;
UnicodeString m_text_;
// protected constructors and destructors -----------------------------
SearchIterator();
SearchIterator(const UnicodeString &text,
BreakIterator *breakiter = nullptr);
SearchIterator(CharacterIterator &text, BreakIterator *breakiter = nullptr);
// protected methods --------------------------------------------------
SearchIterator & operator=(const SearchIterator &that);
virtual int32_t handleNext(int32_t position, UErrorCode &status)
= 0;
virtual int32_t handlePrev(int32_t position, UErrorCode &status)
= 0;
virtual void setMatchLength(int32_t length);
virtual void setMatchStart(int32_t position);
void setMatchNotFound();
};
inline bool SearchIterator::operator!=(const SearchIterator &that) const
{
return !operator==(that);
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_COLLATION */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif
brkiter.h
C++ API: Break Iterator.
chariter.h
C++ API: Character Iterator.
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition: brkiter.h:106
icu::CharacterIterator
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:361
icu::SearchIterator
SearchIterator is an abstract base class that provides methods to search for a pattern within a text ...
Definition: search.h:82
icu::SearchIterator::m_search_
USearch * m_search_
C search data struct.
Definition: search.h:418
icu::SearchIterator::getMatchedLength
int32_t getMatchedLength(void) const
Returns the length of text in the string which matches the search pattern.
icu::SearchIterator::SearchIterator
SearchIterator(CharacterIterator &text, BreakIterator *breakiter=nullptr)
Constructor for use by subclasses.
icu::SearchIterator::SearchIterator
SearchIterator(const SearchIterator &other)
Copy constructor that creates a SearchIterator instance with the same behavior, and iterating over th...
icu::SearchIterator::operator=
SearchIterator & operator=(const SearchIterator &that)
Assignment operator.
icu::SearchIterator::next
int32_t next(UErrorCode &status)
Returns the index of the next point at which the text matches the search pattern, starting from the c...
icu::SearchIterator::setMatchLength
virtual void setMatchLength(int32_t length)
Sets the length of the currently matched string in the text string to be searched.
icu::SearchIterator::getBreakIterator
const BreakIterator * getBreakIterator(void) const
Returns the BreakIterator that is used to restrict the points at which matches are detected.
icu::SearchIterator::first
int32_t first(UErrorCode &status)
Returns the first index at which the string text matches the search pattern.
icu::SearchIterator::setAttribute
void setAttribute(USearchAttribute attribute, USearchAttributeValue value, UErrorCode &status)
Sets the text searching attributes located in the enum USearchAttribute with values from the enum USe...
icu::SearchIterator::handleNext
virtual int32_t handleNext(int32_t position, UErrorCode &status)=0
Abstract method which subclasses override to provide the mechanism for finding the next match in the ...
icu::SearchIterator::previous
int32_t previous(UErrorCode &status)
Returns the index of the previous point at which the string text matches the search pattern,...
icu::SearchIterator::preceding
int32_t preceding(int32_t position, UErrorCode &status)
Returns the first index less than position at which the string text matches the search pattern.
icu::SearchIterator::last
int32_t last(UErrorCode &status)
Returns the last index in the target text at which it matches the search pattern.
icu::SearchIterator::getOffset
virtual int32_t getOffset(void) const =0
Return the current index in the text being searched.
icu::SearchIterator::safeClone
virtual SearchIterator * safeClone(void) const =0
Returns a copy of SearchIterator with the same behavior, and iterating over the same text,...
icu::SearchIterator::getMatchedStart
int32_t getMatchedStart(void) const
Returns the index to the match in the text string that was searched.
icu::SearchIterator::setText
virtual void setText(const UnicodeString &text, UErrorCode &status)
Set the string text to be searched.
icu::SearchIterator::SearchIterator
SearchIterator()
Default constructor.
icu::SearchIterator::m_text_
UnicodeString m_text_
Unicode string version of the search text.
Definition: search.h:434
icu::SearchIterator::setMatchStart
virtual void setMatchStart(int32_t position)
Sets the offset of the currently matched string in the text string to be searched.
icu::SearchIterator::setMatchNotFound
void setMatchNotFound()
sets match not found
icu::SearchIterator::following
int32_t following(int32_t position, UErrorCode &status)
Returns the first index equal or greater than position at which the string text matches the search pa...
icu::SearchIterator::reset
virtual void reset()
Resets the iteration.
icu::SearchIterator::setBreakIterator
void setBreakIterator(BreakIterator *breakiter, UErrorCode &status)
Set the BreakIterator that will be used to restrict the points at which matches are detected.
icu::SearchIterator::getMatchedText
void getMatchedText(UnicodeString &result) const
Returns the text that was matched by the most recent call to first, next, previous,...
icu::SearchIterator::getText
const UnicodeString & getText(void) const
Return the string text to be searched.
icu::SearchIterator::m_breakiterator_
BreakIterator * m_breakiterator_
Break iterator.
Definition: search.h:428
icu::SearchIterator::operator==
virtual bool operator==(const SearchIterator &that) const
Equality operator.
icu::SearchIterator::handlePrev
virtual int32_t handlePrev(int32_t position, UErrorCode &status)=0
Abstract method which subclasses override to provide the mechanism for finding the previous match in ...
icu::SearchIterator::getAttribute
USearchAttributeValue getAttribute(USearchAttribute attribute) const
Gets the text searching attributes.
icu::SearchIterator::setOffset
virtual void setOffset(int32_t position, UErrorCode &status)=0
Sets the index to point to the given position, and clears any state that's affected.
icu::SearchIterator::setText
virtual void setText(CharacterIterator &text, UErrorCode &status)
Set the string text to be searched.
icu::SearchIterator::SearchIterator
SearchIterator(const UnicodeString &text, BreakIterator *breakiter=nullptr)
Constructor for use by subclasses.
icu::SearchIterator::~SearchIterator
virtual ~SearchIterator()
Destructor.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
USearch
struct USearch USearch
Definition: search.h:39
unistr.h
C++ API: Unicode String.
uobject.h
C++ API: Common ICU base class UObject.
usearch.h
C API: StringSearch.
USearchAttribute
USearchAttribute
Definition: usearch.h:167
USearchAttributeValue
USearchAttributeValue
Definition: usearch.h:209
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301