c-md/srcs/utils/string/extract_fence_ext.c
2026-01-12 00:48:09 +01:00

32 lines
616 B
C

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "utils.h"
char *
extract_fence_ext(const char *fence)
{
const char *start;
const char *end;
size_t len;
char *ext;
if (0 != strncmp(fence, "```", 3))
return (NULL);
start = fence + 3;
while (' ' == *start || '\t' == *start)
start++;
if ('\n' == *start || '\0' == *start)
return (NULL);
end = start;
while ('\n' != *end && '\0' != *end && ' ' != *end && '\t' != *end)
end++;
len = (size_t)(end - start);
ext = malloc(len + 1);
if (NULL == ext)
return (NULL);
memcpy(ext, start, len);
ext[len] = '\0';
return (ext);
}