1 /* Elementary Unicode string functions.
2 Copyright (C) 2002, 2005-2007, 2009-2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
35 /* These work like the printf function family.
37 The format directive 'U' takes an UTF-8 string (const uint8_t *).
38 The format directive 'lU' takes an UTF-16 string (const uint16_t *).
39 The format directive 'llU' takes an UTF-32 string (const uint32_t *).
41 The prefix (ulc_, u8_, u16_, u16_) indicates the type of the resulting
42 string. The prefix 'ulc' stands for "locale encoded".
44 An infix 'v' indicates that a va_list is passed instead of multiple
47 The functions *sprintf have a 'buf' argument that is assumed to be large
48 enough. (DANGEROUS! Overflowing the buffer will crash the program.)
49 The functions *snprintf have a 'buf' argument that is assumed to be 'size'
50 units large. (DANGEROUS! The resulting string might be truncated in the
51 middle of a multibyte character.)
52 The functions *asprintf have a 'resultp' argument. The result will be
53 freshly allocated and stored in *resultp.
54 The functions *asnprintf have a (resultbuf, lengthp) argument pair. If
55 resultbuf is not NULL and the result fits into *lengthp units, it is put
56 in resultbuf, and resultbuf is returned. Otherwise, a freshly allocated
57 string is returned. In both cases, *lengthp is set to the length (number
58 of units) of the returned string. In case of error, NULL is returned and
62 /* ASCII format string, result in locale dependent encoded 'char *'. */
64 ulc_sprintf (char *_UC_RESTRICT buf
,
65 const char *format
, ...);
67 ulc_snprintf (char *_UC_RESTRICT buf
, size_t size
,
68 const char *format
, ...);
70 ulc_asprintf (char **resultp
,
71 const char *format
, ...);
73 ulc_asnprintf (char *_UC_RESTRICT resultbuf
, size_t *lengthp
,
74 const char *format
, ...);
76 ulc_vsprintf (char *_UC_RESTRICT buf
,
77 const char *format
, va_list ap
);
79 ulc_vsnprintf (char *_UC_RESTRICT buf
, size_t size
,
80 const char *format
, va_list ap
);
82 ulc_vasprintf (char **resultp
,
83 const char *format
, va_list ap
);
85 ulc_vasnprintf (char *_UC_RESTRICT resultbuf
, size_t *lengthp
,
86 const char *format
, va_list ap
);
88 /* ASCII format string, result in UTF-8 format. */
90 u8_sprintf (uint8_t *buf
,
91 const char *format
, ...);
93 u8_snprintf (uint8_t *buf
, size_t size
,
94 const char *format
, ...);
96 u8_asprintf (uint8_t **resultp
,
97 const char *format
, ...);
99 u8_asnprintf (uint8_t *resultbuf
, size_t *lengthp
,
100 const char *format
, ...);
102 u8_vsprintf (uint8_t *buf
,
103 const char *format
, va_list ap
);
105 u8_vsnprintf (uint8_t *buf
, size_t size
,
106 const char *format
, va_list ap
);
108 u8_vasprintf (uint8_t **resultp
,
109 const char *format
, va_list ap
);
111 u8_vasnprintf (uint8_t *resultbuf
, size_t *lengthp
,
112 const char *format
, va_list ap
);
114 /* UTF-8 format string, result in UTF-8 format. */
116 u8_u8_sprintf (uint8_t *_UC_RESTRICT buf
,
117 const uint8_t *format
, ...);
119 u8_u8_snprintf (uint8_t *_UC_RESTRICT buf
, size_t size
,
120 const uint8_t *format
, ...);
122 u8_u8_asprintf (uint8_t **resultp
,
123 const uint8_t *format
, ...);
125 u8_u8_asnprintf (uint8_t *_UC_RESTRICT resultbuf
, size_t *lengthp
,
126 const uint8_t *format
, ...);
128 u8_u8_vsprintf (uint8_t *_UC_RESTRICT buf
,
129 const uint8_t *format
, va_list ap
);
131 u8_u8_vsnprintf (uint8_t *_UC_RESTRICT buf
, size_t size
,
132 const uint8_t *format
, va_list ap
);
134 u8_u8_vasprintf (uint8_t **resultp
,
135 const uint8_t *format
, va_list ap
);
137 u8_u8_vasnprintf (uint8_t *_UC_RESTRICT resultbuf
, size_t *lengthp
,
138 const uint8_t *format
, va_list ap
);
140 /* ASCII format string, result in UTF-16 format. */
142 u16_sprintf (uint16_t *buf
,
143 const char *format
, ...);
145 u16_snprintf (uint16_t *buf
, size_t size
,
146 const char *format
, ...);
148 u16_asprintf (uint16_t **resultp
,
149 const char *format
, ...);
151 u16_asnprintf (uint16_t *resultbuf
, size_t *lengthp
,
152 const char *format
, ...);
154 u16_vsprintf (uint16_t *buf
,
155 const char *format
, va_list ap
);
157 u16_vsnprintf (uint16_t *buf
, size_t size
,
158 const char *format
, va_list ap
);
160 u16_vasprintf (uint16_t **resultp
,
161 const char *format
, va_list ap
);
163 u16_vasnprintf (uint16_t *resultbuf
, size_t *lengthp
,
164 const char *format
, va_list ap
);
166 /* UTF-16 format string, result in UTF-16 format. */
168 u16_u16_sprintf (uint16_t *_UC_RESTRICT buf
,
169 const uint16_t *format
, ...);
171 u16_u16_snprintf (uint16_t *_UC_RESTRICT buf
, size_t size
,
172 const uint16_t *format
, ...);
174 u16_u16_asprintf (uint16_t **resultp
,
175 const uint16_t *format
, ...);
177 u16_u16_asnprintf (uint16_t *_UC_RESTRICT resultbuf
, size_t *lengthp
,
178 const uint16_t *format
, ...);
180 u16_u16_vsprintf (uint16_t *_UC_RESTRICT buf
,
181 const uint16_t *format
, va_list ap
);
183 u16_u16_vsnprintf (uint16_t *_UC_RESTRICT buf
, size_t size
,
184 const uint16_t *format
, va_list ap
);
186 u16_u16_vasprintf (uint16_t **resultp
,
187 const uint16_t *format
, va_list ap
);
189 u16_u16_vasnprintf (uint16_t *_UC_RESTRICT resultbuf
, size_t *lengthp
,
190 const uint16_t *format
, va_list ap
);
192 /* ASCII format string, result in UTF-32 format. */
194 u32_sprintf (uint32_t *buf
,
195 const char *format
, ...);
197 u32_snprintf (uint32_t *buf
, size_t size
,
198 const char *format
, ...);
200 u32_asprintf (uint32_t **resultp
,
201 const char *format
, ...);
203 u32_asnprintf (uint32_t *resultbuf
, size_t *lengthp
,
204 const char *format
, ...);
206 u32_vsprintf (uint32_t *buf
,
207 const char *format
, va_list ap
);
209 u32_vsnprintf (uint32_t *buf
, size_t size
,
210 const char *format
, va_list ap
);
212 u32_vasprintf (uint32_t **resultp
,
213 const char *format
, va_list ap
);
215 u32_vasnprintf (uint32_t *resultbuf
, size_t *lengthp
,
216 const char *format
, va_list ap
);
218 /* UTF-32 format string, result in UTF-32 format. */
220 u32_u32_sprintf (uint32_t *_UC_RESTRICT buf
,
221 const uint32_t *format
, ...);
223 u32_u32_snprintf (uint32_t *_UC_RESTRICT buf
, size_t size
,
224 const uint32_t *format
, ...);
226 u32_u32_asprintf (uint32_t **resultp
,
227 const uint32_t *format
, ...);
229 u32_u32_asnprintf (uint32_t *_UC_RESTRICT resultbuf
, size_t *lengthp
,
230 const uint32_t *format
, ...);
232 u32_u32_vsprintf (uint32_t *_UC_RESTRICT buf
,
233 const uint32_t *format
, va_list ap
);
235 u32_u32_vsnprintf (uint32_t *_UC_RESTRICT buf
, size_t size
,
236 const uint32_t *format
, va_list ap
);
238 u32_u32_vasprintf (uint32_t **resultp
,
239 const uint32_t *format
, va_list ap
);
241 u32_u32_vasnprintf (uint32_t *_UC_RESTRICT resultbuf
, size_t *lengthp
,
242 const uint32_t *format
, va_list ap
);
244 /* ASCII format string, output to FILE in locale dependent encoding. */
246 ulc_fprintf (FILE *stream
,
247 const char *format
, ...);
249 ulc_vfprintf (FILE *stream
,
250 const char *format
, va_list ap
);
256 #endif /* _UNISTDIO_H */