Implemented string_view type#103
Conversation
| size_t count; | ||
| } string_view; | ||
|
|
||
| static inline string_view strv_init(const char* str) { |
There was a problem hiding this comment.
Names of functions that acting as methods for a structs should start with the full name of the struct
|
|
||
| static inline string_view strv_init(const char* str) { | ||
| if (!str) | ||
| return (string_view){NULL, 0}; |
There was a problem hiding this comment.
Use nullptr instead of NULL
| i++; | ||
| } | ||
|
|
||
| ret.count = (size_t)(i - str); |
There was a problem hiding this comment.
You can use strlen from stdbigos/string.h
| return ret; | ||
| } | ||
|
|
||
| static inline size_t strvlen(string_view strv) { |
There was a problem hiding this comment.
I don't think this function is necessary
|
|
||
| static inline int strvncmp(string_view a, string_view b, size_t n) { | ||
| size_t min = a.count < b.count ? a.count : b.count; | ||
| if (min > n) |
There was a problem hiding this comment.
You can use MIN(a, b) from math.h
| return strv; | ||
| } | ||
|
|
||
| static inline string_view strvtok(string_view strv, string_view delim) { |
There was a problem hiding this comment.
Don't abbreviate names unnecessarily. Naming this like string_view_tokenise would be better imo. Also I think this function would be easier to use if it took a string view by reference so that returned string view has the token and the one taken as reference would have the rest of the string
No description provided.