diff options
author | Chris Robinson <[email protected]> | 2016-02-24 04:53:32 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-02-24 04:53:32 -0800 |
commit | b6824ca7168d20e7aada4b45a32aa93f48fc689c (patch) | |
tree | 2bb03d869200b65926c876f2d74cebe4db4f007d /Alc/helpers.c | |
parent | d04970e568de8747a152db1ab036bbbfbf70f7f1 (diff) |
Add and use a copy-range string function
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r-- | Alc/helpers.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c index 20cd8900..f596c0d9 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -735,8 +735,7 @@ vector_al_string SearchDataFiles(const char *ext, const char *subdir) al_string_copy_cstr(&path, str); else { - al_string_clear(&path); - al_string_append_range(&path, str, next); + al_string_copy_range(&path, str, next); ++next; } if(!al_string_empty(path)) @@ -861,12 +860,16 @@ extern inline const al_string_char_type *al_string_get_cstr(const_al_string str) void al_string_clear(al_string *str) { - /* Reserve one more character than the total size of the string. This is to - * ensure we have space to add a null terminator in the string data so it - * can be used as a C-style string. */ - VECTOR_RESERVE(*str, 1); - VECTOR_RESIZE(*str, 0); - *VECTOR_ITER_END(*str) = 0; + if(!al_string_empty(*str)) + { + /* Reserve one more character than the total size of the string. This + * is to ensure we have space to add a null terminator in the string + * data so it can be used as a C-style string. + */ + VECTOR_RESERVE(*str, 1); + VECTOR_RESIZE(*str, 0); + *VECTOR_ITER_END(*str) = 0; + } } static inline int al_string_compare(const al_string_char_type *str1, size_t str1len, @@ -910,6 +913,15 @@ void al_string_copy_cstr(al_string *str, const al_string_char_type *from) *VECTOR_ITER_END(*str) = 0; } +void al_string_copy_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to) +{ + size_t len = to - from; + VECTOR_RESERVE(*str, len+1); + VECTOR_RESIZE(*str, 0); + VECTOR_INSERT(*str, VECTOR_ITER_END(*str), from, to); + *VECTOR_ITER_END(*str) = 0; +} + void al_string_append_char(al_string *str, const al_string_char_type c) { VECTOR_RESERVE(*str, al_string_length(*str)+2); |