Skip to content

Commit

Permalink
print both cloze sides
Browse files Browse the repository at this point in the history
  • Loading branch information
zqkgo committed Feb 2, 2024
1 parent 7cff08e commit 67250c1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions word_clozer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ func (cc *wordClozer) Cloze(rc io.ReadCloser) (string, error) {
if len(bs) == 0 {
return "", errors.New("empty text")
}
r1 := clozeWord(bs, false)
r2 := clozeWord(bs, true)
return r1 + "\n" + r2, nil
}

func clozeWord(bs []byte, toggleCloze bool) string {
var idx int
var result []byte
var toggleCloze bool
for idx < len(bs) {
// 跳过开头连续的空格。
if len(result) == 0 && bs[idx] == ' ' {
Expand Down Expand Up @@ -55,7 +59,7 @@ func (cc *wordClozer) Cloze(rc io.ReadCloser) (string, error) {
result = append(result, word...)
toggleCloze = !toggleCloze
}
return string(result), nil
return string(result)
}

func isLetter(r byte) bool {
Expand Down

0 comments on commit 67250c1

Please sign in to comment.