diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-08-17 15:03:43 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-08-24 14:09:06 +0200 |
commit | d88fc90e806a72f90667ec780f3370794cbc0c42 (patch) | |
tree | 4197758cf043c96a427dffb90895e4dbd6281044 | |
parent | 7bb57105fad01e11c251f3b464d2719df2632c08 (diff) | |
download | mupdf-d88fc90e806a72f90667ec780f3370794cbc0c42.tar.xz |
Add pdf_array_find to look up the index of an object in an array.
-rw-r--r-- | include/mupdf/pdf/object.h | 1 | ||||
-rw-r--r-- | source/pdf/pdf-object.c | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/include/mupdf/pdf/object.h b/include/mupdf/pdf/object.h index cfae8645..5bc3dcaf 100644 --- a/include/mupdf/pdf/object.h +++ b/include/mupdf/pdf/object.h @@ -95,6 +95,7 @@ void pdf_array_push_drop(fz_context *ctx, pdf_obj *array, pdf_obj *obj); void pdf_array_insert(fz_context *ctx, pdf_obj *array, pdf_obj *obj, int index); void pdf_array_insert_drop(fz_context *ctx, pdf_obj *array, pdf_obj *obj, int index); void pdf_array_delete(fz_context *ctx, pdf_obj *array, int index); +int pdf_array_find(fz_context *ctx, pdf_obj *array, pdf_obj *obj); int pdf_array_contains(fz_context *ctx, pdf_obj *array, pdf_obj *obj); int pdf_dict_len(fz_context *ctx, pdf_obj *dict); diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c index 8fcbceda..10eb6690 100644 --- a/source/pdf/pdf-object.c +++ b/source/pdf/pdf-object.c @@ -808,6 +808,19 @@ pdf_array_contains(fz_context *ctx, pdf_obj *arr, pdf_obj *obj) return 0; } +int +pdf_array_find(fz_context *ctx, pdf_obj *arr, pdf_obj *obj) +{ + int i, len; + + len = pdf_array_len(ctx, arr); + for (i = 0; i < len; i++) + if (!pdf_objcmp(ctx, pdf_array_get(ctx, arr, i), obj)) + return i; + + return -1; +} + pdf_obj *pdf_new_rect(fz_context *ctx, pdf_document *doc, const fz_rect *rect) { pdf_obj *arr = NULL; |