module

TextUtil

Constants

BR_RE = /\<br\s*\/?\>|\s{4,+}/i
FIX_MARKS = {"òa" => "oà", "óa" => "oá", "ỏa" => "oả", "õa" => "oã", "ọa" => "oạ", "òe" => "oè", "óe" => "oé", "ỏe" => "oẻ", "õe" => "oẽ", "ọe" => "oẹ", "ùy" => "uỳ", "úy" => "uý", "ủy" => "uỷ", "ũy" => "uỹ", "ụy" => "uỵ"}
MARK_RE = Regex.new(FIX_MARKS.keys.join('|'))

Instance methods

canon_clean(input : String, upcase : Bool = false) : String

convert all halfwidth to fullwidth and group similar characters

Source
capitalize(input : String) : String

smart capitalize:

  • don't downcase extra characters
  • treat unicode alphanumeric chars as upcase-able
Source
clean_and_trim(input : String) : String
Source
clean_spaces(input : String) : String
Source
fix_viet(str : String)
Source
normalize(input : String) : String

Convert chinese punctuations to english punctuations and full width characters to ascii characters

Source
normalize(input : Array(Char)) : Array(Char)

Convert chinese punctuations to english punctuations and full width characters to ascii characters

Source
slugify(input : String, tones = false) : String

make url friendly string

Source
split_html(input : String, fix_br : Bool = true) : Array(String)
Source
split_spaces(input : String)
Source
split_text(input : String, spaces_as_newline = true) : Array(String)
Source
titleize(input : String) : String

capitalize all words

Source
tokenize(input : String, tones = false) : Array(String)

split input to words

Source
truncate(input : String, limit = 100)
Source
unaccent(input : String) : String

strip vietnamese accents

Source
uniformize(input : String, upcase : Bool = false) : String

convert all halfwidth to fullwidth and group similar characters

Source