Parsee/src/include/StringSplit.h
LDA 61b248363d [ADD/WIP] Codenames, try to get codeblocks basics
Mostly focused on the LMDB support right now, sorry!
2024-08-10 09:52:11 +02:00

61 lines
1.7 KiB
C

#ifndef PARSEE_STRINGSPLIT_H
#define PARSEE_STRINGSPLIT_H
#include <stdbool.h>
#include <stdlib.h>
/* Represents a boundary in a linesplit string */
typedef struct StringRect {
char **source_lines;
/* NOTE: All of these values are inclusive */
/* The start line/character index */
size_t start_line;
size_t start_char;
/* The end line/character index */
size_t end_line;
size_t end_char;
} StringRect;
/** Splits a string into a set of NULL-terminated substrings, which is
* terminated by a NULL pointer.
* ---------
* Returns: A set of lines(excluding them) [LA:HEAP]
* Modifies: NOTHING
* Thrasher: StrFreeLines */
extern char ** StrSplitLines(char *text);
extern void StrFreeLines(char **split);
extern size_t StrLines(char **split);
/* Creates a full zone covering every part of the split */
extern StringRect StrFullRect(char **split);
/**
* Retrieves a character from a string rectview, or \0 if out of bounds.
* --------------
* Returns: A character at {line}, {col} in C-indices | '\0'
* Modifies: NOTHING */
extern char StrGet(StringRect *rect, int line, int col);
/**
* Retrieves a line from a string rectview, or a NULL one
* --------------
* Returns: A stringview that lives along the original
* Modifies: NOTHING */
extern StringRect StrGetl(StringRect *rect, int line, bool extend);
/**
* Returns a new stringrect, shifted by N chars.
* --------------
* Returns: A stringview that lives along the original
* Modifies: NOTHING */
extern StringRect StrShift(StringRect rect, int n);
extern size_t StrViewLines(StringRect);
extern size_t StrViewChars(StringRect, int line);
extern char * StrViewToStr(StringRect rect);
#endif