Class: Unicoder::Builder::Types
- Inherits:
- 
      Object
      
        - Object
- Unicoder::Builder::Types
 
- Includes:
- Unicoder::Builder, MultiDimensionalArrayBuilder
- Defined in:
- lib/unicoder/builders/types.rb
Constant Summary collapse
- NONCHARACTERS =
- [ *0xFDD0..0xFDEF, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, 0x10FFFF, ] 
Instance Attribute Summary
Attributes included from Unicoder::Builder
Instance Method Summary collapse
Methods included from MultiDimensionalArrayBuilder
#assign_codepoint, #compress!, #remove_trailing_nils!
Methods included from Unicoder::Builder
#assign, #assign_codepoint, build, #export, #initialize, #meta, #parse_file
Instance Method Details
#initialize_index ⇒ Object
| 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # File 'lib/unicoder/builders/types.rb', line 28 def initialize_index @index = { TYPES: [], TYPE_NAMES: %w[ Graphic Format Control Private-use Surrogate Noncharacter Reserved ], OFFSETS: [ 0x10000, 0x1000, 0x100, 0x10 ], } end | 
#parse! ⇒ Object
| 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | # File 'lib/unicoder/builders/types.rb', line 49 def parse! parse_file :general_categories, :line, regex: /^(?<from>[^. ]+)(?:..(?<to>\S+))?\s*; (?<category>\S+).*$/ do |line| if line["to"] codepoints = Range.new(line["from"].to_i(16), line["to"].to_i(16)) else codepoints = [line["from"].to_i(16)] end codepoints.each{ |codepoint| case line["category"] when "Cf", "Zl", "Zp" type = 1 when "Cc" type = 2 when "Co" type = 3 when "Cs" type = 4 when "Cn" if NONCHARACTERS.include?(codepoint) type = 5 else type = 6 end end assign :TYPES, codepoint, type } end 4.times{ compress! @index[:TYPES] } end |