File: char_type.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 (32 lines) | stat: -rw-r--r-- 756 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
32
# -*- encoding: utf-8 -*-

require "unicode_utils/gc"
require "unicode_utils/general_category"

module UnicodeUtils

  GENERAL_CATEGORY_TYPE_MAP = Hash.new.tap { |map|
    GENERAL_CATEGORY_ALIAS_MAP.each_pair { |short, long|
      if short.length == 2
        map[short] = GENERAL_CATEGORY_ALIAS_MAP[short[0].to_sym]
      end
    }
  } # :nodoc:

  # Get the long major general category alias of char.
  #
  # Example:
  #
  #   require "unicode_utils/char_type"
  #   UnicodeUtils.char_type("1") # => :Number
  #
  # Always returns a symbol when char is in the Unicode code point
  # range.
  #
  # See also: UnicodeUtils.general_category
  def char_type(char)
    GENERAL_CATEGORY_TYPE_MAP[UnicodeUtils.gc(char)]
  end
  module_function :char_type

end