MuPDF X.Y.Z

fitz/string-util.h

Index

macro

function

String Util

macro FZ_REPLACEMENT_CHARACTER

#define FZ_REPLACEMENT_CHARACTER 0xFFFD

The Unicode character used to incoming character whose value is unknown or unrepresentable.

Safe string functions

function fz_strnlen

size_t
fz_strnlen (
        const char *s,
        size_t maxlen
)

Return strlen(s), if that is less than maxlen, or maxlen if there is no null byte (‘\0’) among the first maxlen bytes.

function fz_strsep

char *
fz_strsep (
        char **stringp,
        const char *delim
)

Given a pointer to a C string (or a pointer to NULL) break it at the first occurrence of a delimiter char (from a given set).

stringp:
Pointer to a C string pointer (or NULL). Updated on exit to point to the first char of the string after the delimiter that was found. The string pointed to by stringp will be corrupted by this call (as the found delimiter will be overwritten by 0).
delim:
A C string of acceptable delimiter characters.

Returns a pointer to a C string containing the chars of stringp up to the first delimiter char (or the end of the string), or NULL.

function fz_strlcpy

size_t
fz_strlcpy (
        char *dst,
        const char *src,
        size_t n
)

Copy at most n-1 chars of a string into a destination buffer with null termination, returning the real length of the initial string (excluding terminator).

dst:
Destination buffer, at least n bytes long.
src:
C string (non-NULL).
n:
Size of dst buffer in bytes.

Returns the length (excluding terminator) of src.

function fz_strlcat

size_t
fz_strlcat (
        char *dst,
        const char *src,
        size_t n
)

Concatenate 2 strings, with a maximum length.

dst:
pointer to first string in a buffer of n bytes.
src:
pointer to string to concatenate.
n:
Size (in bytes) of buffer that dst is in.

Returns the real length that a concatenated dst + src would have been (not including terminator).

function fz_strstr

const char *
fz_strstr (
        const char *haystack,
        const char *needle
)

Safe strstr function.

haystack:
Where to look (may be NULL).
needled:
What to look for.

Returns NULL if unmatched, or pointer to start of match.

function fz_strstrcase

const char *
fz_strstrcase (
        const char *haystack,
        const char *needle
)

Safe case-insensitive strstr function. (Accepts UTF-8).

haystack:
Where to look (may be NULL).
needled:
What to look for.

Returns NULL if unmatched, or pointer to start of match.

function fz_memmem

void *
fz_memmem (
        const void *haystack,
        size_t haystacklen,
        const void *needle,
        size_t needlelen
)

Find the start of the first occurrence of the substring needle in haystack.

function fz_dirname

void
fz_dirname (
        char *dir,
        const char *path,
        size_t dirsize
)

extract the directory component from a path.

function fz_basename

const char *
fz_basename (
        const char *path
)

Find the filename component in a path.

function fz_strverscmp

int
fz_strverscmp (
        const char *s1,
        const char *s2
)

portable strverscmp(3) function

function fz_urldecode

char *
fz_urldecode (
        char *url
)

Like fz_decode_uri_component but in-place.

function fz_decode_uri

char *
fz_decode_uri (
        fz_context *ctx,
        const char *s
)

