aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-02-24 04:53:32 -0800
committerChris Robinson <[email protected]>2016-02-24 04:53:32 -0800
commitb6824ca7168d20e7aada4b45a32aa93f48fc689c (patch)
tree2bb03d869200b65926c876f2d74cebe4db4f007d /Alc
parentd04970e568de8747a152db1ab036bbbfbf70f7f1 (diff)
Add and use a copy-range string function
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alstring.h1
-rw-r--r--Alc/helpers.c28
-rw-r--r--Alc/hrtf.c5
3 files changed, 22 insertions, 12 deletions
diff --git a/Alc/alstring.h b/Alc/alstring.h
index f53d2c57..6167f5ce 100644
--- a/Alc/alstring.h
+++ b/Alc/alstring.h
@@ -32,6 +32,7 @@ int al_string_cmp_cstr(const_al_string str1, const al_string_char_type *str2);
void al_string_copy(al_string *str, const_al_string from);
void al_string_copy_cstr(al_string *str, const al_string_char_type *from);
+void al_string_copy_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to);
void al_string_append_char(al_string *str, const al_string_char_type c);
void al_string_append_cstr(al_string *str, const al_string_char_type *from);
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);
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index 9436ee55..49c9793b 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -583,10 +583,7 @@ static void AddFileEntry(vector_HrtfEntry *list, al_string *filename)
if(!ext)
al_string_copy_cstr(&entry.name, name);
else
- {
- al_string_clear(&entry.name);
- al_string_append_range(&entry.name, name, ext);
- }
+ al_string_copy_range(&entry.name, name, ext);
if(i != 0)
{
char str[64];