Class: InjalidDejice::LocaleResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/injalid_dejice/locale_resolver.rb

Overview

Finds start and end indexes of a non-Latin sub-string.

Instance Method Summary collapse

Constructor Details

#initialize(string, forced_latin = []) ⇒ LocaleResolver

Class init.



14
15
16
17
# File 'lib/injalid_dejice/locale_resolver.rb', line 14

def initialize(string, forced_latin = [])
  @string = string
  @forced_latin = forced_latin
end

Instance Method Details

#callArray<Array<Integer>>

Return start and end indexes for all so-called “non-Latin” sub-strings of the input string. Numbers and some punctuation characters can be part of both Latin, and non-Latin sub-strings. The “locale” of these characters is defined by the preceding character(s). E.g., in the string “привет-123 hello-456” the “-123 ” chunk (note the trailing space) would be considered as a part of the non-Latin sub-string, while the “-456” chunk as a part of the Latin sub-string.

Sometimes it is required to forcibly apply the Latin ‘locale’ to the character. This is needed to avoid some bugs in the legacy software (e.g. MK90 BASIC). For this purpose there’s the optional argument ‘forced_latin’.



38
39
40
41
42
43
44
45
46
47
# File 'lib/injalid_dejice/locale_resolver.rb', line 38

def call
  @non_latin_indexes = []
  @start_index = nil

  _handle_subtrings

  _handle_last_substring if @start_index

  @non_latin_indexes
end