Skip to content

Commit

Permalink
add IntString type for unmarshalling radical values
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnps committed Feb 22, 2014
1 parent b77eae0 commit 932ba56
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions kanjidic2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@ package kanjidic2

import (
"encoding/xml"
"log"
"os"
"strconv"
)

// for ,innerxml to unmarshal into ints instead of strings
type IntString string

func (f *IntString) UnmarshalXML(i interface{}) int64 {
s := i.(string)
n, err := strconv.ParseInt(s, 10, 0)
if err != nil {
log.Fatal(err)
}
return n
}

type Reading struct {
RType string `xml:"r_type,attr"`
Value string `xml:",innerxml"`
Expand All @@ -16,8 +30,8 @@ type Meaning struct {
}

type DicRef struct {
DrType string `xml:"dr_type,attr"`
Value string `xml:",innerxml"`
DrType string `xml:"dr_type,attr"`
Value IntString `xml:",innerxml"`
}

type CpValue struct {
Expand All @@ -26,8 +40,8 @@ type CpValue struct {
}

type RadValue struct {
RadType string `xml:"rad_type,attr"`
Value int `xml:",innerxml"`
RadType string `xml:"rad_type,attr"`
Value IntString `xml:",innerxml"`
}

type Variant struct {
Expand Down

0 comments on commit 932ba56

Please sign in to comment.