From 4cd1b2f6d92e7c429fcedeff31a40bc0532ed96c Mon Sep 17 00:00:00 2001 From: Richard Lehane Date: Thu, 15 Oct 2015 21:28:42 +1100 Subject: [PATCH] add Null type --- README.md | 4 ++-- msoleps.go | 12 ++++++++++++ sets.go | 11 +++++++++-- types/numeric.go | 14 ++++++++++++++ types/types.go | 1 + 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index abec33e..f49eba5 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Example usage: if oerr := props.Reset(doc); oerr != nil { log.Fatal(oerr) } - for prop := range props.Property { + for _, prop := range props.Property { fmt.Printf("Name: %s; Type: %s; Value: %v", prop.Name, prop.Type(), prop) } } @@ -22,6 +22,6 @@ Example usage: Install with `go get github.com/richardlehane/msoleps` -*Status: currently works for simple property sets like SummaryInformation. Not all types implemented yet (e.g. Vector, Array). Property set bags not implemented yet* +*Status: currently works for simple property sets like SummaryInformation. Not all types implemented yet (e.g. Array). Property set bags not implemented yet* [![Build Status](https://travis-ci.org/richardlehane/msoleps.png?branch=master)](https://travis-ci.org/richardlehane/msoleps) \ No newline at end of file diff --git a/msoleps.go b/msoleps.go index 190dbbc..0eafd67 100644 --- a/msoleps.go +++ b/msoleps.go @@ -125,9 +125,15 @@ func (r *Reader) start(rdr io.Reader) error { dict = make(map[uint32]string) } } + dict = addDefaults(dict) for i, v := range ps.idsOffs { r.Property[i] = &Property{} r.Property[i].Name = dict[v.id] + // don't try to evaluate dictionary property + if v.id == 0x00000000 { + r.Property[i].T = types.Null{} + continue + } t, _ := types.Evaluate(r.buf[int(v.offset+pss.offsetA):]) if t.Type() == "CodeString" { cs := t.(*types.CodeString) @@ -146,10 +152,16 @@ func (r *Reader) start(rdr io.Reader) error { dict = make(map[uint32]string) } } + dict = addDefaults(dict) for i, v := range psb.idsOffs { i += len(ps.idsOffs) r.Property[i] = &Property{} r.Property[i].Name = dict[v.id] + // don't try to evaluate dictionary property + if v.id == 0x00000000 { + r.Property[i].T = types.Null{} + continue + } t, _ := types.Evaluate(r.buf[int(v.offset+pss.offsetB):]) if t.Type() == "CodeString" { cs := t.(*types.CodeString) diff --git a/sets.go b/sets.go index b079a16..0de79b8 100644 --- a/sets.go +++ b/sets.go @@ -16,9 +16,17 @@ package msoleps import "github.com/richardlehane/msoleps/types" +func addDefaults(m map[uint32]string) map[uint32]string { + m[0x00000000] = "Dictionary" + m[0x00000001] = "CodePage" + m[0x80000000] = "Locale" + m[0x80000003] = "Behaviour" + return m + +} + var propertySets map[types.Guid]map[uint32]string = map[types.Guid]map[uint32]string{ types.MustGuidFromString("{D5CDD502-2E9C-101B-9397-08002B2CF9AE}"): map[uint32]string{ - 0x00000001: "CodePage", 0x00000002: "Category", 0x00000003: "Presentation Format", 0x00000004: "Byte count", @@ -47,7 +55,6 @@ var propertySets map[types.Guid]map[uint32]string = map[types.Guid]map[uint32]st 0x0000001D: "Document Version", }, types.MustGuidFromString("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"): map[uint32]string{ - 0x00000001: "CodePage", 0x00000002: "Title", 0x00000003: "Subject", 0x00000004: "Author", diff --git a/types/numeric.go b/types/numeric.go index f510a9c..0ddc387 100644 --- a/types/numeric.go +++ b/types/numeric.go @@ -19,6 +19,20 @@ import ( "strconv" ) +type Null struct{} + +func (i Null) Type() string { + return "Null" +} + +func (i Null) Length() int { + return 0 +} + +func (i Null) String() string { + return "" +} + type Bool bool func (i Bool) Type() string { diff --git a/types/types.go b/types/types.go index a2ca4fc..62f68ee 100644 --- a/types/types.go +++ b/types/types.go @@ -19,6 +19,7 @@ import ( "errors" ) +// MakeVariant is defined in vectorArray.go. It calls Evaluate, which refers to the MakeTypes map, so must add at runtime func init() { MakeTypes[VT_VARIANT] = MakeVariant } var (