Is there anyway that I can combine this Korean consonants and vowels into a complete character.
For example if I have
ㄱㅏㅁㅅㅏㅎㅏㅂㄴㅣㄷㅏ
It would be
감사합니다
Is there any way to do this? I can only think of bruteforcing every case that would have to count many many cases.
Below is my try. Not optimal and take too much time.
if strings.Contains(input_str, "ㅏㄴㅈ") {
input_str = strings.Replace(input_str, "ㅇㅏㄴㅈ", "앉", -1)
}
if strings.Contains(input_str, "ㅏㄹㅂ") {
input_str = strings.Replace(input_str, "ㅂㅏㄹㅂ", "밟", -1)
}
if strings.Contains(input_str, "ㅏㅂㅅ") {
input_str = strings.Replace(input_str, "ㄱㅏㅂㅅ", "값", -1)
}
What you want is Unicode normalization to compose hangul jamo. Go supports this but not (yet) in the standard library. See this related issue.
To import the external go.text/unicode/norm
package use:
go get -u golang.org/x/text/unicode/norm
You probably want to use NFC which does a
Example for NFD (decomposition):
// 앉 -> 앉
fmt.Println( string( norm.NFD.AppendString(nil, "앉") ) )
Example for NFC (composition):
// 앉 -> 앉
fmt.Println( string( norm.NFC.AppendString(nil, "앉") ) )
Someone recently did a write-up on unicode in Korean: http://www.programminginkorean.com/programming/hangul-in-unicode/composing-syllables-in-unicode/