From 932ba56b58f4fd6b72ade311529a4a31626f0b23 Mon Sep 17 00:00:00 2001 From: Shawn Smith Date: Sat, 22 Feb 2014 17:29:06 +0900 Subject: [PATCH] add IntString type for unmarshalling radical values --- kanjidic2.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/kanjidic2.go b/kanjidic2.go index 053f9e2..63204fe 100644 --- a/kanjidic2.go +++ b/kanjidic2.go @@ -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"` @@ -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 { @@ -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 {