class ICU::StringSearch

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

Defined in:

icu/string_search.cr

Constant Summary

DEFAULT = AttributeValue::Default
DONE = -1
OFF = AttributeValue::Off
ON = AttributeValue::On

Constructors

Instance Method Summary

Constructor Detail

def self.new(pattern : String, text : String, locale : String = Locale::DEFAULT_LOCALE, break_iterator : BreakIterator? = nil) #

Creates a search iterator specifying a locale language rule set

See also: #break_iterator=


[View source]
def self.new(pattern : String, text : String, collator : Collator, break_iterator : BreakIterator? = nil) #

Creates a search iterator specifying a collator language rule set

See also: #collator=, #break_iterator=


[View source]

Instance Method Detail

def [](attribute : Attribute) : AttributeValue #

Get the value of the specified attribute


[View source]
def []=(attribute : Attribute, value : AttributeValue) #

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)]

[View source]
def break_iterator : ICU::BreakIterator? #

[View source]
def break_iterator=(break_iterator : BreakIterator) #

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

[View source]
def collator : ICU::Collator? #

[View source]
def collator=(collator : Collator) #

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

[View source]
def first : Position? #

Returns the first index at which the string text matches the search pattern


[View source]
def following(position : Int) : Position? #

Returns the first index greater or equal than position at which the string text matches the search pattern


[View source]
def last : Position? #

Returns the last index in the target text at which it matches the search pattern


[View source]
def next #

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

[View source]
def offset : Int32 #

Returns the last index in the text at which it matches the search pattern


[View source]
def offset=(offset : Int32) #

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

[View source]
def pattern : String #

Returns the value of the search pattern


[View source]
def pattern=(pattern : String) #

Sets the pattern used for matching


[View source]
def preceding(position : Int) : Position? #

Returns the first index less than position at which the string text matches the search pattern


[View source]
def previous #

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

[View source]
def reset #

Resets the position of the cursor

search = ICU::StringSearch.new("abc", "...abc...abc...")
search.next # => 3...6
search.reset
search.next # => 3...6

[View source]
def rewind #

[View source]
def text : String #

Return the text to be searched


[View source]
def text=(text : String) #

Set the string text to be searched


[View source]