Lely core libraries
2.3.4
|
This file is part of the utilities library; it contains the implementation of the printing functions. More...
#include "util.h"
#include <lely/libc/stdio.h>
#include <lely/libc/uchar.h>
#include <lely/util/lex.h>
#include <lely/util/print.h>
#include <assert.h>
#include <float.h>
#include <stdint.h>
#include <string.h>
Go to the source code of this file.
Functions | |
size_t | print_fmt (char **pbegin, char *end, const char *format,...) |
Prints a formatted string to a memory buffer. More... | |
size_t | vprint_fmt (char **pbegin, char *end, const char *format, va_list ap) |
Prints a formatted string to a memory buffer. More... | |
size_t | print_utf8 (char **pbegin, char *end, char32_t c32) |
Prints a UTF-8 encoded Unicode character to a memory buffer. More... | |
size_t | print_c99_esc (char **pbegin, char *end, char32_t c32) |
Prints a UTF-8 encoded Unicode character to a memory buffer. More... | |
size_t | print_c99_str (char **pbegin, char *end, const char *s, size_t n) |
Prints a UTF-8 encoded Unicode string to a memory buffer. More... | |
size_t | print_c99_long (char **pbegin, char *end, long l) |
Prints a C99 long to a memory buffer. More... | |
size_t | print_c99_ulong (char **pbegin, char *end, unsigned long ul) |
Prints a C99 unsigned long to a memory buffer. More... | |
size_t | print_c99_llong (char **pbegin, char *end, long long ll) |
Prints a C99 long long to a memory buffer. More... | |
size_t | print_c99_ullong (char **pbegin, char *end, unsigned long long ull) |
Prints a C99 unsigned long long to a memory buffer. More... | |
size_t | print_c99_flt (char **pbegin, char *end, float f) |
Prints a C99 float to a memory buffer. More... | |
size_t | print_c99_dbl (char **pbegin, char *end, double d) |
Prints a C99 double to a memory buffer. More... | |
size_t | print_c99_ldbl (char **pbegin, char *end, long double ld) |
Prints a C99 long double to a memory buffer. More... | |
size_t | print_c99_i8 (char **pbegin, char *end, int_least8_t i8) |
Prints a C99 int_least8_t to a memory buffer. More... | |
size_t | print_c99_i16 (char **pbegin, char *end, int_least16_t i16) |
Prints a C99 int_least16_t to a memory buffer. More... | |
size_t | print_c99_i32 (char **pbegin, char *end, int_least32_t i32) |
Prints a C99 int_least32_t to a memory buffer. More... | |
size_t | print_c99_i64 (char **pbegin, char *end, int_least64_t i64) |
Prints a C99 int_least64_t to a memory buffer. More... | |
size_t | print_c99_u8 (char **pbegin, char *end, uint_least8_t u8) |
Prints a C99 uint_least8_t to a memory buffer. More... | |
size_t | print_c99_u16 (char **pbegin, char *end, uint_least16_t u16) |
Prints a C99 uint_least16_t to a memory buffer. More... | |
size_t | print_c99_u32 (char **pbegin, char *end, uint_least32_t u32) |
Prints a C99 uint_least32_t to a memory buffer. More... | |
size_t | print_c99_u64 (char **pbegin, char *end, uint_least64_t u64) |
Prints a C99 uint_least64_t to a memory buffer. More... | |
size_t | print_base64 (char **pbegin, char *end, const void *ptr, size_t n) |
Prints the Base64 representation of binary data to a memory buffer. More... | |
This file is part of the utilities library; it contains the implementation of the printing functions.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Definition in file print.c.
size_t print_fmt | ( | char ** | pbegin, |
char * | end, | ||
const char * | format, | ||
... | |||
) |
Prints a formatted string to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written. |
format | a printf-style format string. |
... | an optional list of arguments to be printed according to format. |
size_t vprint_fmt | ( | char ** | pbegin, |
char * | end, | ||
const char * | format, | ||
va_list | ap | ||
) |
Prints a formatted string to a memory buffer.
This function is equivalent to print_fmt(), except that it accepts a va_list
instead of a variable number of arguments.
size_t print_utf8 | ( | char ** | pbegin, |
char * | end, | ||
char32_t | c32 | ||
) |
Prints a UTF-8 encoded Unicode character to a memory buffer.
Illegal Unicode code points are silently replaced by the Unicode replacement character (U+FFFD). Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
c32 | the Unicode character to be written. |
size_t print_c99_esc | ( | char ** | pbegin, |
char * | end, | ||
char32_t | c32 | ||
) |
Prints a UTF-8 encoded Unicode character to a memory buffer.
Non-printable ASCII characters are printed using C99 escape sequences, illegal Unicode code points using hexadecimal escape sequences. Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
c32 | the Unicode character to be written. |
size_t print_c99_str | ( | char ** | pbegin, |
char * | end, | ||
const char * | s, | ||
size_t | n | ||
) |
Prints a UTF-8 encoded Unicode string to a memory buffer.
Non-printable ASCII characters are printed using C99 escape sequences, illegal Unicode code points using hexadecimal escape sequences. Note that the output is not delimited by double quotes and not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
s | a pointer to the string to be written. |
n | the number of characters at s. |
size_t print_c99_long | ( | char ** | pbegin, |
char * | end, | ||
long | l | ||
) |
Prints a C99 long
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
l | the value to be written. |
size_t print_c99_ulong | ( | char ** | pbegin, |
char * | end, | ||
unsigned long | ul | ||
) |
Prints a C99 unsigned long
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
ul | the value to be written. |
size_t print_c99_llong | ( | char ** | pbegin, |
char * | end, | ||
long long | ll | ||
) |
Prints a C99 long long
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
ll | the value to be written. |
size_t print_c99_ullong | ( | char ** | pbegin, |
char * | end, | ||
unsigned long long | ul | ||
) |
Prints a C99 unsigned long long
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
ul | the value to be written. |
size_t print_c99_flt | ( | char ** | pbegin, |
char * | end, | ||
float | f | ||
) |
Prints a C99 float
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
f | the value to be written. |
size_t print_c99_dbl | ( | char ** | pbegin, |
char * | end, | ||
double | d | ||
) |
Prints a C99 double
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
d | the value to be written. |
size_t print_c99_ldbl | ( | char ** | pbegin, |
char * | end, | ||
long double | ld | ||
) |
Prints a C99 long double
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
ld | the value to be written. |
size_t print_c99_i8 | ( | char ** | pbegin, |
char * | end, | ||
int_least8_t | i8 | ||
) |
Prints a C99 int_least8_t
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
i8 | the value to be written. |
size_t print_c99_i16 | ( | char ** | pbegin, |
char * | end, | ||
int_least16_t | i16 | ||
) |
Prints a C99 int_least16_t
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
i16 | the value to be written. |
size_t print_c99_i32 | ( | char ** | pbegin, |
char * | end, | ||
int_least32_t | i32 | ||
) |
Prints a C99 int_least32_t
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
i32 | the value to be written. |
size_t print_c99_i64 | ( | char ** | pbegin, |
char * | end, | ||
int_least64_t | i64 | ||
) |
Prints a C99 int_least64_t
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
i64 | the value to be written. |
size_t print_c99_u8 | ( | char ** | pbegin, |
char * | end, | ||
uint_least8_t | u8 | ||
) |
Prints a C99 uint_least8_t
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
u8 | the value to be written. |
size_t print_c99_u16 | ( | char ** | pbegin, |
char * | end, | ||
uint_least16_t | u16 | ||
) |
Prints a C99 uint_least16_t
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
u16 | the value to be written. |
size_t print_c99_u32 | ( | char ** | pbegin, |
char * | end, | ||
uint_least32_t | u32 | ||
) |
Prints a C99 uint_least32_t
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
u32 | the value to be written. |
size_t print_c99_u64 | ( | char ** | pbegin, |
char * | end, | ||
uint_least64_t | u64 | ||
) |
Prints a C99 uint_least64_t
to a memory buffer.
Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
u64 | the value to be written. |
size_t print_base64 | ( | char ** | pbegin, |
char * | end, | ||
const void * | ptr, | ||
size_t | n | ||
) |
Prints the Base64 representation of binary data to a memory buffer.
This function implements the MIME variant of Base64 as specified in RFC 2045. Note that the output is not null-terminated.
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |
ptr | a pointer to the binary data to be encoded and written. |
n | the number of bytes at ptr. |