Sha256: 966b99b91c64f04c88891294edd6c544ea23023e9a9d662362dcd11191a2650b
Contents?: true
Size: 1.6 KB
Versions: 19
Compression:
Stored size: 1.6 KB
Contents
# encoding: UTF-8 # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 module TwitterCldr module Tokenizers class UnicodeRegexTokenizer extend Forwardable def_delegator :tokenizer, :insert_before def tokenize(pattern) tokenizer.tokenize(pattern) end private def tokenizer @tokenizer ||= begin recognizers = [ # The variable name can contain letters and digits, but must start with a letter. TokenRecognizer.new(:variable, /\$\w[\w\d]*/), TokenRecognizer.new(:character_set, /\[:\w+:\]|\\p\{[\w=]+\}/), # [:Lu:] or \p{Lu} or \p{Sentence_Break=CF} TokenRecognizer.new(:negated_character_set, /\[:\^\w+:\]|\\P\{[\w=]+\}/), #[:^Lu:] or \P{Lu} TokenRecognizer.new(:unicode_char, /\\u\{?[a-fA-F0-9]{1,6}\}?/), TokenRecognizer.new(:multichar_string, /\{\w+\}/u), TokenRecognizer.new(:escaped_character, /\\./), TokenRecognizer.new(:negate, /\^/), TokenRecognizer.new(:ampersand, /&/), TokenRecognizer.new(:pipe, /\|/), TokenRecognizer.new(:dash, /-/), # stuff that shouldn't be converted to codepoints TokenRecognizer.new(:special_char, /\{\d,?\d?\}|[$?:{}()*+\.,\/\\]/), TokenRecognizer.new(:open_bracket, /\[/), TokenRecognizer.new(:close_bracket, /\]/), TokenRecognizer.new(:string, //) do |val| val == " " ? val : val.strip end ] Tokenizer.new(recognizers) end end end end end
Version data entries
19 entries across 19 versions & 2 rubygems