|
@@ -1,22 +1,5 @@
|
|
|
#include "codec/codec_ttl.h"
|
|
|
|
|
|
-/** @brief List of characters to be escaped in serialized literals.
|
|
|
- *
|
|
|
- * @sa https://www.w3.org/TR/n-triples/#grammar-production-ECHAR
|
|
|
- */
|
|
|
-#define LIT_ECHAR "\t\b\n\r\f\"\'\\"
|
|
|
-
|
|
|
-/** @brief Regex of characters to be escaped in serialized IRIs.
|
|
|
- *
|
|
|
- * @sa https://www.w3.org/TR/n-triples/#grammar-production-IRIREF
|
|
|
- */
|
|
|
-#define IRI_ECHAR_PTN "[\x00-\x20<>\"\\{\\}\\|\\^`\\\\]"
|
|
|
-
|
|
|
-
|
|
|
-/* * * Static prototypes. * * */
|
|
|
-
|
|
|
-static LSUP_rc escape_lit (const char *in, char **out_p);
|
|
|
-
|
|
|
|
|
|
/* * * Codec functions. * * */
|
|
|
|
|
@@ -201,40 +184,3 @@ gr_to_ttl_init (const LSUP_Graph *gr)
|
|
|
|
|
|
return it;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-/** @brief Add escape character (backslash) to illegal literal characters.
|
|
|
- */
|
|
|
-static LSUP_rc
|
|
|
-escape_lit (const char *in, char **out_p)
|
|
|
-{
|
|
|
- size_t out_size = strlen (in) + 1;
|
|
|
-
|
|
|
- // Expand output string size to accommodate escape characters.
|
|
|
- for (
|
|
|
- size_t i = strcspn (in, LIT_ECHAR);
|
|
|
- i < strlen (in);
|
|
|
- i += strcspn (in + i + 1, LIT_ECHAR) + 1) {
|
|
|
- out_size ++;
|
|
|
- }
|
|
|
-
|
|
|
- char *out = calloc (1, out_size);
|
|
|
- if (UNLIKELY (!out)) return LSUP_MEM_ERR;
|
|
|
-
|
|
|
- size_t boundary;
|
|
|
- boundary = strcspn (in, LIT_ECHAR);
|
|
|
- for (size_t i = 0, j = 0;;) {
|
|
|
- out = strncat (out, in + i, boundary);
|
|
|
-
|
|
|
- i += boundary;
|
|
|
- j += boundary;
|
|
|
- if (i >= strlen (in)) break;
|
|
|
-
|
|
|
- out[j++] = '\\';
|
|
|
- out[j++] = escape_char (in[i++]);
|
|
|
- boundary = strcspn (in + i, LIT_ECHAR);
|
|
|
- }
|
|
|
-
|
|
|
- *out_p = out;
|
|
|
- return 0;
|
|
|
-}
|