Return a new string representing the unencoded version of the given URI. This decodes all escape sequences except those that would result in a reserved character that are part of the URI syntax (; / ? : @ & = + $ , #).

function fz_decode_uri_component

char *
fz_decode_uri_component (
        fz_context *ctx,
        const char *s
)

Return a new string representing the unencoded version of the given URI component. This decodes all escape sequences!

function fz_encode_uri

char *
fz_encode_uri (
        fz_context *ctx,
        const char *s
)

Return a new string representing the provided string encoded as a URI.

function fz_encode_uri_component

char *
fz_encode_uri_component (
        fz_context *ctx,
        const char *s
)

Return a new string representing the provided string encoded as an URI component. This also encodes the special reserved characters (; / ? : @ & = + $ , #).

function fz_encode_uri_pathname

char *
fz_encode_uri_pathname (
        fz_context *ctx,
        const char *s
)

Return a new string representing the provided string encoded as an URI path name. This also encodes the special reserved characters except /.

function fz_format_output_path

void
fz_format_output_path (
        fz_context *ctx,
        char *path,
        size_t size,
        const char *fmt,
        int page
)

create output file name using a template.

If the path contains %[0-9]*d, the first such pattern will be replaced with the page number. If the template does not contain such a pattern, the page number will be inserted before the filename extension. If the template does not have a filename extension, the page number will be added to the end.

function fz_cleanname

char *
fz_cleanname (
        char *name
)

rewrite path to the shortest string that names the same path.

Eliminates multiple and trailing slashes, interprets “.” and “..”. Overwrites the string in place.

function fz_cleanname_strdup

char *
fz_cleanname_strdup (
        fz_context *ctx,
        const char *name
)

rewrite path to the shortest string that names the same path.

Eliminates multiple and trailing slashes, interprets “.” and “..”. Allocates a new string that the caller must free.

function fz_realpath

char *
fz_realpath (
        const char *path,
        char *resolved_path
)

Resolve a path to an absolute file name. The resolved path buffer must be of at least PATH_MAX size.

function fz_strcasecmp

int
fz_strcasecmp (
        const char *a,
        const char *b
)

Case insensitive (UTF8) string comparison.

function fz_strcasecmp_ascii

int
fz_strcasecmp_ascii (
        const char *a,
        const char *b
)

Case insensitive (Ascii) string comparison.

This will accept UTF8 strings, and not corrupt them, but won’t do the case insensitive folding on non-ascii characters, so will be slightly faster if you know you are only comparing ascii chars.

function fz_strncasecmp

int
fz_strncasecmp (
        const char *a,
        const char *b,
        size_t n
)

Case insensitive (UTF8) string comparison.

n = maximum number of bytes to read from either a or b.

macro FZ_UTFMAX

#define FZ_UTFMAX 4

FZ_UTFMAX: Maximum number of bytes in a decoded rune (maximum length returned by fz_chartorune).

function fz_chartorune

int
fz_chartorune (
        int *rune,
        const char *str
)

UTF8 decode a single rune from a sequence of chars.

rune:
Pointer to an int to assign the decoded ‘rune’ to. (0xFFFD on error).
str:
Pointer to a UTF8 encoded string.

Returns the number of bytes consumed.

function fz_chartorunen

int
fz_chartorunen (
        int *rune,
        const char *str,
        size_t n
)

UTF8 decode a single rune from a sequence of chars of given length.

rune:
Pointer to an int to assign the decoded ‘rune’ to. (0xFFFD on error).
str:
Pointer to a UTF8 encoded string.
n:
The number of bytes available at str.

Returns the number of bytes consumed.

function fz_runetochar

int
fz_runetochar (
        char *str,
        int rune
)

UTF8 encode a rune to a sequence of chars.

str:
Pointer to a place to put the UTF8 encoded character.
rune:
Pointer to a ‘rune’.

Returns the number of bytes the rune took to output.

function fz_runelen

int
fz_runelen (
        int rune
)

Count how many chars are required to represent a rune.

rune:
The rune to encode.

Returns the number of bytes required to represent this run in UTF8.

function fz_runeidx

int
fz_runeidx (
        const char *str,
        const char *p
)

Compute the index of a rune in a string.

str:
Pointer to beginning of a string.
p:
Pointer to a char in str.

Returns the index of the rune pointed to by p in str.

function fz_runeptr

const char *
fz_runeptr (
        const char *str,
        int idx
)

Obtain a pointer to the char representing the rune at a given index.

str:
Pointer to beginning of a string.
idx:
Index of a rune to return a char pointer to.

Returns a pointer to the char where the desired rune starts, or NULL if the string ends before the index is reached.

function fz_utflen

int
fz_utflen (
        const char *s
)

Count how many runes the UTF-8 encoded string consists of.

s:
The UTF-8 encoded, NUL-terminated text string.

Returns the number of runes in the string.

function fz_utf8_from_wchar

char *
fz_utf8_from_wchar (
        fz_context *ctx,
        const wchar_t *s
)

Convert a wchar string into a new heap allocated utf8 one.

function fz_wchar_from_utf8

wchar_t *
fz_wchar_from_utf8 (
        fz_context *ctx,
        const char *path
)

Convert a utf8 string into a new heap allocated wchar one.

function fz_strtof

float
fz_strtof (
        const char *s,
        char **es
)

Locale-independent decimal to binary conversion. On overflow return (-)INFINITY and set errno to ERANGE. On underflow return 0 and set errno to ERANGE. Special inputs (case insensitive): “NAN”, “INF” or “INFINITY”.

function fz_grisu

int
fz_grisu (
        float f,
        char *s,
        int *exp
)

function fz_is_page_range

int
fz_is_page_range (
        fz_context *ctx,
        const char *s
)

Check and parse string into page ranges: /,?(-?|N)(-(-?|N))?/

function fz_parse_page_range

const char *
fz_parse_page_range (
        fz_context *ctx,
        const char *s,
        int *a,
        int *b,
        int n
)

function fz_tolower

int
fz_tolower (
        int c
)

Unicode aware tolower and toupper and isalpha functions.

function fz_toupper

int
fz_toupper (
        int c
)

function fz_isalpha

int
fz_isalpha (
        int c
)

function fz_unpack_uint16

uint16_t
fz_unpack_uint16 (
        const uint8_t *p
)

Bit unpacking.

function fz_unpack_uint16_le

uint16_t
fz_unpack_uint16_le (
        const uint8_t *p
)

function fz_unpack_uint32

uint32_t
fz_unpack_uint32 (
        const uint8_t *p
)

function fz_unpack_uint32_le

uint32_t
fz_unpack_uint32_le (
        const uint8_t *p
)

function fz_unpack_uint64

uint64_t
fz_unpack_uint64 (
        const uint8_t *p
)

function fz_unpack_uint64_le

uint64_t
fz_unpack_uint64_le (
        const uint8_t *p
)

function fz_unpack_int16

int16_t
fz_unpack_int16 (
        const uint8_t *p
)

function fz_unpack_int16_le

int16_t
fz_unpack_int16_le (
        const uint8_t *p
)

function fz_unpack_int32

int32_t
fz_unpack_int32 (
        const uint8_t *p
)

function fz_unpack_int32_le

int32_t
fz_unpack_int32_le (
        const uint8_t *p
)

function fz_unpack_int64

int64_t
fz_unpack_int64 (
        const uint8_t *p
)

function fz_unpack_int64_le

int64_t
fz_unpack_int64_le (
        const uint8_t *p
)

function fz_unpack_float

float
fz_unpack_float (
        const uint8_t *p
)

function fz_unpack_float_le

float
fz_unpack_float_le (
        const uint8_t *p
)

function fz_unpack_double

double
fz_unpack_double (
        const uint8_t *p
)

function fz_unpack_double_le

double
fz_unpack_double_le (
        const uint8_t *p
)

function fz_pack_uint16

void
fz_pack_uint16 (
        uint8_t *p,
        uint16_t x
)

function fz_pack_uint32

void
fz_pack_uint32 (
        uint8_t *p,
        uint32_t x
)

function fz_pack_uint64

void
fz_pack_uint64 (
        uint8_t *p,
        uint64_t x
)

function fz_pack_uint16_le

void
fz_pack_uint16_le (
        uint8_t *p,
        uint16_t x
)

function fz_pack_uint32_le

void
fz_pack_uint32_le (
        uint8_t *p,
        uint32_t x
)

function fz_pack_uint64_le

void
fz_pack_uint64_le (
        uint8_t *p,
        uint64_t x
)

function fz_pack_float

void
fz_pack_float (
        uint8_t *p,
        float x
)

function fz_pack_double

void
fz_pack_double (
        uint8_t *p,
        double x
)

function fz_pack_float_le

void
fz_pack_float_le (
        uint8_t *p,
        float x
)

function fz_pack_double_le

void
fz_pack_double_le (
        uint8_t *p,
        double x
)