From 4548fd56a596aa21737112aa49e8a8cf191bbf67 Mon Sep 17 00:00:00 2001 From: Gunnsteinn Hall Date: Sat, 2 Jun 2018 16:13:03 +0000 Subject: [PATCH] Add Len and Get methods to PdfObjectArray --- pdf/core/primitives.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pdf/core/primitives.go b/pdf/core/primitives.go index 461f2fbe..16a05f24 100644 --- a/pdf/core/primitives.go +++ b/pdf/core/primitives.go @@ -330,6 +330,22 @@ func (array *PdfObjectArray) Append(obj PdfObject) { *array = append(*array, obj) } +// Len returns the number of elements in the array. +func (array *PdfObjectArray) Len() int { + if array == nil { + return 0 + } + return len(*array) +} + +// Get returns the i-th element of the array or nil if out of bounds. +func (array *PdfObjectArray) Get(i int) PdfObject { + if array == nil || i >= len(*array) || i < 0 { + return nil + } + return (*array)[i] +} + func getNumberAsFloat(obj PdfObject) (float64, error) { if fObj, ok := obj.(*PdfObjectFloat); ok { return float64(*fObj), nil