mupdf
Loading...
Searching...
No Matches
string-util.h
Go to the documentation of this file.
1// Copyright (C) 2004-2025 Artifex Software, Inc.
2//
3// This file is part of MuPDF.
4//
5// MuPDF is free software: you can redistribute it and/or modify it under the
6// terms of the GNU Affero General Public License as published by the Free
7// Software Foundation, either version 3 of the License, or (at your option)
8// any later version.
9//
10// MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13// details.
14//
15// You should have received a copy of the GNU Affero General Public License
16// along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17//
18// Alternative licensing terms are available from the licensor.
19// For commercial licensing, see <https://www.artifex.com/> or contact
20// Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21// CA 94129, USA, for further information.
22
23#ifndef MUPDF_FITZ_STRING_H
24#define MUPDF_FITZ_STRING_H
25
26#include "mupdf/fitz/system.h"
27#include "mupdf/fitz/context.h"
28
29/* The Unicode character used to incoming character whose value is
30 * unknown or unrepresentable. */
31#define FZ_REPLACEMENT_CHARACTER 0xFFFD
32
36
41size_t fz_strnlen(const char *s, size_t maxlen);
42
60char *fz_strsep(char **stringp, const char *delim);
61
75size_t fz_strlcpy(char *dst, const char *src, size_t n);
76
89size_t fz_strlcat(char *dst, const char *src, size_t n);
90
100const char *fz_strstr(const char *haystack, const char *needle);
101
111const char *fz_strstrcase(const char *haystack, const char *needle);
112
116void *fz_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen);
117
121void fz_dirname(char *dir, const char *path, size_t dirsize);
122
126const char *fz_basename(const char *path);
127
131int fz_strverscmp(const char *s1, const char *s2);
132
136char *fz_urldecode(char *url);
137
143char *fz_decode_uri(fz_context *ctx, const char *s);
144
149char *fz_decode_uri_component(fz_context *ctx, const char *s);
150
154char *fz_encode_uri(fz_context *ctx, const char *s);
155
160char *fz_encode_uri_component(fz_context *ctx, const char *s);
161
166char *fz_encode_uri_pathname(fz_context *ctx, const char *s);
167
177void fz_format_output_path(fz_context *ctx, char *path, size_t size, const char *fmt, int page);
178
185char *fz_cleanname(char *name);
186
193char *fz_cleanname_strdup(fz_context *ctx, const char *name);
194
199char *fz_realpath(const char *path, char *resolved_path);
200
204int fz_strcasecmp(const char *a, const char *b);
205
211int fz_strncasecmp(const char *a, const char *b, size_t n);
212
217enum { FZ_UTFMAX = 4 };
218
229int fz_chartorune(int *rune, const char *str);
230
244int fz_chartorunen(int *rune, const char *str, size_t n);
245
255int fz_runetochar(char *str, int rune);
256
265int fz_runelen(int rune);
266
276int fz_runeidx(const char *str, const char *p);
277
289const char *fz_runeptr(const char *str, int idx);
290
299int fz_utflen(const char *s);
300
301/*
302 Convert a wchar string into a new heap allocated utf8 one.
303*/
304char *fz_utf8_from_wchar(fz_context *ctx, const wchar_t *s);
305
306/*
307 Convert a utf8 string into a new heap allocated wchar one.
308*/
309wchar_t *fz_wchar_from_utf8(fz_context *ctx, const char *path);
310
311
318float fz_strtof(const char *s, char **es);
319
320int fz_grisu(float f, char *s, int *exp);
321
326int fz_is_page_range(fz_context *ctx, const char *s);
327const char *fz_parse_page_range(fz_context *ctx, const char *s, int *a, int *b, int n);
328
332int fz_tolower(int c);
333int fz_toupper(int c);
334
338
339static inline uint16_t fz_unpack_uint16(const uint8_t *p)
340{
341 return (uint16_t)p[0] << 8 | (uint16_t)p[1];
342}
343
344static inline uint16_t fz_unpack_uint16_le(const uint8_t *p)
345{
346 return (uint16_t)p[1] << 8 | (uint16_t)p[0];
347}
348
349static inline uint32_t fz_unpack_uint32(const uint8_t *p)
350{
351 return (uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | (uint32_t)p[3];
352}
353
354static inline uint32_t fz_unpack_uint32_le(const uint8_t *p)
355{
356 return (uint32_t)p[3] << 24 | (uint32_t)p[2] << 16 | (uint32_t)p[1] << 8 | (uint32_t)p[0];
357}
358
359static inline uint64_t fz_unpack_uint64(const uint8_t *p)
360{
361 return (
362 (uint64_t)p[0]<<56 | (uint64_t)p[1]<<48 | (uint64_t)p[2]<<40 | (uint64_t)p[3]<<32 |
363 (uint64_t)p[4]<<24 | (uint64_t)p[5]<<16 | (uint64_t)p[6]<<8 | (uint64_t)p[7]
364 );
365}
366
367static inline uint64_t fz_unpack_uint64_le(const uint8_t *p)
368{
369 return (
370 (uint64_t)p[7]<<56 | (uint64_t)p[6]<<48 | (uint64_t)p[5]<<40 | (uint64_t)p[4]<<32 |
371 (uint64_t)p[3]<<24 | (uint64_t)p[2]<<16 | (uint64_t)p[1]<<8 | (uint64_t)p[0]
372 );
373}
374
375static inline int16_t fz_unpack_int16(const uint8_t *p) { return fz_unpack_uint16(p); }
376static inline int16_t fz_unpack_int16_le(const uint8_t *p) { return fz_unpack_uint16_le(p); }
377static inline int32_t fz_unpack_int32(const uint8_t *p) { return fz_unpack_uint32(p); }
378static inline int32_t fz_unpack_int32_le(const uint8_t *p) { return fz_unpack_uint32_le(p); }
379static inline int64_t fz_unpack_int64(const uint8_t *p) { return fz_unpack_uint64(p); }
380static inline int64_t fz_unpack_int64_le(const uint8_t *p) { return fz_unpack_uint64_le(p); }
381
382static inline float fz_unpack_float(const uint8_t *p)
383{
384 uint32_t u = fz_unpack_uint32(p);
385 float x;
386 memcpy(&x, &u, sizeof x);
387 return x;
388}
389
390static inline float fz_unpack_float_le(const uint8_t *p)
391{
392 uint32_t u = fz_unpack_uint32_le(p);
393 float x;
394 memcpy(&x, &u, sizeof x);
395 return x;
396}
397
398static inline double fz_unpack_double(const uint8_t *p)
399{
400 uint64_t u = fz_unpack_uint64(p);
401 double x;
402 memcpy(&x, &u, sizeof x);
403 return x;
404}
405
406static inline double fz_unpack_double_le(const uint8_t *p)
407{
408 uint64_t u = fz_unpack_uint64_le(p);
409 double x;
410 memcpy(&x, &u, sizeof x);
411 return x;
412}
413
414static inline void fz_pack_uint16(uint8_t *p, uint16_t x)
415{
416 p[0] = x >> 8;
417 p[1] = x;
418}
419
420static inline void fz_pack_uint32(uint8_t *p, uint32_t x)
421{
422 p[0] = x >> 24;
423 p[1] = x >> 16;
424 p[2] = x >> 8;
425 p[3] = x;
426}
427
428static inline void fz_pack_uint64(uint8_t *p, uint64_t x)
429{
430 p[0] = x >> 56;
431 p[1] = x >> 48;
432 p[2] = x >> 40;
433 p[3] = x >> 32;
434 p[4] = x >> 24;
435 p[5] = x >> 16;
436 p[6] = x >> 8;
437 p[7] = x;
438}
439
440static inline void fz_pack_uint16_le(uint8_t *p, uint16_t x)
441{
442 p[0] = x;
443 p[1] = x >> 8;
444}
445
446static inline void fz_pack_uint32_le(uint8_t *p, uint32_t x)
447{
448 p[0] = x;
449 p[1] = x >> 8;
450 p[2] = x >> 16;
451 p[3] = x >> 24;
452}
453
454static inline void fz_pack_uint64_le(uint8_t *p, uint64_t x)
455{
456 p[0] = x;
457 p[1] = x >> 8;
458 p[2] = x >> 16;
459 p[3] = x >> 24;
460 p[4] = x >> 32;
461 p[5] = x >> 40;
462 p[6] = x >> 48;
463 p[7] = x >> 56;
464}
465
466static inline void fz_pack_float(uint8_t *p, float x)
467{
468 uint32_t u;
469 memcpy(&u, &x, sizeof u);
470 fz_pack_uint32(p, u);
471}
472
473static inline void fz_pack_double(uint8_t *p, double x)
474{
475 uint64_t u;
476 memcpy(&u, &x, sizeof u);
477 fz_pack_uint64(p, u);
478}
479
480static inline void fz_pack_float_le(uint8_t *p, float x)
481{
482 uint32_t u;
483 memcpy(&u, &x, sizeof u);
484 fz_pack_uint32_le(p, u);
485}
486
487static inline void fz_pack_double_le(uint8_t *p, double x)
488{
489 uint64_t u;
490 memcpy(&u, &x, sizeof u);
491 fz_pack_uint64_le(p, u);
492}
493
494#endif
int fz_chartorunen(int *rune, const char *str, size_t n)
int fz_runelen(int rune)
void fz_format_output_path(fz_context *ctx, char *path, size_t size, const char *fmt, int page)
void fz_dirname(char *dir, const char *path, size_t dirsize)
int fz_strverscmp(const char *s1, const char *s2)
int fz_runeidx(const char *str, const char *p)
int fz_utflen(const char *s)
int fz_strcasecmp(const char *a, const char *b)
char * fz_encode_uri(fz_context *ctx, const char *s)
char * fz_encode_uri_pathname(fz_context *ctx, const char *s)
char * fz_urldecode(char *url)
int fz_chartorune(int *rune, const char *str)
char * fz_realpath(const char *path, char *resolved_path)
char * fz_cleanname_strdup(fz_context *ctx, const char *name)
int fz_is_page_range(fz_context *ctx, const char *s)
char * fz_utf8_from_wchar(fz_context *ctx, const wchar_t *s)
char * fz_cleanname(char *name)
char * fz_encode_uri_component(fz_context *ctx, const char *s)
int fz_strncasecmp(const char *a, const char *b, size_t n)
int fz_tolower(int c)
@ FZ_UTFMAX
Definition string-util.h:217
const char * fz_strstrcase(const char *haystack, const char *needle)
const char * fz_parse_page_range(fz_context *ctx, const char *s, int *a, int *b, int n)
void * fz_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
int fz_toupper(int c)
wchar_t * fz_wchar_from_utf8(fz_context *ctx, const char *path)
size_t fz_strlcat(char *dst, const char *src, size_t n)
char * fz_decode_uri_component(fz_context *ctx, const char *s)
const char * fz_strstr(const char *haystack, const char *needle)
char * fz_strsep(char **stringp, const char *delim)
size_t fz_strnlen(const char *s, size_t maxlen)
int fz_runetochar(char *str, int rune)
const char * fz_basename(const char *path)
int fz_grisu(float f, char *s, int *exp)
size_t fz_strlcpy(char *dst, const char *src, size_t n)
char * fz_decode_uri(fz_context *ctx, const char *s)
float fz_strtof(const char *s, char **es)
const char * fz_runeptr(const char *str, int idx)
Definition context.h:886