-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solved https://github.com/asticode/go-astisub/issues/59 #60
Conversation
ssa.go
Outdated
@@ -1268,3 +1274,14 @@ func (s Subtitles) WriteToSSA(o io.Writer) (err error) { | |||
} | |||
return | |||
} | |||
|
|||
// SSAOptions | |||
type SSAOptions struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OnUnknownSectionName
and OnInvalidLine
need to be fields of SSAOptions
.
You also need to create a defaultSSAOptions func() SSAOptions
that would return SSAOptions
with callbacks properly set for logging
ssa.go
Outdated
@@ -175,7 +181,7 @@ func ReadFromSSA(i io.Reader) (o *Subtitles, err error) { | |||
format = make(map[int]string) | |||
continue | |||
default: | |||
log.Printf("astisub: unknown section: %s", line) | |||
opts.OnUnknownSectionName(line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once OnUnknownSectionName
is a field, you'll need to wrap this with if opts.OnUnknownSectionName != nil
ssa.go
Outdated
@@ -195,7 +201,7 @@ func ReadFromSSA(i io.Reader) (o *Subtitles, err error) { | |||
// Split on ":" | |||
var split = strings.Split(line, ":") | |||
if len(split) < 2 || split[0] == "" { | |||
log.Printf("astisub: not understood: '%s', ignoring", line) | |||
opts.OnInvalidLine(line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once OnInvalidLine
is a field, you'll need to wrap this with if opts.OnInvalidLine != nil
ssa.go
Outdated
@@ -134,6 +134,12 @@ var ssaRegexpEffect = regexp.MustCompile(`\{[^\{]+\}`) | |||
|
|||
// ReadFromSSA parses an .ssa content | |||
func ReadFromSSA(i io.Reader) (o *Subtitles, err error) { | |||
o, err = ReadFromSSAWithOptions(i, SSAOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to replace SSAOptions{}
with defaultSSAOptions()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Originated from #59