ICU 63.1  63.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 
22 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
23 
24 #include "unicode/uobject.h"
25 #include "unicode/unistr.h"
26 #include "unicode/chariter.h"
27 #include "unicode/brkiter.h"
28 #include "unicode/usearch.h"
29 
33 struct USearch;
37 typedef struct USearch USearch;
38 
40 
82 
83 public:
84 
85  // public constructors and destructors -------------------------------
86 
94 
99  virtual ~SearchIterator();
100 
101  // public get and set methods ----------------------------------------
102 
116  virtual void setOffset(int32_t position, UErrorCode &status) = 0;
117 
126  virtual int32_t getOffset(void) const = 0;
127 
138  USearchAttributeValue value,
139  UErrorCode &status);
140 
148 
165  int32_t getMatchedStart(void) const;
166 
181  int32_t getMatchedLength(void) const;
182 
197  void getMatchedText(UnicodeString &result) const;
198 
214  void setBreakIterator(BreakIterator *breakiter, UErrorCode &status);
215 
226  const BreakIterator * getBreakIterator(void) const;
227 
238  virtual void setText(const UnicodeString &text, UErrorCode &status);
239 
255  virtual void setText(CharacterIterator &text, UErrorCode &status);
256 
262  const UnicodeString & getText(void) const;
263 
264  // operator overloading ----------------------------------------------
265 
274  virtual UBool operator==(const SearchIterator &that) const;
275 
282  UBool operator!=(const SearchIterator &that) const;
283 
284  // public methods ----------------------------------------------------
285 
293  virtual SearchIterator* safeClone(void) const = 0;
294 
308  int32_t first(UErrorCode &status);
309 
327  int32_t following(int32_t position, UErrorCode &status);
328 
342  int32_t last(UErrorCode &status);
343 
367  int32_t preceding(int32_t position, UErrorCode &status);
368 
383  int32_t next(UErrorCode &status);
384 
398  int32_t previous(UErrorCode &status);
399 
408  virtual void reset();
409 
410 protected:
411  // protected data members ---------------------------------------------
412 
418 
428 
434 
435  // protected constructors and destructors -----------------------------
436 
443 
460  BreakIterator *breakiter = NULL);
461 
482 
483  // protected methods --------------------------------------------------
484 
492 
512  virtual int32_t handleNext(int32_t position, UErrorCode &status)
513  = 0;
514 
534  virtual int32_t handlePrev(int32_t position, UErrorCode &status)
535  = 0;
536 
547  virtual void setMatchLength(int32_t length);
548 
559  virtual void setMatchStart(int32_t position);
560 
566 };
567 
569 {
570  return !operator==(that);
571 }
573 
574 #endif /* #if !UCONFIG_NO_COLLATION */
575 
576 #endif
577 
icu::SearchIterator::getMatchedStart
int32_t getMatchedStart(void) const
Returns the index to the match in the text string that was searched.
icu::SearchIterator::m_breakiterator_
BreakIterator * m_breakiterator_
Break iterator.
Definition: search.h:427
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition: brkiter.h:102
icu::SearchIterator
SearchIterator is an abstract base class that provides methods to search for a pattern within a text ...
Definition: search.h:81
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::getMatchedLength
int32_t getMatchedLength(void) const
Returns the length of text in the string which matches the search pattern.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
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
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
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::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::SearchIterator::reset
virtual void reset()
Resets the iteration.
icu::SearchIterator::setText
virtual void setText(const UnicodeString &text, UErrorCode &status)
Set the string text to be searched.
icu::SearchIterator::SearchIterator
SearchIterator(CharacterIterator &text, BreakIterator *breakiter=NULL)
Constructor for use by subclasses.
icu::SearchIterator::getMatchedText
void getMatchedText(UnicodeString &result) const
Returns the text that was matched by the most recent call to first, next, previous,...
NULL
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
icu::SearchIterator::getAttribute
USearchAttributeValue getAttribute(USearchAttribute attribute) const
Gets the text searching attributes.
brkiter.h
C++ API: Break Iterator.
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::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::getText
const UnicodeString & getText(void) const
Return the string text to be searched.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:290
USearchAttributeValue
USearchAttributeValue
Definition: usearch.h:205
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
USearchAttribute
USearchAttribute
Definition: usearch.h:163
icu::SearchIterator::operator==
virtual UBool operator==(const SearchIterator &that) const
Equality operator.
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:401
usearch.h
C API: StringSearch.
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::SearchIterator
SearchIterator()
Default constructor.
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::first
int32_t first(UErrorCode &status)
Returns the first index at which the string text matches the search pattern.
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
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::last
int32_t last(UErrorCode &status)
Returns the last index in the target text at which it matches the search pattern.
icu::SearchIterator::~SearchIterator
virtual ~SearchIterator()
Destructor.
icu::CharacterIterator
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:358
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::m_text_
UnicodeString m_text_
Unicode string version of the search text.
Definition: search.h:433
icu::SearchIterator::SearchIterator
SearchIterator(const UnicodeString &text, BreakIterator *breakiter=NULL)
Constructor for use by subclasses.
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.
USearch
struct USearch USearch
Definition: search.h:37
chariter.h
C++ API: Character Iterator.
icu::SearchIterator::getOffset
virtual int32_t getOffset(void) const =0
Return the current index in the text being searched.
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::SearchIterator
SearchIterator(const SearchIterator &other)
Copy constructor that creates a SearchIterator instance with the same behavior, and iterating over th...
uobject.h
C++ API: Common ICU base class UObject.
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::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.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
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::setText
virtual void setText(CharacterIterator &text, UErrorCode &status)
Set the string text to be searched.
icu::SearchIterator::operator=
SearchIterator & operator=(const SearchIterator &that)
Assignment operator.
unistr.h
C++ API: Unicode String.
icu::SearchIterator::m_search_
USearch * m_search_
C search data struct.
Definition: search.h:417