aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Johnson <nick@nicksphere.ch>2022-01-18 00:00:00 +0000
committerNicholas Johnson <nick@nicksphere.ch>2022-01-18 00:00:00 +0000
commit462caea6a2969f5cb9a2f0c9edc96aed103eb6b9711b5eb2ec849594f9a37a9e (patch)
treef6c40a626c178bf2e4636a4685635315907e86be25821295202900023951e1c4
parent73138f36af451ede4c3cdcc839067ea4b6b18800f6d5e69191978715745ae155 (diff)
Document escape_text_add_tags()
-rw-r--r--src/gemini2html.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/gemini2html.c b/src/gemini2html.c
index cfb929d..c080932 100644
--- a/src/gemini2html.c
+++ b/src/gemini2html.c
@@ -25,11 +25,11 @@
/* Escapes text so it can be safely inserted within HTML tags and attributes.
* Examples:
- * "5 < 6" => "5 &lt; 6"
- * "6 > 5" => "6 &gt; 5"
- * "me & you" => "me &amp; you"
- * "i'm so high" => "I&apos;m so high"
- * ""hello world" => "&quot;hello world&quot;"
+ * escape_text("5 < 6", 5) => "5 &lt; 6"
+ * escape_text("6 > 5", 5) => "6 &gt; 5"
+ * escape_text("me & you", 8) => "me &amp; you"
+ * escape_text("i'm so high", 11) => "I&apos;m so high"
+ * escape_text("\"hello world\"", 13) => "&quot;hello world&quot;"
*/
char* escape_text(const char* unescaped, const size_t unescaped_len) {
/* In the worst case, every unescaped character corresponds to 6 escape characters.
@@ -90,8 +90,11 @@ void skip_non_whitespace(const char* str, size_t* pos) {
while (str[*pos] != '\0' && !(str[*pos] == ' ' || str[*pos] == '\t')) (*pos)++;
}
-/* Escapes unescaped string, prepending opening_tag and appending closing tag and a newline.
- * If unescaped ends in a newline, ignore the newline. Inserting it causes the returned string to line break inappropriately.
+/* Escapes unescaped, prepending opening_tag and appending closing tag and a newline.
+ * If unescaped ends in a newline, that newline is ignored. Inserting it causes the returned string to line break inappropriately.
+ * Examples:
+ * escape_text_add_tags("<p>", "5 < 6\n", "</p>", 6) => "<p>5 &lt; 6</p>\n"
+ * escape_text_add_tags("<p>", "5 < 6", "</p>", 5) => "<p>5 &lt; 6</p>\n"
*/
char* escape_text_add_tags(const char* opening_tag, const char* unescaped, const char* closing_tag, const size_t unescaped_len) {
char* escaped = escape_text(unescaped, unescaped_len);