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
51 pdfobjfree(o);51 pdfobjfree(o);
52 return nil;52 return nil;
53}53}
54
55int
56arraylen(Object *o)
57{
58 if(o == nil || o == &null)
59 return 0;
60 return (o->type == Oarray) ? o->array.ne : 1;
61}
62
63Object *
64arrayget(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
71int
72arrayint(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