diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/nx/win/nxmutablestring.c | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/replicant/nx/win/nxmutablestring.c')
-rw-r--r-- | Src/replicant/nx/win/nxmutablestring.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Src/replicant/nx/win/nxmutablestring.c b/Src/replicant/nx/win/nxmutablestring.c new file mode 100644 index 00000000..1e11bdba --- /dev/null +++ b/Src/replicant/nx/win/nxmutablestring.c @@ -0,0 +1,40 @@ +#include "nxmutablestring.h" +#include "foundation/error.h" + +/* currently this is closely coupled with the nx_string_t implementation. beware! */ +extern HANDLE string_heap; + +void NXMutableStringDestroy(nx_mutable_string_t mutable_string) +{ + if (mutable_string) + { + if (mutable_string->nx_string_data) + NXStringRelease(mutable_string->nx_string_data); + HeapFree(string_heap, 0, mutable_string); + } +} + +nx_mutable_string_t NXMutableStringCreateFromXML(const nsxml_char_t *characters, size_t num_characters) +{ + nx_mutable_string_t mutable_string = (nx_mutable_string_t)HeapAlloc(string_heap, 0, sizeof(nx_mutable_string_struct_t)); + NXStringCreateWithBytes(&mutable_string->nx_string_data, characters, num_characters*2, nx_charset_utf16le); + mutable_string->allocation_length = num_characters; + return mutable_string; +} + +int NXMutableStringGrowFromXML(nx_mutable_string_t mutable_string, const nsxml_char_t *characters, size_t num_characters) +{ + if (mutable_string->nx_string_data->len + num_characters + 1 > mutable_string->allocation_length) + { + nx_string_t new_string = NXStringRealloc(mutable_string->nx_string_data, mutable_string->nx_string_data->len + num_characters + 1); + if (!new_string) + return NErr_OutOfMemory; + mutable_string->nx_string_data = new_string; + mutable_string->allocation_length = mutable_string->nx_string_data->len + num_characters + 1; + } + memcpy(mutable_string->nx_string_data->string + mutable_string->nx_string_data->len, characters, num_characters*sizeof(wchar_t)); + mutable_string->nx_string_data->len += num_characters; + mutable_string->nx_string_data->string[mutable_string->nx_string_data->len]=0; /* well null terminate */ + + return NErr_Success; +}
\ No newline at end of file |