File: graphic_char_q.rb

package info (click to toggle)
ruby-unicode-utils 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,988 kB
  • sloc: ruby: 1,877; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 930 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- encoding: utf-8 -*-

require "unicode_utils/gc"

module UnicodeUtils

  GENERAL_CATEGORY_IS_GRAPHIC_MAP = {
    Lu: true, Ll: true, Lt: true, Lm: true, Lo: true,
    Mn: true, Mc: true, Me: true,
    Nd: true, Nl: true, No: true,
    Pc: true, Pd: true, Ps: true, Pe: true, Pi: true, Pf: true, Po: true,
    Sm: true, Sc: true, Sk: true, So: true,
    Zs: true, Zl: false, Zp: false,
    Cc: false, Cf: false, Cs: false, Co: false, Cn: false
  } # :nodoc:

  # Returns true if the given char is a graphic char, false otherwise.
  # See table 2-3 in section 2.4 of Unicode 6.0.0.
  #
  # Examples:
  #
  #   require "unicode_utils/graphic_char_q"
  #   UnicodeUtils.graphic_char?("a")  # => true
  #   UnicodeUtils.graphic_char?("\n") # => false
  #   UnicodeUtils.graphic_char?(0x0)  # => false
  def graphic_char?(char)
    GENERAL_CATEGORY_IS_GRAPHIC_MAP[UnicodeUtils.gc(char)]
  end
  module_function :graphic_char?

end