diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -36,3 +36,20 @@ char* trimwhitespace(char* str) { return str; } + +/* + * Remove given section from string. Negative len means remove + * everything up to the end. + * + * based on SO answer https://stackoverflow.com/a/20346241 + */ +int cut_str(char *str, int begin, int len) +{ + int l = strlen(str); + + if (len < 0) len = l - begin; + if (begin + len > l) len = l - begin; + memmove(str + begin, str + begin + len, l - len + 1); + + return len; +} |