CORE_Static
This commit is contained in:
@@ -1,39 +1,39 @@
|
||||
|
||||
function U8
|
||||
CORE_Static U8
|
||||
to_lower_case(U8 a) {
|
||||
if (a >= 'A' && a <= 'Z')
|
||||
a += 32;
|
||||
return a;
|
||||
}
|
||||
|
||||
function U8
|
||||
CORE_Static U8
|
||||
to_upper_case(U8 a) {
|
||||
if (a >= 'a' && a <= 'z')
|
||||
a -= 32;
|
||||
return a;
|
||||
}
|
||||
|
||||
function U8
|
||||
CORE_Static U8
|
||||
char_to_lower(U8 c){
|
||||
if(c >= 'A' && c <= 'Z')
|
||||
c += 32;
|
||||
return c;
|
||||
}
|
||||
|
||||
function U8
|
||||
CORE_Static U8
|
||||
char_to_upper(U8 c){
|
||||
if(c >= 'a' && c <= 'z')
|
||||
c -= 32;
|
||||
return c;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
is_whitespace(U8 w) {
|
||||
bool result = w == '\n' || w == ' ' || w == '\t' || w == '\v' || w == '\r';
|
||||
return result;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
is_alphabetic(U8 a) {
|
||||
if ((a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z')) {
|
||||
return true;
|
||||
@@ -41,19 +41,19 @@ is_alphabetic(U8 a) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
is_number(U8 a) {
|
||||
B32 result = a >= '0' && a <= '9';
|
||||
return result;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
is_alphanumeric(U8 a) {
|
||||
B32 result = is_number(a) || is_alphabetic(a);
|
||||
return result;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
string_compare(String a, String b, B32 ignore_case = false) {
|
||||
if (a.len != b.len)
|
||||
return false;
|
||||
@@ -70,12 +70,12 @@ string_compare(String a, String b, B32 ignore_case = false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
operator==(String a, String b){
|
||||
return string_compare(a,b);
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_copy(Arena *a, String string){
|
||||
U8 *copy = arena_push_array(a, U8, string.len+1);
|
||||
memory_copy(copy, string.str, string.len);
|
||||
@@ -83,7 +83,7 @@ string_copy(Arena *a, String string){
|
||||
return String{copy, string.len};
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_fmtv(Arena *a, const char *str, va_list args1) {
|
||||
va_list args2;
|
||||
va_copy(args2, args1);
|
||||
@@ -103,7 +103,7 @@ va_start(args1, str); \
|
||||
String result = string_fmtv(alloc, str, args1); \
|
||||
va_end(args1)
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_fmt(Arena *a, const char *str, ...) {
|
||||
STRING_FMT(a, str, result);
|
||||
return result;
|
||||
@@ -202,7 +202,7 @@ struct String_Builder{
|
||||
}
|
||||
};
|
||||
|
||||
function String_Builder
|
||||
CORE_Static String_Builder
|
||||
string_builder_make(Arena *a, S64 first_block_size = 4096){
|
||||
String_Builder sb = {a};
|
||||
sb.init(first_block_size);
|
||||
@@ -214,7 +214,7 @@ enum String_Builder_Flag{
|
||||
String_Builder_Flag_AddSize = 0,
|
||||
};
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_flatten(Arena *a, String_Builder *b, String_Builder_Flag flags = String_Builder_Flag_None){
|
||||
// @Note(Krzosa): Compute size to allocate
|
||||
S64 size = 1;
|
||||
@@ -240,7 +240,7 @@ string_flatten(Arena *a, String_Builder *b, String_Builder_Flag flags = String_B
|
||||
return result;
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
test_string_builder(){
|
||||
Scratch scratch;
|
||||
String_Builder sb = string_builder_make(scratch, 4);
|
||||
@@ -255,7 +255,7 @@ test_string_builder(){
|
||||
//-----------------------------------------------------------------------------
|
||||
// String ops
|
||||
//-----------------------------------------------------------------------------
|
||||
function void
|
||||
CORE_Static void
|
||||
string_path_normalize(String s) {
|
||||
for (S64 i = 0; i < s.len; i++) {
|
||||
if (s.str[i] == '\\')
|
||||
@@ -263,7 +263,7 @@ string_path_normalize(String s) {
|
||||
}
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_make(char *str, S64 len) {
|
||||
String result;
|
||||
result.str = (U8 *)str;
|
||||
@@ -271,19 +271,19 @@ string_make(char *str, S64 len) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_make(U8 *str, S64 len) {
|
||||
return string_make((char*)str, len);
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_chop(String string, S64 len) {
|
||||
len = clamp_top(len, string.len);
|
||||
String result = string_make(string.str, string.len - len);
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_skip(String string, S64 len) {
|
||||
len = clamp_top(len, string.len);
|
||||
S64 remain = string.len - len;
|
||||
@@ -291,7 +291,7 @@ string_skip(String string, S64 len) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_get_postfix(String string, S64 len) {
|
||||
len = clamp_top(len, string.len);
|
||||
S64 remain_len = string.len - len;
|
||||
@@ -299,14 +299,14 @@ string_get_postfix(String string, S64 len) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_get_prefix(String string, S64 len) {
|
||||
len = clamp_top(len, string.len);
|
||||
String result = string_make(string.str, len);
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_slice(String string, S64 first_index, S64 one_past_last_index) {
|
||||
assert_message(first_index < one_past_last_index, "string_slice, first_index is bigger then one_past_last_index");
|
||||
assert_message(string.len > 0, "Slicing string of length 0! Might be an error!");
|
||||
@@ -325,7 +325,7 @@ string_slice(String string, S64 first_index, S64 one_past_last_index) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_trim(String string) {
|
||||
if (string.len == 0) return string;
|
||||
|
||||
@@ -354,7 +354,7 @@ string_trim(String string) {
|
||||
return string;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_trim_end(String string) {
|
||||
S64 whitespace_end = string.len;
|
||||
for (; whitespace_end != 0; whitespace_end--) {
|
||||
@@ -367,7 +367,7 @@ string_trim_end(String string) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_to_lower_case(Arena *arena, String s) {
|
||||
String copy = string_copy(arena, s);
|
||||
for (U64 i = 0; i < copy.len; i++) {
|
||||
@@ -376,7 +376,7 @@ string_to_lower_case(Arena *arena, String s) {
|
||||
return copy;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_to_upper_case(Arena *arena, String s) {
|
||||
String copy = string_copy(arena, s);
|
||||
for (U64 i = 0; i < copy.len; i++) {
|
||||
@@ -392,7 +392,7 @@ enum {
|
||||
MatchFlag_IgnoreCase=2,
|
||||
};
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
string_find(String string, String find, MatchFlag flags, S64 *index_out) {
|
||||
B32 result = false;
|
||||
if (flags & MatchFlag_FindLast) {
|
||||
@@ -422,21 +422,21 @@ string_find(String string, String find, MatchFlag flags, S64 *index_out) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_chop_last_slash(String s) {
|
||||
String result = s;
|
||||
string_find(s, "/"_s, MatchFlag_FindLast, &result.len);
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_chop_last_period(String s) {
|
||||
String result = s;
|
||||
string_find(s, "."_s, MatchFlag_FindLast, &result.len);
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_skip_to_last_slash(String s) {
|
||||
S64 pos;
|
||||
String result = s;
|
||||
@@ -446,7 +446,7 @@ string_skip_to_last_slash(String s) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_skip_to_last_period(String s) {
|
||||
S64 pos;
|
||||
String result = s;
|
||||
@@ -456,14 +456,14 @@ string_skip_to_last_period(String s) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function S64
|
||||
CORE_Static S64
|
||||
string_len(char *string){
|
||||
S64 len = 0;
|
||||
while(*string++!=0)len++;
|
||||
return len;
|
||||
}
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_from_cstring(char *string){
|
||||
String result;
|
||||
result.str = (U8 *)string;
|
||||
@@ -476,7 +476,7 @@ struct String_Replace {
|
||||
String replace;
|
||||
};
|
||||
|
||||
function String
|
||||
CORE_Static String
|
||||
string_replace(Arena *arena, String string, Array<String_Replace> pairs){
|
||||
Scratch scratch(arena);
|
||||
String_Builder builder = {scratch};
|
||||
|
||||
Reference in New Issue
Block a user