lib/characteristics/unicode.rb in characteristics-0.6.0 vs lib/characteristics/unicode.rb in characteristics-0.7.0

- old
+ new

@@ -89,10 +89,80 @@ 0x2067, 0x2068, 0x2069, ].freeze + VARIATION_SELECTORS = [ + *0x180B..0x180D, + *0xFE00..0xFE0F, + *0xE0100..0xE01EF, + ].freeze + + TAGS = [ + 0xE0001, + *0xE0020..0xE007F, + ].freeze + + 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, + ].freeze + + IGNORABLE = [ + 0x00AD, + 0x034F, + 0x061C, + *0x115F..0x1160, + *0x17B4..0x17B5, + *0x180B..0x180E, + *0x200B..0x200F, + *0x202A..0x202E, + *0x2060..0x206F, + 0x3164, + *0xFE00..0xFE0F, + 0xFEFF, + 0xFFA0, + *0xFFF0..0xFFF8, + *0x1BCA0..0x1BCA3, + *0x1D173..0x1D17A, + *0xE0000..0xE0FFF, + ].freeze + + KDDI = [ + *0xE468..0xE5DF, + *0xEA80..0xEB8E, + ].freeze + + SOFTBANK = [ + *0xE001..0xE05A, + *0xE101..0xE15A, + *0xE201..0xE25A, + *0xE301..0xE34D, + *0xE401..0xE44C, + *0xE501..0xE53E, + ].freeze + + DOCOMO = [ + *0xE63E..0xE757, + ].freeze + attr_reader :category def initialize(char) super @@ -140,31 +210,45 @@ def bidi_control? @is_valid && BIDI_CONTROL.include?(@ord) end + # unicode specific + + def variation_selector? + @is_valid && VARIATION_SELECTORS.include?(@ord) + end + + def tag? + @is_valid && TAGS.include?(@ord) + end + + def noncharacter? + @is_valid && NONCHARACTERS.include?(@ord) + end + + def ignorable? + @is_valid && IGNORABLE.include?(@ord) + end + + # emoji + def kddi? @is_valid && encoding_has_kddi? && - ( @ord >= 0xE468 && @ord <= 0xE5DF || - @ord >= 0xEA80 && @ord <= 0xEB8E ) + KDDI.include?(@ord) end def softbank? @is_valid && encoding_has_softbank? && - ( @ord >= 0xE001 && @ord <= 0xE05A || - @ord >= 0xE101 && @ord <= 0xE15A || - @ord >= 0xE201 && @ord <= 0xE25A || - @ord >= 0xE301 && @ord <= 0xE34D || - @ord >= 0xE401 && @ord <= 0xE44C || - @ord >= 0xE501 && @ord <= 0xE53E ) + SOFTBANK.include?(@ord) end def docomo? @is_valid && encoding_has_docomo? && - ( @ord >= 0xE63E && @ord <= 0xE757 ) + DOCOMO.include?(@ord) end private def encoding_has_c1?