aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r--Alc/helpers.c28
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);