shithub: pdffs

Download patch

ref: d613b76a67a6dbb4d2c16a17e6994e7bdf2731df
parent: b4e6b3b89646f4dd5973b770b36aba511843624e
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Aug 31 07:50:06 EDT 2020

add array helpers

--- a/array.c
+++ b/array.c
@@ -51,3 +51,25 @@
 	pdfobjfree(o);
 	return nil;
 }
+
+int
+arraylen(Object *o)
+{
+	if(o == nil || o == &null)
+		return 0;
+	return (o->type == Oarray) ? o->array.ne : 1;
+}
+
+Object *
+arrayget(Object *o, int i)
+{
+	if(arraylen(o) <= i)
+		sysfatal("array: indexing out of range");
+	return o->type == Oarray ? o->array.e[i] : o;
+}
+
+int
+arrayint(Object *o, int i)
+{
+	return (o = arrayget(o, i))->type == Onum ? o->num : 0;
+}
--- a/pdf.h
+++ b/pdf.h
@@ -150,6 +150,10 @@
  */
 int isdelim(int c);
 
+int arraylen(Object *o);
+Object *arrayget(Object *o, int i);
+int arrayint(Object *o, int i);
+
 Object *dictget(Object *o, char *name);
 vlong dictint(Object *o, char *name);
 char *dictstring(Object *o, char *name);