Compare commits
No commits in common. "3a4af168b1ace0aa56ca6073af1fbe13f883abc1" and "39e8389f46273563f1653aad222790ef282f19d0" have entirely different histories.
3a4af168b1
...
39e8389f46
90
rtcore.h
90
rtcore.h
@ -215,14 +215,6 @@ RTC_API split_result S8Split(s8 s, u8 c);
|
|||||||
/* Creates a clone of string s on arena a */
|
/* Creates a clone of string s on arena a */
|
||||||
RTC_API s8 S8Clone(s8 s, arena *a);
|
RTC_API s8 S8Clone(s8 s, arena *a);
|
||||||
|
|
||||||
typedef struct { i64 i; b32 ok; } s8_parse_i64_result;
|
|
||||||
typedef struct { i32 i; b32 ok; } s8_parse_i32_result;
|
|
||||||
|
|
||||||
/* Parses a integer from string s */
|
|
||||||
RTC_API s8_parse_i64_result S8ParseI64(s8 s, int base);
|
|
||||||
/* Parses an integer from string s */
|
|
||||||
RTC_API s8_parse_i32_result S8ParseI32(s8 s, int base);
|
|
||||||
|
|
||||||
/* Basic file io */
|
/* Basic file io */
|
||||||
typedef struct file_buffer
|
typedef struct file_buffer
|
||||||
{
|
{
|
||||||
@ -293,7 +285,7 @@ RTC_API void *
|
|||||||
ArenaAlloc(arena *a, isize size, isize align, isize n, int flags)
|
ArenaAlloc(arena *a, isize size, isize align, isize n, int flags)
|
||||||
{
|
{
|
||||||
isize padding = -(usize)a->begin & (align - 1);
|
isize padding = -(usize)a->begin & (align - 1);
|
||||||
isize available = (isize)(a->end - a->begin) - padding;
|
isize available = a->end - a->begin - padding;
|
||||||
if (available < 0 || n > available / size)
|
if (available < 0 || n > available / size)
|
||||||
{
|
{
|
||||||
if (!(flags & ALLOC_SOFTFAIL))
|
if (!(flags & ALLOC_SOFTFAIL))
|
||||||
@ -301,7 +293,7 @@ ArenaAlloc(arena *a, isize size, isize align, isize n, int flags)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
void *p = a->begin + padding;
|
void *p = a->begin + padding;
|
||||||
a->begin += padding + n * size;
|
a->begin += padding - n * size;
|
||||||
return (flags & ALLOC_NOZERO) ? p : memset(p, 0, n * size);
|
return (flags & ALLOC_NOZERO) ? p : memset(p, 0, n * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,84 +392,6 @@ S8Clone(s8 s, arena *a)
|
|||||||
memcpy(c.data, s.data, s.length);
|
memcpy(c.data, s.data, s.length);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
RTC_API s8_parse_i64_result
|
|
||||||
S8ParseI64(s8 s, int base)
|
|
||||||
{
|
|
||||||
isize at = s.length - 1;
|
|
||||||
i64 exp = 1;
|
|
||||||
i64 val = 0;
|
|
||||||
while (at >= 0)
|
|
||||||
{
|
|
||||||
u8 c = s.data[at];
|
|
||||||
int digit = 0;
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
digit = c - '0';
|
|
||||||
else if (c >= 'A' && c <= 'Z')
|
|
||||||
digit = c - 'A';
|
|
||||||
else if (c >= 'a' && c <= 'z')
|
|
||||||
digit = c - 'a';
|
|
||||||
else if (c == '-')
|
|
||||||
{
|
|
||||||
val *= -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (c == '+')
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return (s8_parse_i64_result){0};
|
|
||||||
if (digit >= base)
|
|
||||||
return (s8_parse_i64_result){0};
|
|
||||||
|
|
||||||
val += digit * exp;
|
|
||||||
exp *= base;
|
|
||||||
--at;
|
|
||||||
}
|
|
||||||
return (s8_parse_i64_result){
|
|
||||||
.i = val,
|
|
||||||
.ok = 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
RTC_API s8_parse_i32_result
|
|
||||||
S8ParseI32(s8 s, int base)
|
|
||||||
{
|
|
||||||
isize at = s.length - 1;
|
|
||||||
i32 exp = 1;
|
|
||||||
i32 val = 0;
|
|
||||||
while (at >= 0)
|
|
||||||
{
|
|
||||||
u8 c = s.data[at];
|
|
||||||
int digit = 0;
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
digit = c - '0';
|
|
||||||
else if (c >= 'A' && c <= 'Z')
|
|
||||||
digit = c - 'A';
|
|
||||||
else if (c >= 'a' && c <= 'z')
|
|
||||||
digit = c - 'a';
|
|
||||||
else if (c == '-')
|
|
||||||
{
|
|
||||||
val *= -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (c == '+')
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return (s8_parse_i32_result){0};
|
|
||||||
if (digit >= base)
|
|
||||||
return (s8_parse_i32_result){0};
|
|
||||||
|
|
||||||
val += digit * exp;
|
|
||||||
exp *= base;
|
|
||||||
--at;
|
|
||||||
}
|
|
||||||
return (s8_parse_i32_result){
|
|
||||||
.i = val,
|
|
||||||
.ok = 1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Basic file io */
|
/* Basic file io */
|
||||||
RTC_API file_buffer
|
RTC_API file_buffer
|
||||||
|
|||||||
16
test.c
16
test.c
@ -47,20 +47,6 @@ ThreadTest(void)
|
|||||||
return AtomicLoad(&p) == 42;
|
return AtomicLoad(&p) == 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal int
|
|
||||||
ParseIntTest(void)
|
|
||||||
{
|
|
||||||
if (S8ParseI32(S8("123"), 10).i != 123)
|
|
||||||
return 0;
|
|
||||||
if (S8ParseI32(S8("-124"), 10).i != -124)
|
|
||||||
return 0;
|
|
||||||
if (S8ParseI64(S8("9223372036854775807"), 10).i != 9223372036854775807)
|
|
||||||
return 0;
|
|
||||||
if (S8ParseI32(S8("Not a number"), 10).ok)
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
@ -70,7 +56,5 @@ main()
|
|||||||
return 2;
|
return 2;
|
||||||
if (!ThreadTest())
|
if (!ThreadTest())
|
||||||
return 3;
|
return 3;
|
||||||
if (!ParseIntTest())
|
|
||||||
return 4;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user