ICU 72.1 72.1

search.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 * Copyright (C) 2001-2011 IBM and others. All rights reserved.
6 **********************************************************************
7 * Date Name Description
8 * 03/22/2000 helena Creation.
9 **********************************************************************
10 */
11
12 #ifndef SEARCH_H
13 #define SEARCH_H
14
15 #include "unicode/utypes.h"
16
17 #if U_SHOW_CPLUSPLUS_API
18
24 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
25
26 #include "unicode/uobject.h"
27 #include "unicode/unistr.h"
28 #include "unicode/chariter.h"
29 #include "unicode/brkiter.h"
30 #include "unicode/usearch.h"
31
35 struct USearch;
39 typedef struct USearch USearch;
40
41 U_NAMESPACE_BEGIN
42
82 class U_I18N_API SearchIterator : public UObject {
83
84 public:
85
86 // public constructors and destructors -------------------------------
87
94 SearchIterator(const SearchIterator &other);
95
100 virtual ~SearchIterator();
101
102 // public get and set methods ----------------------------------------
103
117 virtual void setOffset(int32_t position, UErrorCode &status) = 0;
118
127 virtual int32_t getOffset(void) const = 0;
128
138 void setAttribute(USearchAttribute attribute,
139 USearchAttributeValue value,
140 UErrorCode &status);
141
148 USearchAttributeValue getAttribute(USearchAttribute attribute) const;
149
166 int32_t getMatchedStart(void) const;
167
182 int32_t getMatchedLength(void) const;
183
198 void getMatchedText(UnicodeString &result) const;
199
215 void setBreakIterator(BreakIterator *breakiter, UErrorCode &status);
216
227 const BreakIterator * getBreakIterator(void) const;
228
239 virtual void setText(const UnicodeString &text, UErrorCode &status);
240
256 virtual void setText(CharacterIterator &text, UErrorCode &status);
257
263 const UnicodeString & getText(void) const;
264
265 // operator overloading ----------------------------------------------
266
275 virtual bool operator==(const SearchIterator &that) const;
276
283 bool operator!=(const SearchIterator &that) const;
284
285 // public methods ----------------------------------------------------
286
294 virtual SearchIterator* safeClone(void) const = 0;
295
309 int32_t first(UErrorCode &status);
310
328 int32_t following(int32_t position, UErrorCode &status);
329
343 int32_t last(UErrorCode &status);
344
368 int32_t preceding(int32_t position, UErrorCode &status);
369
384 int32_t next(UErrorCode &status);
385
399 int32_t previous(UErrorCode &status);
400
409 virtual void reset();
410
411 protected:
412 // protected data members ---------------------------------------------
413
418 USearch *m_search_;
419
428 BreakIterator *m_breakiterator_;
429
434 UnicodeString m_text_;
435
436 // protected constructors and destructors -----------------------------
437
443 SearchIterator();
444
460 SearchIterator(const UnicodeString &text,
461 BreakIterator *breakiter = NULL);
462
482 SearchIterator(CharacterIterator &text, BreakIterator *breakiter = NULL);
483
484 // protected methods --------------------------------------------------
485
492 SearchIterator & operator=(const SearchIterator &that);
493
513 virtual int32_t handleNext(int32_t position, UErrorCode &status)
514 = 0;
515
535 virtual int32_t handlePrev(int32_t position, UErrorCode &status)
536 = 0;
537
548 virtual void setMatchLength(int32_t length);
549
560 virtual void setMatchStart(int32_t position);
561
566 void setMatchNotFound();
567 };
568
569 inline bool SearchIterator::operator!=(const SearchIterator &that) const
570 {
571 return !operator==(that);
572 }
573 U_NAMESPACE_END
574
575 #endif /* #if !UCONFIG_NO_COLLATION */
576
577 #endif /* U_SHOW_CPLUSPLUS_API */
578
579 #endif
580
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(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::SearchIterator
SearchIterator(CharacterIterator &text, BreakIterator *breakiter=NULL)
Constructor for use by subclasses.
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=NULL)
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.
NULL
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
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