Established length-based strings
This commit is contained in:
22
include/lenstr.h
Normal file
22
include/lenstr.h
Normal 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
|
||||
Reference in New Issue
Block a user