-
Notifications
You must be signed in to change notification settings - Fork 3
Modify the XML code according to TODO #9
Copy link
Copy link
Open
Description
What version of Go are you using (go version)?
$ go version go master
Original code
// procInst parses the `param="..."` or `param='...'`
// value out of the provided string, returning "" if not found.
func procInst(param, s string) string {
// TODO: this parsing is somewhat lame and not exact.
// It works for all actual cases, though.
param = param + "="
idx := strings.Index(s, param)
if idx == -1 {
return ""
}
v := s[idx+len(param):]
if v == "" {
return ""
}
if v[0] != '\'' && v[0] != '"' {
return ""
}
idx = strings.IndexRune(v[1:], rune(v[0]))
if idx == -1 {
return ""
}
return v[1 : idx+1]
}Modified code
func procInst(param, s string) string {
// TODO: this parsing is somewhat lame and not exact.
// It works for all actual cases, though.
param = param + "="
if idx := strings.Index(s, param); idx == -1 {
return ""
}
if v := s[idx+len(param):]; v == "" {
return ""
}
if v[0] != '\'' && v[0] != '"' {
return ""
}
idx = strings.IndexByte(v[1:],v[0])
if idx == -1 {
return ""
}
return v[1 : idx+1]
}What did you see?
- better understanding of TODO
- modify the code better
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels