aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-06-27 03:01:20 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-06-29 01:35:45 +0200
commit519f1f8031687ebf3853817a8b2e3557c2443d67 (patch)
tree320be2942773ee95c34a798da09685728115045f /src/utils.c
parent4cfeb39fbe99be28f22611c6146b1655549f7850 (diff)
downloadblogc-519f1f8031687ebf3853817a8b2e3557c2443d67.tar.gz
blogc-519f1f8031687ebf3853817a8b2e3557c2443d67.tar.bz2
blogc-519f1f8031687ebf3853817a8b2e3557c2443d67.zip
content-parser: rewrote inline parser.
parser is stricter now, and won't produce invalid HTML anymore.
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 855b503..d7362a6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -287,6 +287,27 @@ sb_str_replace(const char *str, const char search, const char *replace)
}
+char*
+sb_str_find(const char *str, char c)
+{
+ // this is somewhat similar to strchr, but respects '\' escaping.
+ if (str == NULL)
+ return NULL;
+ if (c == '\0')
+ return (char*) str + strlen(str);
+ for (size_t i = 0; str[i] != '\0'; i++) {
+ if (str[i] == '\\') {
+ i++;
+ continue;
+ }
+ if (str[i] == c) {
+ return (char*) str + i;
+ }
+ }
+ return NULL;
+}
+
+
void
sb_strv_free(char **strv)
{
@@ -425,6 +446,26 @@ sb_string_append_printf(sb_string_t *str, const char *format, ...)
}
+sb_string_t*
+sb_string_append_escaped(sb_string_t *str, const char *suffix)
+{
+ if (str == NULL)
+ return NULL;
+ if (suffix == NULL)
+ return str;
+ bool escaped = false;
+ for (size_t i = 0; suffix[i] != '\0'; i++) {
+ if (suffix[i] == '\\' && !escaped) {
+ escaped = true;
+ continue;
+ }
+ escaped = false;
+ str = sb_string_append_c(str, suffix[i]);
+ }
+ return str;
+}
+
+
sb_trie_t*
sb_trie_new(sb_free_func_t free_func)
{