22 lines
587 B
C
22 lines
587 B
C
#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
|