|
@@ -3,7 +3,7 @@
|
|
|
|
|
|
#include "volksdata/graph.h"
|
|
#include "volksdata/graph.h"
|
|
|
|
|
|
-/** @defgroup codec RDF codec module
|
|
|
|
|
|
+/** @defgroup codec_priv Private RDF codec API
|
|
* @ingroup private
|
|
* @ingroup private
|
|
* @{
|
|
* @{
|
|
*/
|
|
*/
|
|
@@ -41,6 +41,115 @@ typedef struct parse_error_t {
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * Common utility functions.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+/** @brief strdup() for unsigned char.
|
|
|
|
+ *
|
|
|
|
+ * This is to be used with uint8_t sequences considered to be UTF-8 sequences,
|
|
|
|
+ * requird by re2c (it won't work with byte sequences containing `NUL`).
|
|
|
|
+ */
|
|
|
|
+inline uint8_t
|
|
|
|
+*uint8_dup (const uint8_t *str)
|
|
|
|
+{ return (uint8_t *) strdup ((char *) str); }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief strndup() for unsigned char.
|
|
|
|
+ *
|
|
|
|
+ * This is to be used with uint8_t sequences considered to be UTF-8 sequences,
|
|
|
|
+ * requird by re2c (it won't work with byte sequences containing `NUL`).
|
|
|
|
+ */
|
|
|
|
+inline uint8_t
|
|
|
|
+*uint8_ndup (const uint8_t *str, size_t size)
|
|
|
|
+{ return (uint8_t *) strndup ((char *) str, size); }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Add escape character (backslash) to illegal literal characters.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] in Input string.
|
|
|
|
+ *
|
|
|
|
+ * @param[out] out Output string.
|
|
|
|
+ *
|
|
|
|
+ * @return VOLK_OK on success; VOLK_MEM_ERR on memory error.
|
|
|
|
+ */
|
|
|
|
+VOLK_rc
|
|
|
|
+escape_lit (const char *in, char **out);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Replace non-printable characters with their literal byte.
|
|
|
|
+ *
|
|
|
|
+ * Escape backslash is to be added separately.
|
|
|
|
+ */
|
|
|
|
+static inline char
|
|
|
|
+escape_char (const char c) {
|
|
|
|
+ switch (c) {
|
|
|
|
+ case '\t': return 't';
|
|
|
|
+ case '\b': return 'b';
|
|
|
|
+ case '\n': return 'n';
|
|
|
|
+ case '\r': return 'r';
|
|
|
|
+ case '\f': return 'f';
|
|
|
|
+ default: return c;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Unescape a single character.
|
|
|
|
+ *
|
|
|
|
+ * Convert escaped special characters such as `\t`, `\n`, etc. into their
|
|
|
|
+ * corresponding code points.
|
|
|
|
+ *
|
|
|
|
+ * Non-special characters are returned unchanged.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] c Character to unescape. Note that this is the single character
|
|
|
|
+ * after `\`.
|
|
|
|
+ *
|
|
|
|
+ * @return Code point corresponding to the escaped character.
|
|
|
|
+ */
|
|
|
|
+inline char
|
|
|
|
+unescape_char (const char c)
|
|
|
|
+{
|
|
|
|
+ switch (c) {
|
|
|
|
+ case 't': return '\t';
|
|
|
|
+ case 'b': return '\b';
|
|
|
|
+ case 'n': return '\n';
|
|
|
|
+ case 'r': return '\r';
|
|
|
|
+ case 'f': return '\f';
|
|
|
|
+ default: return c;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Replace `\uxxxx` and `\Uxxxxxxxx` with Unicode bytes.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] esc_str Escaped string.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] size Maximum number of characters to scan, à la strncpy().
|
|
|
|
+ *
|
|
|
|
+ * @return String with escape sequences replaced by Unicode bytes.
|
|
|
|
+ */
|
|
|
|
+uint8_t *unescape_unicode (const uint8_t *esc_str, size_t size);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @brief Format an informational header.
|
|
|
|
+ *
|
|
|
|
+ * The information includes software version and current date. It is terminated
|
|
|
|
+ * by a newline + NUL and prefixed with the string specified in `pfx`. It is
|
|
|
|
+ * NOT prefixed by any comment characters.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] pfx Prefix to add to the string. It may be a comment starter,
|
|
|
|
+ * such as `# `.
|
|
|
|
+ */
|
|
|
|
+char *fmt_header (char *pfx);
|
|
|
|
+
|
|
|
|
+/// @} END defgroup codec_priv
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/** @defgroup codec_p RDF encoder & decoder module
|
|
|
|
+ * @ingroup public
|
|
|
|
+ * @{
|
|
|
|
+ */
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Interface prototypes.
|
|
* Interface prototypes.
|
|
*/
|
|
*/
|
|
@@ -189,108 +298,6 @@ struct codec_t {
|
|
term_decode_fn_t decode_term; ///< Term decoder function.
|
|
term_decode_fn_t decode_term; ///< Term decoder function.
|
|
gr_decode_fn_t decode_graph; ///< Graph decoder function.
|
|
gr_decode_fn_t decode_graph; ///< Graph decoder function.
|
|
};
|
|
};
|
|
-
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
- * Common utility functions.
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
-/** @brief strdup() for unsigned char.
|
|
|
|
- *
|
|
|
|
- * This is to be used with uint8_t sequences considered to be UTF-8 sequences,
|
|
|
|
- * requird by re2c (it won't work with byte sequences containing `NUL`).
|
|
|
|
- */
|
|
|
|
-inline uint8_t
|
|
|
|
-*uint8_dup (const uint8_t *str)
|
|
|
|
-{ return (uint8_t *) strdup ((char *) str); }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/** @brief strndup() for unsigned char.
|
|
|
|
- *
|
|
|
|
- * This is to be used with uint8_t sequences considered to be UTF-8 sequences,
|
|
|
|
- * requird by re2c (it won't work with byte sequences containing `NUL`).
|
|
|
|
- */
|
|
|
|
-inline uint8_t
|
|
|
|
-*uint8_ndup (const uint8_t *str, size_t size)
|
|
|
|
-{ return (uint8_t *) strndup ((char *) str, size); }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/** @brief Add escape character (backslash) to illegal literal characters.
|
|
|
|
- *
|
|
|
|
- * @param[in] in Input string.
|
|
|
|
- *
|
|
|
|
- * @param[out] out Output string.
|
|
|
|
- *
|
|
|
|
- * @return VOLK_OK on success; VOLK_MEM_ERR on memory error.
|
|
|
|
- */
|
|
|
|
-VOLK_rc
|
|
|
|
-escape_lit (const char *in, char **out);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/** @brief Replace non-printable characters with their literal byte.
|
|
|
|
- *
|
|
|
|
- * Escape backslash is to be added separately.
|
|
|
|
- */
|
|
|
|
-static inline char
|
|
|
|
-escape_char (const char c) {
|
|
|
|
- switch (c) {
|
|
|
|
- case '\t': return 't';
|
|
|
|
- case '\b': return 'b';
|
|
|
|
- case '\n': return 'n';
|
|
|
|
- case '\r': return 'r';
|
|
|
|
- case '\f': return 'f';
|
|
|
|
- default: return c;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/** @brief Unescape a single character.
|
|
|
|
- *
|
|
|
|
- * Convert escaped special characters such as `\t`, `\n`, etc. into their
|
|
|
|
- * corresponding code points.
|
|
|
|
- *
|
|
|
|
- * Non-special characters are returned unchanged.
|
|
|
|
- *
|
|
|
|
- * @param[in] c Character to unescape. Note that this is the single character
|
|
|
|
- * after `\`.
|
|
|
|
- *
|
|
|
|
- * @return Code point corresponding to the escaped character.
|
|
|
|
- */
|
|
|
|
-inline char
|
|
|
|
-unescape_char (const char c)
|
|
|
|
-{
|
|
|
|
- switch (c) {
|
|
|
|
- case 't': return '\t';
|
|
|
|
- case 'b': return '\b';
|
|
|
|
- case 'n': return '\n';
|
|
|
|
- case 'r': return '\r';
|
|
|
|
- case 'f': return '\f';
|
|
|
|
- default: return c;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/** @brief Replace `\uxxxx` and `\Uxxxxxxxx` with Unicode bytes.
|
|
|
|
- *
|
|
|
|
- * @param[in] esc_str Escaped string.
|
|
|
|
- *
|
|
|
|
- * @param[in] size Maximum number of characters to scan, à la strncpy().
|
|
|
|
- *
|
|
|
|
- * @return String with escape sequences replaced by Unicode bytes.
|
|
|
|
- */
|
|
|
|
-uint8_t *unescape_unicode (const uint8_t *esc_str, size_t size);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/** @brief Format an informational header.
|
|
|
|
- *
|
|
|
|
- * The information includes software version and current date. It is terminated
|
|
|
|
- * by a newline + NUL and prefixed with the string specified in `pfx`. It is
|
|
|
|
- * NOT prefixed by any comment characters.
|
|
|
|
- *
|
|
|
|
- * @param[in] pfx Prefix to add to the string. It may be a comment starter,
|
|
|
|
- * such as `# `.
|
|
|
|
- */
|
|
|
|
-char *fmt_header (char *pfx);
|
|
|
|
-
|
|
|
|
/// @} END defgroup codec
|
|
/// @} END defgroup codec
|
|
|
|
+
|
|
#endif
|
|
#endif
|