stringview.h (520B)
1 #ifndef STRINGVIEW_H 2 #define STRINGVIEW_H 3 4 #include <stddef.h> 5 #include <string.h> 6 7 struct stringview { 8 unsigned char *ptr; 9 size_t len; 10 }; 11 12 #define FROM_CSTR(cstr) ((struct stringview) { (cstr), strlen(cstr), }) 13 14 inline int 15 svcmp(struct stringview *a, struct stringview *b) 16 { 17 if (a->len != b->len) 18 return a->len - b->len; 19 20 return strncmp((char *) a->ptr, (char *) b->ptr, a->len); 21 } 22 23 inline unsigned char * 24 svstr(struct stringview *haystack, struct stringview *needle) 25 { 26 return NULL; 27 } 28 29 #endif /* STRINGVIEW_H */