Skip to content

Commit

Permalink
add Null type
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlehane committed Oct 15, 2015
1 parent c0b86b7 commit 4cd1b2f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ 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)
}
}
}

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)
12 changes: 12 additions & 0 deletions msoleps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions types/numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 4cd1b2f

Please sign in to comment.