From 2c5ca974a98993a9dbf9221d4008f4298d1e1b22 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sat, 21 Sep 2024 23:25:22 +0900 Subject: [PATCH] DebugWriter --- haiku.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/haiku.go b/haiku.go index f06ebfe..7ed9a5d 100644 --- a/haiku.go +++ b/haiku.go @@ -2,6 +2,7 @@ package haiku import ( "fmt" + "io" "os" "regexp" "strings" @@ -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) { @@ -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 == "、" {