Sha256: c6260b1ac0f0c278b50d431e34748736cd0c7da530660ac8c64863bc5984c31e

Contents?: true

Size: 1.72 KB

Versions: 19

Compression:

Stored size: 1.72 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Normalization
    module Hangul

      class << self

        # Special composition for Hangul syllables. Documented in Section 3.12 at
        # http://www.unicode.org/versions/Unicode6.1.0/ch03.pdf
        #
        def compose(code_points)
          l = code_points.first - LBASE
          v = code_points[1] - VBASE
          t = code_points[2] ? code_points[2] - TBASE : 0  # T part may be missing, that's ok

          SBASE + l * NCOUNT + v * TCOUNT + t
        end

        # Special decomposition for Hangul syllables. Documented in Section 3.12 at http://www.unicode.org/versions/Unicode6.1.0/ch03.pdf
        # Also see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/collation/ICU_collation_design.htm#Hangul_Implicit_CEs
        #
        def decompose(code_point)
          l = code_point - SBASE

          t = l % TCOUNT
          l /= TCOUNT
          v = l % VCOUNT
          l /= VCOUNT

          result = []

          result << LBASE + l
          result << VBASE + v
          result << TBASE + t if t > 0

          result
        end

        def hangul_syllable?(code_point)
          (SBASE...SLIMIT).include?(code_point)
        end

        SBASE  = 0xAC00
        LBASE  = 0x1100
        VBASE  = 0x1161
        TBASE  = 0x11A7

        LCOUNT = 19
        VCOUNT = 21
        TCOUNT = 28

        NCOUNT = VCOUNT * TCOUNT # 588
        SCOUNT = LCOUNT * NCOUNT # 11172

        LLIMIT = LBASE + LCOUNT  # 0x1113 = 4371
        VLIMIT = VBASE + VCOUNT  # 0x1176 = 4470
        TLIMIT = TBASE + TCOUNT  # 0x11C3 = 4547
        SLIMIT = SBASE + SCOUNT  # 0xD7A4 = 55204

      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
twitter_cldr-2.4.3 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-2.4.2 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-2.4.1 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-2.4.0 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-2.2.0 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-2.1.1 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-2.1.0 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-2.0.2 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-2.0.1 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-2.0.0 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-1.9.1 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-1.9.0 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-1.8.1 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-1.8.0 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-1.7.0 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-1.6.2 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-1.6.1 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-1.6.0 lib/twitter_cldr/normalization/hangul.rb
twitter_cldr-1.5.0 lib/twitter_cldr/normalization/hangul.rb