diff --git a/include/tlibc/base64.h b/include/tlibc/base64.h index e71cc88..e1d371d 100644 --- a/include/tlibc/base64.h +++ b/include/tlibc/base64.h @@ -20,4 +20,4 @@ u32 base64_decodedSize(const char* src, u32 src_size); /// @param src_size size of data to decode. Must be a multiple of 4 for valid base64 data. /// @param dst buffer of size base64_decodedSize(src, src_size) /// @return number of decoded characters or 0 on error -u32 base64_decode(const u8* src, u32 src_size, u8* dst); +u32 base64_decode(const char* src, u32 src_size, u8* dst); diff --git a/include/tlibc/collections/Array.h b/include/tlibc/collections/Array.h index d699ed1..9aa6812 100755 --- a/include/tlibc/collections/Array.h +++ b/include/tlibc/collections/Array.h @@ -35,6 +35,3 @@ static inline Array_ Array_copy(Array_ src){ #define Array_len(AR, T) ((AR)->size / sizeof(T)) #define Array_memset(A, VAL) memset((A)->data, VAL, (A)->size) - -#define str_castTo_Array(S) Array_construct_size((S).data, (S).size) -#define Array_castTo_str(S, IS_ZERO_TERMINATED) str_construct((S).data, (S).size, IS_ZERO_TERMINATED) diff --git a/include/tlibc/string/str.h b/include/tlibc/string/str.h index 509b03f..866961d 100755 --- a/include/tlibc/string/str.h +++ b/include/tlibc/string/str.h @@ -20,6 +20,14 @@ static inline str str_from_cstr(cstr s_ptr){ return str_construct((void*)s_ptr, strlen(s_ptr), true); } +static inline Array_ str_castTo_Array(str s) { + return Array_construct_size(s.data, s.size); +} + +static inline str Array_castTo_str(Array_ a, bool isZeroTerminated) { + return str_construct(a.data, a.size, isZeroTerminated); +} + static const str str_null = str_construct(NULL, 0, 0); /// copies src content to new string and adds \0 at the end diff --git a/src/base64.c b/src/base64.c index bac1765..7eae33d 100644 --- a/src/base64.c +++ b/src/base64.c @@ -61,7 +61,7 @@ static int b64inverse[] = { 43, 44, 45, 46, 47, 48, 49, 50, 51 }; -u32 base64_decode(const u8* src, u32 src_size, u8* dst){ +u32 base64_decode(const char* src, u32 src_size, u8* dst){ // incomplete src if(src_size % 4 != 0) return 0; diff --git a/src/string/StringBuilder.c b/src/string/StringBuilder.c index b32bdd3..9ef10c2 100755 --- a/src/string/StringBuilder.c +++ b/src/string/StringBuilder.c @@ -6,7 +6,8 @@ void StringBuilder_destroy(StringBuilder* b){ } str StringBuilder_getStr(StringBuilder* b){ - List_push(&b->buffer, u8, '\0'); + if(b->buffer.size == 0 || ((char*)b->buffer.data)[b->buffer.size - 1] != '\0') + List_push(&b->buffer, u8, '\0'); str result = str_construct((char*)b->buffer.data, b->buffer.size - 1, true); return result; }