README

hangul logo

About hangul

hangul is a set of handy tools for manipulate korean character in Go language.

GoDoc Build Status

Example

package main

import (
        "fmt"
        hangul "github.com/suapapa/go_hangul"
)

func main() {
        var i, m, f, ci, cm, cf rune
        var c int
        for _, r := range "맥도날드" {
                // Storke count
                c = hangul.Stroke(r)
                // Split to three elements
                i, m, f = hangul.Split(r)
                // Convert between jamo and compatibility-jamo
                ci = hangul.CompatJamo(i)
                cm = hangul.CompatJamo(m)
                cf = hangul.CompatJamo(f)

                fmt.Printf("%c %d %c(%v) %c(%v) %c(%v)\n", r, c, ci, i, cm, m, cf, f)
        }
        fmt.Println("")

        fmt.Println(
            hangul.EndsWithConsonant("강")) // true
        fmt.Println(
            hangul.EndsWithConsonant("그")) // false
        fmt.Println(
            hangul.AppendPostposition("강", "이", "가")) // "강이"
        fmt.Println(
            hangul.AppendPostposition("물고기", "은", "는")) // "물고기는"
}

Installation

$ go get github.com/suapapa/go_hangul

Author

Homin Lee <homin.lee@suapapa.net>

Copyright (c) 2012, Homin Lee. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Documentation

