-
Notifications
You must be signed in to change notification settings - Fork 0
/
km_string.h
60 lines (45 loc) · 2 KB
/
km_string.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include "km_array.h"
#include "km_container.h"
using string = Array<char>;
using const_string = const Array<const char>;
uint32 StringLength(const char* str);
const_string ToString(const char* cString);
string ToNonConstString(const_string constString); // TODO(patio): wish I didn't have to do this, maybe?
#ifdef KM_CPP_STD
#include <string>
string ToString(const std::string& str);
#endif
template <uint32 S>
void InitFromCString(FixedArray<char, S>* string, const char* cString);
template <typename Allocator>
char* ToCString(const_string str, Allocator* allocator);
int StringCompare(const_string str1, const_string str2);
bool StringEquals(const_string str1, const_string str2);
uint32 SubstringSearch(const_string str, const_string substr);
bool StringContains(const_string str, const_string substr);
bool IsNewline(char c);
bool IsWhitespace(char c);
bool IsAlphanumeric(char c);
string TrimWhitespace(const_string str);
bool StringToIntBase10(const_string str, int* intBase10);
bool StringToUInt32Base10(const_string str, uint32* intBase10);
bool StringToFloat32(const_string str, float32* f);
string NextSplitElement(string* str, char separator);
template <typename Allocator>
void StringSplit(const_string str, char c, DynamicArray<string, Allocator>* outSplit);
template <typename T>
bool StringToElementArray(const_string str, char sep, bool trimElements,
bool (*conversionFunction)(const_string, T*),
int maxElements, T* array, int* numElements);
template <typename Allocator>
string StringConcatenate(const_string str1, const_string str2, Allocator* allocator);
bool SizedPrintf(string* str, const char* format, ...);
template <typename Allocator>
string AllocPrintf(Allocator* allocator, const char* format, ...);
template <typename Allocator>
DynamicArray<char, Allocator> AllocPrintf(const char* format, ...);
#ifdef KM_UTF8
template <typename Allocator>
bool Utf8ToUppercase(const_string utf8String, DynamicArray<char, Allocator>* outString);
#endif