This commit is contained in:
Alex Yatskov 2016-07-31 13:10:01 -07:00
parent 4df5d16aa1
commit 8efc580f80
3 changed files with 18 additions and 8 deletions

View File

@ -28,7 +28,7 @@ import (
"regexp"
)
func parseEntries(reader io.Reader, callback func(decoder *xml.Decoder, element xml.StartElement) error) (map[string]string, error) {
func parseEntries(reader io.Reader, callback func(decoder *xml.Decoder, element *xml.StartElement) error) (map[string]string, error) {
decoder := xml.NewDecoder(reader)
for {
@ -42,7 +42,7 @@ func parseEntries(reader io.Reader, callback func(decoder *xml.Decoder, element
directive := token.(xml.Directive)
decoder.Entity = parseEntities(&directive)
case xml.StartElement:
if err := callback(decoder, startElement); err != nil {
if err := callback(decoder, &startElement); err != nil {
return nil, err
}
}

View File

@ -22,8 +22,10 @@
package jmdict
import "io"
import "encoding/xml"
import (
"encoding/xml"
"io"
)
// Entries consist of kanji elements, reading elements,
// general information and sense elements. Each entry must have at
@ -231,9 +233,13 @@ type edictSense struct {
func LoadEdict(reader io.Reader) ([]edictEntry, map[string]string, error) {
var entries []edictEntry
entities, err := parseEntries(reader, func(decoder *xml.Decoder, element xml.StartElement) error {
entities, err := parseEntries(reader, func(decoder *xml.Decoder, element *xml.StartElement) error {
if element.Name.Local != "entry" {
return nil
}
var entry edictEntry
if err := decoder.DecodeElement(&entry, &element); err != nil {
if err := decoder.DecodeElement(&entry, element); err != nil {
return err
}

View File

@ -132,9 +132,13 @@ type enamTranslation struct {
func LoadEnamdict(reader io.Reader) ([]enamdictEntry, map[string]string, error) {
var entries []enamdictEntry
entities, err := parseEntries(reader, func(decoder *xml.Decoder, element xml.StartElement) error {
entities, err := parseEntries(reader, func(decoder *xml.Decoder, element *xml.StartElement) error {
if element.Name.Local != "entry" {
return nil
}
var entry enamdictEntry
if err := decoder.DecodeElement(&entry, &element); err != nil {
if err := decoder.DecodeElement(&entry, element); err != nil {
return err
}