Example #1
0
func hasHangul(s string) bool {
	for _, c := range s {
		if han.IsHangul(c) {
			return true
		}
	}
	log.Printf("%s not has hangul\n", s)
	return false
}
Example #2
0
func Encode(s string) (string, int) {
	needForeignMarker := hasHangul(s)

	var currentMarker rune
	rs := make([]rune, 0)
	for _, c := range s {
		switch {
		case han.IsJaeum(c) || han.IsMoeum(c):
			if currentMarker != markerJamo {
				rs = append(rs, markerJamo)
				currentMarker = markerJamo
			}
			rs = append(rs, Jamo(c)...)
		case han.IsHangul(c):
			// In Korean braille string there is no marker for
			// Korean string.
			if currentMarker != 0x00 {
				currentMarker = 0x00
			}
			i, m, f := han.Split(c)
			rs = append(rs, Jamo(i)...)
			rs = append(rs, Jamo(m)...)
			rs = append(rs, Jamo(f)...)
		case '0' <= c && c <= '9':
			if currentMarker != markerNumber {
				rs = append(rs, markerNumber)
				currentMarker = markerNumber
			}
			rs = append(rs, brl.Alphabet(c)...)
		case ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'):
			if currentMarker != markerForeign {
				if needForeignMarker {
					rs = append(rs, markerForeign)
				}
				currentMarker = markerForeign
			}
			rs = append(rs, brl.Alphabet(c)...)
		case isSupportedSymbol(c):
			// No marker change in symbols... Is it right?
			rs = append(rs, symbol[c]...)
		case c == 0x20:
			rs = append(rs, brl.Rune())
			currentMarker = 0x00
		case c == 0x0a:
			rs = append(rs, c)
			currentMarker = 0x00
		default:
			log.Printf("Braille for %c(0x%x) not present... yet", c, c)
			rs = append(rs, brl.BrailleCodeBase)
		}

	}

	return string(rs), len(rs)
}