| 1 |
/// @file |
| 2 |
/// @brief XML escaping functionality |
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <util/api.h> |
| 7 |
|
| 8 |
#ifdef __cplusplus |
| 9 |
extern "C" { |
| 10 |
#endif |
| 11 |
|
| 12 |
/// options to tweak the behavior of XML escaping |
| 13 |
typedef struct { |
| 14 |
/// assume no embedded escapes, and escape "\n" and "\r" |
| 15 |
unsigned raw : 1; |
| 16 |
/// escape '-' |
| 17 |
unsigned dash : 1; |
| 18 |
/// escape consecutive ' ' |
| 19 |
unsigned nbsp : 1; |
| 20 |
/// anticipate non-ASCII characters that need to be encoded |
| 21 |
unsigned utf8 : 1; |
| 22 |
} xml_flags_t; |
| 23 |
|
| 24 |
/// XML-escape a string |
| 25 |
/// |
| 26 |
/// @param s Source string to process. |
| 27 |
/// @param flags Options of how to configure escaping. |
| 28 |
/// @param cb An `fputs` analogue for emitting escaped output. |
| 29 |
/// @param state Caller-defined data to pass to `cb`. |
| 30 |
/// @return The first negative value `cb` returns or the last return value of |
| 31 |
/// `cb`. |
| 32 |
UTIL_API int gv_xml_escape(const char *s, xml_flags_t flags, |
| 33 |
int (*cb)(void *state, const char *s), void *state); |
| 34 |
|
| 35 |
#ifdef __cplusplus |
| 36 |
} |
| 37 |
#endif |