class ICU::StringSearch
- ICU::StringSearch
- Reference
- Object
Overview
String Searching
Provides language-sensitive text searching.
Usage
col = ICU::Collator.new("de_DE")
col.strength = ICU::Collator::Strength::Primary
search = ICU::StringSearch.new("ß", "...SS...", col)
search.next # => 3...5
See also
Included Modules
- Iterator(Range(Int32, Int32))
Defined in:
icu/string_search.crConstant Summary
-
DEFAULT =
AttributeValue::Default
-
DONE =
-1
-
OFF =
AttributeValue::Off
-
ON =
AttributeValue::On
Constructors
-
.new(pattern : String, text : String, locale : String = Locale::DEFAULT_LOCALE, break_iterator : BreakIterator? = nil)
Creates a search iterator specifying a locale language rule set
-
.new(pattern : String, text : String, collator : Collator, break_iterator : BreakIterator? = nil)
Creates a search iterator specifying a collator language rule set
Instance Method Summary
-
#[](attribute : Attribute) : AttributeValue
Get the value of the specified attribute
-
#[]=(attribute : Attribute, value : AttributeValue)
Set a value to the specified attribute
- #break_iterator : ICU::BreakIterator?
-
#break_iterator=(break_iterator : BreakIterator)
Set the BreakIterator that will be used to restrict the points at which matches are detected
- #collator : ICU::Collator?
-
#collator=(collator : Collator)
Sets the collator used for the language rules
-
#first : Position?
Returns the first index at which the string text matches the search pattern
-
#following(position : Int) : Position?
Returns the first index greater or equal than position at which the string text matches the search pattern
-
#last : Position?
Returns the last index in the target text at which it matches the search pattern
-
#next
Returns the index of the next point at which the string text matches the search pattern, starting from the current position.
-
#offset : Int32
Returns the last index in the text at which it matches the search pattern
-
#offset=(offset : Int32)
Sets the current position in the text string which the next search will start from
-
#pattern : String
Returns the value of the search pattern
-
#pattern=(pattern : String)
Sets the pattern used for matching
-
#preceding(position : Int) : Position?
Returns the first index less than position at which the string text matches the search pattern
-
#previous
Returns the index of the previous point at which the string text matches the search pattern, starting at the current position.
-
#reset
Resets the position of the cursor
- #rewind
-
#text : String
Return the text to be searched
-
#text=(text : String)
Set the string text to be searched
Constructor Detail
Creates a search iterator specifying a locale language rule set
See also: #break_iterator=
Creates a search iterator specifying a collator language rule set
See also: #collator=
, #break_iterator=
Instance Method Detail
Get the value of the specified attribute
Set a value to the specified attribute
search = ICU::StringSearch.new("bb", "abbbc")
search[ICU::StringSearch::Attribute::Overlap] = ICU::StringSearch::OFF
search.to_a # => [(1...3)]
search.rewind
search[ICU::StringSearch::Attribute::Overlap] = ICU::StringSearch::ON
search.to_a # => [(1...3), (2...4)]
Set the BreakIterator that will be used to restrict the points at which matches are detected
search = ICU::StringSearch.new("ab", "... abc ...")
search.break_iterator = ICU::BreakIterator.new(ICU::BreakIterator::Type::Word)
search.next # => Iterator::Stop::INSTANCE
search.pattern = "abc"
search.reset
search.next # => 4...6
Sets the collator used for the language rules
search = ICU::StringSearch.new("aa", "ab")
search.collator = ICU::Collator.new("&b = a".to_uchars)
search.next # => 0...2
Returns the first index at which the string text matches the search pattern
Returns the first index greater or equal than position at which the string text matches the search pattern
Returns the last index in the target text at which it matches the search pattern
Returns the index of the next point at which the string text matches the search pattern, starting from the current position.
search = ICU::StringSearch.new("abc", "...abc...abc...")
search.next # => 3...6
search.next # => 9...12
Sets the current position in the text string which the next search will start from
search = ICU::StringSearch.new("abc", "...abc...abc...")
search.offset = 6
search.next # => 9...12
Returns the first index less than position at which the string text matches the search pattern
Returns the index of the previous point at which the string text matches the search pattern, starting at the current position.
search = ICU::StringSearch.new("abc", "...abc...abc...")
search.offset = 14
search.previous # => 9...12
search.previous # => 3...6
Resets the position of the cursor
search = ICU::StringSearch.new("abc", "...abc...abc...")
search.next # => 3...6
search.reset
search.next # => 3...6