Established length-based strings

This commit is contained in:
kilroy
2025-11-28 19:31:49 -05:00
parent 62c202d4e7
commit b7ce065002
3 changed files with 119 additions and 2 deletions

22
include/lenstr.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef LENSTR_H
#define LENSTR_H
/* Length-based strings
* and methods to go with them. */
#define PrintStr(str) printf("%.*s\n", str.length, str.chars)
#define StrLit(s) (string) {s, sizeof(s)-1}
typedef struct {
char *chars;
size_t length;
} string;
string CStyleToLengthString_Assign(char *cstr); // StrLit(s) macro but in function form.
string CStyleToLengthString_Copy(char *cstr);
string StringCopy(string str);
string StringSlice_Index(string str, size_t starti, size_t endi);
string StringSlice_Length(string str, size_t starti, size_t length);
#endif // LENSTR_H