Skip to content

Commit

Permalink
DebugWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Sep 21, 2024
1 parent 2255b2b commit 2c5ca97
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions haiku.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package haiku

import (
"fmt"
"io"
"os"
"regexp"
"strings"
Expand All @@ -20,9 +21,10 @@ var (
)

type Opt struct {
Dict *dict.Dict
UserDict *dict.UserDict
Debug bool
Dict *dict.Dict
UserDict *dict.UserDict
Debug bool
DebugWriter io.Writer
}

func UseDict(d *dict.Dict) {
Expand Down Expand Up @@ -178,7 +180,11 @@ func MatchWithOpt(text string, rule []int, opt *Opt) bool {
}
}
if opt.Debug {
fmt.Fprintln(os.Stderr, c, y)
if opt.DebugWriter != nil {
fmt.Fprintln(opt.DebugWriter, c, y)
} else {
fmt.Fprintln(os.Stderr, c, y)
}
}
if !reWord.MatchString(y) {
if y == "、" {
Expand Down

0 comments on commit 2c5ca97

Please sign in to comment.