From 59000167da500e8c5e5d8a4da54a236eb1aa2840 Mon Sep 17 00:00:00 2001 From: retoor <retoor@molodetz.nl> Date: Sun, 30 Mar 2025 01:48:35 +0100 Subject: [PATCH] clean. --- .gitignore | 1 + inplace_url.h | 50 -------------------------------------------------- 2 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 inplace_url.h diff --git a/.gitignore b/.gitignore index 0b5a214..4cab043 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ auth.h .rcontext* tests rpylib.so +rd diff --git a/inplace_url.h b/inplace_url.h deleted file mode 100644 index 8b4c66c..0000000 --- a/inplace_url.h +++ /dev/null @@ -1,50 +0,0 @@ -// Written by retoor@molodetz.nl - -// This source code extracts URLs from an input string and replaces them inline -// with their respective content in Markdown style. - -// Imports used: regex.h for regular expression operations, http.h and url.h for -// HTTP and URL-related utility functions. - -// MIT License - -#include "http.h" -#include "url.h" -#include <regex.h> -#include <stdlib.h> -#include <string.h> - -void extract_urls(const char *input, char **urls, int *url_count) { - const char *pattern = "https?://[^ ]+"; - regex_t regex; - regcomp(®ex, pattern, REG_EXTENDED); - regmatch_t match; - const char *cursor = input; - - *url_count = 0; - while (!regexec(®ex, cursor, 1, &match, 0)) { - int length = match.rm_eo - match.rm_so; - urls[*url_count] = strndup(cursor + match.rm_so, length); - cursor += match.rm_eo; - (*url_count)++; - } - regfree(®ex); -} - -void inplace_urls_markdown_style(char **input, char **urls, char **contents, - int url_count) { - for (int i = 0; i < url_count; i++) { - char *found = strstr(*input, urls[i]); - if (found) { - char *new_text = (char *)malloc(strlen(*input) + strlen(contents[i]) - - strlen(urls[i]) + 1); - strncpy(new_text, *input, found - *input); - new_text[found - *input] = '\0'; - strcat(new_text, contents[i]); - strcat(new_text, found + strlen(urls[i])); - - free(*input); - *input = new_text; - } - } -} \ No newline at end of file