Module: NKJ

Defined in:
lib/nkj.rb,
lib/nkj/range_table.rb,
lib/nkj/unicode2jis_mapping.rb

Defined Under Namespace

Classes: Error, RangeTable, Unicode2JISMapping

Class Method Summary collapse

Class Method Details

.jisx0213?(str) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# File 'lib/nkj.rb', line 11

def jisx0213?(str)
  each_grapheme_codepoint(encode(str)) do |cp|
    return false unless Unicode2JISMapping.exists?(cp)
  end

  true
end

.level1?(str) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
# File 'lib/nkj.rb', line 19

def level1?(str)
  level1_range_table = RangeTable.new((0x3021..0x4F53))
  each_grapheme_codepoint(encode(str)) do |cp|
    jis_cp = Unicode2JISMapping.fetch(cp)
    return false unless level1_range_table.include?(jis_cp)
  end

  true
end

.level2?(str) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
# File 'lib/nkj.rb', line 29

def level2?(str)
  level2_range_table = RangeTable.new((0x5021..0x7426))
  each_grapheme_codepoint(encode(str)) do |cp|
    jis_cp = Unicode2JISMapping.fetch(cp)
    return false unless level2_range_table.include?(jis_cp)
  end

  true
end

.level3?(str) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
# File 'lib/nkj.rb', line 39

def level3?(str)
  level3_range_table = RangeTable.new((0x2E21..0x2F7E), (0x4F54..0x4F7E), (0x7427..0x7E7E))
  each_grapheme_codepoint(encode(str)) do |cp|
    jis_cp = Unicode2JISMapping.fetch(cp)
    return false unless level3_range_table.include?(jis_cp)
  end

  true
end

.level4?(str) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
# File 'lib/nkj.rb', line 49

def level4?(str)
  level4_range_table = RangeTable.new((0xA1A1..0xFEF6))
  each_grapheme_codepoint(encode(str)) do |cp|
    jis_cp = Unicode2JISMapping.fetch(cp)
    return false unless level4_range_table.include?(jis_cp)
  end

  true
end