summaryrefslogtreecommitdiff
path: root/source/fitz/buffer.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-04-14 00:42:49 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-04-26 15:12:57 +0200
commit445bcc8f464252649ae5d13add727420abe661d7 (patch)
tree94d4b00ce0eebafec9f8905e2c3611fd7144ef97 /source/fitz/buffer.c
parentf0d993da8a086aaac201ec3c5e246446e9b40987 (diff)
downloadmupdf-445bcc8f464252649ae5d13add727420abe661d7.tar.xz
Add base64 string decoder.
Diffstat (limited to 'source/fitz/buffer.c')
-rw-r--r--source/fitz/buffer.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c
index 6f0e7057..2d6f9932 100644
--- a/source/fitz/buffer.c
+++ b/source/fitz/buffer.c
@@ -57,6 +57,37 @@ fz_new_buffer_from_shared_data(fz_context *ctx, const char *data, int size)
}
fz_buffer *
+fz_new_buffer_from_base64(fz_context *ctx, const char *data, int size)
+{
+ fz_buffer *buf = fz_new_buffer(ctx, size);
+ const char *end = data + size;
+ const char *s = data;
+ fz_try(ctx)
+ {
+ while (s < end)
+ {
+ int c = *s++;
+ if (c >= 'A' && c <= 'Z')
+ fz_write_buffer_bits(ctx, buf, c - 'A', 6);
+ else if (c >= 'a' && c <= 'z')
+ fz_write_buffer_bits(ctx, buf, c - 'a' + 26, 6);
+ else if (c >= '0' && c <= '9')
+ fz_write_buffer_bits(ctx, buf, c - '0' + 52, 6);
+ else if (c == '+')
+ fz_write_buffer_bits(ctx, buf, 62, 6);
+ else if (c == '/')
+ fz_write_buffer_bits(ctx, buf, 63, 6);
+ }
+ }
+ fz_catch(ctx)
+ {
+ fz_drop_buffer(ctx, buf);
+ fz_rethrow(ctx);
+ }
+ return buf;
+}
+
+fz_buffer *
fz_keep_buffer(fz_context *ctx, fz_buffer *buf)
{
if (buf)