Overview

    Package hangul provide handy tools for manipulate korean character:

    - Provide shorthands for korean consonants and vowels
    - Convert between jamo and compatibility-jamo
    - Split a character to it's three elements
    - Split multi element
    - Stroke count
    

    Index

    Examples

    Constants

    View Source
    const (
    	G   // HANGUL LETTER KIYEOK
    	GG  // HANGUL LETTER SSANGKIYEOK
    	GS  // HANGUL LETTER KIYEOK-SIOS
    	N   // HANGUL LETTER NIEUN
    	NJ  // HANGUL LETTER NIEUN-CIEUC
    	NH  // HANGUL LETTER NIEUN-HIEUH
    	D   // HANGUL LETTER TIKEUT
    	DD  // HANGUL LETTER SSANGTIKEUT
    	L   // HANGUL LETTER RIEUL
    	LG  // HANGUL LETTER RIEUL-KIYEOK
    	LM  // HANGUL LETTER RIEUL-MIEUM
    	LB  // HANGUL LETTER RIEUL-PIEUP
    	LS  // HANGUL LETTER RIEUL-SIOS
    	LT  // HANGUL LETTER RIEUL-THIEUTH
    	LP  // HANGUL LETTER RIEUL-PHIEUPH
    	LH  // HANGUL LETTER RIEUL-HIEUH
    	M   // HANGUL LETTER MIEUM
    	B   // HANGUL LETTER PIEUP
    	BB  // HANGUL LETTER SSANGPIEUP
    	BS  // HANGUL LETTER PIEUP-SIOS
    	S   // HANGUL LETTER SIOS
    	SS  // HANGUL LETTER SSANGSIOS
    	ZS  // HANGUL LETTER IEUNG (zero sound)
    	J   // HANGUL LETTER CIEUC
    	JJ  // HANGUL LETTER SSANGCIEUC
    	C   // HANGUL LETTER CHIEUCH
    	K   // HANGUL LETTER KHIEUKH
    	T   // HANGUL LETTER THIEUTH
    	P   // HANGUL LETTER PHIEUPH
    	H   // HANGUL LETTER HIEUH
    	A   // HANGUL LETTER A
    	AE  // HANGUL LETTER AE
    	YA  // HANGUL LETTER YA
    	YAE // HANGUL LETTER YAE
    	EO  // HANGUL LETTER EO
    	E   // HANGUL LETTER E
    	YEO // HANGUL LETTER YEO
    	YE  // HANGUL LETTER YE
    	O   // HANGUL LETTER O
    	WA  // HANGUL LETTER WA
    	WAE // HANGUL LETTER WAE
    	OE  // HANGUL LETTER OE
    	YO  // HANGUL LETTER YO
    	U   // HANGUL LETTER U
    	WEO // HANGUL LETTER WEO
    	WE  // HANGUL LETTER WE
    	WI  // HANGUL LETTER WI
    	YU  // HANGUL LETTER YU
    	EU  // HANGUL LETTER EU
    	YI  // HANGUL LETTER YI
    	I   // HANGUL LETTER I
    	NG  = ZS
    )

      Hangul Compatibility Jamo. Range: 3130-318F

      View Source
      const (
      	LeadG  // HANGUL CHOSEONG KIYEOK
      	LeadGG // HANGUL CHOSEONG SSANGKIYEOK
      	LeadN  // HANGUL CHOSEONG NIEUN
      	LeadD  // HANGUL CHOSEONG TIKEUT
      	LeadDD // HANGUL CHOSEONG SSANGTIKEUT
      	LeadR  // HANGUL CHOSEONG RIEUL
      	LeadM  // HANGUL CHOSEONG MIEUM
      	LeadB  // HANGUL CHOSEONG PIEUP
      	LeadBB // HANGUL CHOSEONG SSANGPIEUP
      	LeadS  // HANGUL CHOSEONG SIOS
      	LeadSS // HANGUL CHOSEONG SSANGSIOS
      	LeadZS // HANGUL CHOSEONG IEUNG (zero sound)
      	LeadJ  // HANGUL CHOSEONG CIEUC
      	LeadJJ // HANGUL CHOSEONG SSANGCIEUC
      	LeadC  // HANGUL CHOSEONG CHIEUCH
      	LeadK  // HANGUL CHOSEONG KHIEUKH
      	LeadT  // HANGUL CHOSEONG THIEUTH
      	LeadP  // HANGUL CHOSEONG PHIEUPH
      	LeadH  // HANGUL CHOSEONG HIEUH
      )

        Initial consonants 초성

        View Source
        const (
        	MedialA   // HANGUL JUNGSEONG A
        	MedialAE  // HANGUL JUNGSEONG AE
        	MedialYA  // HANGUL JUNGSEONG YA
        	MedialYAE // HANGUL JUNGSEONG YAE
        	MedialEO  // HANGUL JUNGSEONG EO
        	MedialE   // HANGUL JUNGSEONG E
        	MedialYEO // HANGUL JUNGSEONG YEO
        	MedialYE  // HANGUL JUNGSEONG YE
        	MedialO   // HANGUL JUNGSEONG O
        	MedialWA  // HANGUL JUNGSEONG WA
        	MedialWAE // HANGUL JUNGSEONG WAE
        	MedialOE  // HANGUL JUNGSEONG OE
        	MedialYO  // HANGUL JUNGSEONG YO
        	MedialU   // HANGUL JUNGSEONG U
        	MedialWEO // HANGUL JUNGSEONG WEO
        	MedialWE  // HANGUL JUNGSEONG WE
        	MedialWI  // HANGUL JUNGSEONG WI
        	MedialYU  // HANGUL JUNGSEONG YU
        	MedialEU  // HANGUL JUNGSEONG EU
        	MedialYI  // HANGUL JUNGSEONG YI
        	MedialI   // HANGUL JUNGSEONG I
        )

          Medial vowels 중성

          View Source
          const (
          	TailG  // HANGUL JONGSEONG KIYEOK
          	TailGG // HANGUL JONGSEONG SSANGKIYEOK
          	TailGS // HANGUL JONGSEONG KIYEOK-SIOS
          	TailN  // HANGUL JONGSEONG NIEUN
          	TailNJ // HANGUL JONGSEONG NIEUN-CIEUC
          	TailNH // HANGUL JONGSEONG NIEUN-HIEUH
          	TailD  // HANGUL JONGSEONG TIKEUT
          	TailL  // HANGUL JONGSEONG RIEUL
          	TailLG // HANGUL JONGSEONG RIEUL-KIYEOK
          	TailLM // HANGUL JONGSEONG RIEUL-MIEUM
          	TailLB // HANGUL JONGSEONG RIEUL-PIEUP
          	TailLS // HANGUL JONGSEONG RIEUL-SIOS
          	TailLT // HANGUL JONGSEONG RIEUL-THIEUTH
          	TailLP // HANGUL JONGSEONG RIEUL-PHIEUPH
          	TailLH // HANGUL JONGSEONG RIEUL-HIEUH
          	TailM  // HANGUL JONGSEONG MIEUM
          	TailB  // HANGUL JONGSEONG PIEUP
          	TailBS // HANGUL JONGSEONG PIEUP-SIOS
          	TailS  // HANGUL JONGSEONG SIOS
          	TailSS // HANGUL JONGSEONG SSANGSIOS
          	TailNG // HANGUL JONGSEONG IEUNG
          	TailJ  // HANGUL JONGSEONG CIEUC
          	TailC  // HANGUL JONGSEONG CHIEUCH
          	TailK  // HANGUL JONGSEONG KHIEUKH
          	TailT  // HANGUL JONGSEONG THIEUTH
          	TailP  // HANGUL JONGSEONG PHIEUPH
          	TailH  // HANGUL JONGSEONG HIEUH
          )

            Final consonants 종성

            Variables

            This section is empty.

            Functions

            func AppendPostposition

            func AppendPostposition(word, with, without string) string

              AppendPostposition returns word with postposition(조사). The 'with' will be appended to a word that ends with consonant, and the 'without' will be appended to a word that does not end with consonant.

              Example
              Output:
              
              강이
              물고기는
              영철이랑
              순희랑
              마을로
              

              func CompatJamo

              func CompatJamo(r rune) rune

                CompatJamo converts lead, medial, tail to compatibility jamo

                func EndsWithConsonant

                func EndsWithConsonant(word string) bool

                  EndsWithConsonant returns true if the given word ends with consonant(종성), false otherwise.

                  func IsHangul

                  func IsHangul(r rune) bool

                    IsHangul checks given rune is Hangul

                    func IsJaeum

                    func IsJaeum(r rune) bool

                      IsJaeum checks given rune is Hangul Jaeum

                      func IsLead

                      func IsLead(r rune) bool

                        IsLead checks given rune is lead consonant

                        func IsMedial

                        func IsMedial(r rune) bool

                          IsMedial checks given rune is medial vowel

                          func IsMoeum

                          func IsMoeum(r rune) bool

                            IsMoeum checks given rune is Hangul Moeum

                            func IsTail

                            func IsTail(r rune) bool

                              IsTail checks given rune is tail consonant

                              func Join

                              func Join(l, m, t rune) rune

                                Join converts NFD to NFC

                                func LastConsonant

                                func LastConsonant(word string) rune

                                  LastConsonant returns last consonant(종성). It returns 0 if last consonant not exists.

                                  Example
                                  Output:
                                  
                                  4540
                                  0
                                  

                                  func Lead

                                  func Lead(c rune) rune

                                    Lead converts compatibility jaeum to corresponding lead consonant

                                    func Medial

                                    func Medial(c rune) rune

                                      Medial converts compatibility moeum to corresponding medial vowel

                                      func Split

                                      func Split(c rune) (l, m, t rune)

                                        Split converts NFC to NFD

                                        func SplitCompat

                                        func SplitCompat(c rune) (l, m, t rune)

                                          SplitCompat splits and returns l, m, t in compatibility jamo

                                          func SplitMultiElement

                                          func SplitMultiElement(r rune) ([]rune, bool)

                                            SplitMultiElement splits multi-element compatibility jamo

                                            func Stroke

                                            func Stroke(r rune) (c int)

                                              Stroke returns stroke count of given jamo.

                                              func Tail

                                              func Tail(c rune) rune

                                                Tail converts compatibility jaeum to corresponding tail consonant

                                                Types

                                                This section is empty.

                                                Directories

                                                Path Synopsis
                                                encoding
                                                cp949
                                                Package cp949 provide support for CP949 character encoding, It's degault encoding in Korean MS Windows.
                                                Package cp949 provide support for CP949 character encoding, It's degault encoding in Korean MS Windows.