Sha256: 7260734444d099516b56d4a5a24dbd76629d8fecf042820ba7d5cdab0014ca70
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
require_relative "categories/constants" module Unicode module Categories def self.categories(string, **options) res = [] string.each_char{ |char| category_name = category(char, **options) res << category_name unless res.include?(category_name) } res.sort end class << self; alias of categories; end def self.category(char, format: :short) require_relative 'categories/index' unless defined? ::Unicode::Categories::INDEX codepoint_depth_offset = char.unpack("U")[0] or raise(ArgumentError, "Unicode::Categories.category must be given a valid char") index_or_value = INDEX[:CATEGORIES] [0x10000, 0x1000, 0x100, 0x10].each{ |depth| index_or_value = index_or_value[codepoint_depth_offset / depth] codepoint_depth_offset = codepoint_depth_offset % depth unless index_or_value.is_a? Array res = index_or_value || "Cn" return format == :long ? INDEX[:CATEGORY_NAMES][res] : res end } res = index_or_value[codepoint_depth_offset] || "Cn" format == :long ? INDEX[:CATEGORY_NAMES][res] : res end def self.names(format: :short) require_relative 'categories/index' unless defined? ::Unicode::Categories::INDEX case format when :long INDEX[:CATEGORY_NAMES].values.sort when :short INDEX[:CATEGORY_NAMES].keys.sort when :table INDEX[:CATEGORY_NAMES].dup end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
unicode-categories-1.1.0 | lib/unicode/categories.rb |
unicode-categories-1.0.0 | lib/unicode/categories.rb |