History

add array helpers

Sigrid Haflínudóttir committed 6 years ago

Commit d613b761 parent b4e6b3b2 files · +26 −0Browse files

Showing the changes to array.c (1 of 2 files). Show all

Unified · Split

array.c+22−0
@@ -51,3 +51,25 @@ err: · 50 unmodified lines
5151 pdfobjfree(o);
5252 return nil;
5353 }
54+
55+int
56+arraylen(Object *o)
57+{
58+ if(o == nil || o == &null)
59+ return 0;
60+ return (o->type == Oarray) ? o->array.ne : 1;
61+}
62+
63+Object *
64+arrayget(Object *o, int i)
65+{
66+ if(arraylen(o) <= i)
67+ sysfatal("array: indexing out of range");
68+ return o->type == Oarray ? o->array.e[i] : o;
69+}
70+
71+int
72+arrayint(Object *o, int i)
73+{
74+ return (o = arrayget(o, i))->type == Onum ? o->num : 0;
75+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t