comparison mupdf-source/docs/reference/c/fitz/strings.md @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 # Strings
2
3 All text strings in MuPDF use the `UTF-8` encoding.
4
5 ## Unicode
6
7 The following functions encode and decode `UTF-8` characters, and return the
8 number of bytes used by the `UTF-8` character (at most `FZ_UTFMAX`).
9
10 int fz_chartorune(int *rune, const char *str);
11 int fz_runetochar(char *str, int rune);
12
13 ## Locale Independent
14
15 Since many of the C string functions are locale dependent, we also provide our
16 own locale independent versions of these functions. We also have a couple of
17 semi-standard functions like `strsep` and `strlcpy` that we can't rely on the
18 system providing. These should be pretty self explanatory:
19
20 char *fz_strdup(fz_context *ctx, const char *s);
21 float fz_strtof(const char *s, char **es);
22 char *fz_strsep(char **stringp, const char *delim);
23 size_t fz_strlcpy(char *dst, const char *src, size_t n);
24 size_t fz_strlcat(char *dst, const char *src, size_t n);
25 void *fz_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen);
26 int fz_strcasecmp(const char *a, const char *b);
27
28 There are also a couple of functions to process filenames and URLs:
29
30 `char *fz_cleanname(char *path);`
31 : Rewrite path in-place to the shortest string that names the same path.
32 Eliminates multiple and trailing slashes, and interprets "." and "..".
33
34 `void fz_dirname(char *dir, const char *path, size_t dir_size);`
35 : Extract the directory component from a path.
36
37 `char *fz_urldecode(char *url);`
38 : Decode URL escapes in-place.
39
40 ## Formatting
41
42 Our `printf` family handles the common `printf` formatting characters, with a
43 few minor differences. We also support several non-standard formatting
44 characters. The same `printf` syntax is used in the `printf` functions in the
45 I/O module as well.
46
47 size_t fz_vsnprintf(char *buffer, size_t space, const char *fmt, va_list args);
48 size_t fz_snprintf(char *buffer, size_t space, const char *fmt, ...);
49 char *fz_asprintf(fz_context *ctx, const char *fmt, ...);
50
51 `%%`, `%c`, `%e`, `%f`, `%p`, `%x`, `%d`, `%u`, `%s`
52 : These behave as usual, but only take padding (+,0,space), width, and precision arguments.
53
54 `%g float`
55 : Prints the `float` in the shortest possible format that won't lose precision, except `NaN` to `0`, `+Inf` to `FLT_MAX`, `-Inf` to `-FLT_MAX`.
56
57 `%M fz_matrix*`
58 : Prints all 6 coefficients in the matrix as `%g` separated by spaces.
59
60 `%R fz_rect*`
61 : Prints all `x0`, `y0`, `x1`, `y1` in the rectangle as `%g` separated by spaces.
62
63 `%P fz_point*`
64 : Prints `x`, `y` in the point as `%g` separated by spaces.
65
66 `%C int`
67 : Formats character as `UTF-8`. Useful to print unicode text.
68
69 `%q char*`
70 : Formats string using double quotes and C escapes.
71
72 `%( char*`
73 : Formats string using parenthesis quotes and Postscript escapes.
74
75 `%n char*`
76 : Formats string using prefix `/` and PDF name hex-escapes.