func (h *Hyphenator) Hyphenate(s, hyphen string) (string, bool) { var sc scanner.Scanner sc.Init(strings.NewReader(s)) sc.Mode = scanner.ScanIdents sc.Whitespace = 0 var outstr string tok := sc.Scan() for tok != scanner.EOF { switch tok { case scanner.Ident: // a word (or part thereof) to hyphenate t := sc.TokenText() // try the exceptions first exc := h.exceptions[t] if len(exc) != 0 { if hyphen != `-` { strings.Replace(exc, `-`, hyphen, -1) } return exc, true } // not an exception, hyphenate normally outstr += h.hyphenateWord(sc.TokenText(), hyphen) default: // A Unicode rune to append to the output p := make([]byte, utf8.UTFMax) l := utf8.EncodeRune(tok, p) outstr += string(p[0:l]) } tok = sc.Scan() } return outstr, true }