added simple socket server
This commit is contained in:
24
core.c
24
core.c
@@ -231,28 +231,27 @@ StringList strSplit(Arena *arena, string splitStr, string inputStr) {
|
||||
return result;
|
||||
}
|
||||
|
||||
ParsePositiveIntResult parsePositiveInt(string str, size_t *lengthPointer) {
|
||||
Int32Result parsePositiveInt(string str) {
|
||||
size_t numEnd = 0;
|
||||
char currChar = str.str[numEnd];
|
||||
while (numEnd < str.length && isNumeric(currChar)) {
|
||||
currChar = str.str[++numEnd];
|
||||
*lengthPointer += 1;
|
||||
numEnd++;
|
||||
currChar = str.str[numEnd];
|
||||
}
|
||||
*lengthPointer -= 1;
|
||||
if (numEnd > 0) {
|
||||
uint8 result = 0;
|
||||
uint32 result = 0;
|
||||
for (size_t i = 0; i < numEnd; i++) {
|
||||
result *= 10;
|
||||
result += str.str[i] - '0';
|
||||
}
|
||||
return (ParsePositiveIntResult){ .result=result, .valid=true };
|
||||
return (Int32Result){ .result=result, .valid=true };
|
||||
} else {
|
||||
return (ParsePositiveIntResult){ .result=0, .valid=false};
|
||||
return (Int32Result){ .result=0, .valid=false};
|
||||
}
|
||||
}
|
||||
|
||||
ParsePositiveReal32Result parsePositiveReal32(string str, size_t *lengthPointer) {
|
||||
ParsePositiveReal32Result result = { .result=NAN, .valid=false};
|
||||
Real32Result parsePositiveReal32(string str) {
|
||||
Real32Result result = { .result=NAN, .valid=false};
|
||||
|
||||
string wholePartStr = (string){0};
|
||||
string fractionalPartStr = (string){0};
|
||||
@@ -271,9 +270,8 @@ ParsePositiveReal32Result parsePositiveReal32(string str, size_t *lengthPointer)
|
||||
c++;
|
||||
}
|
||||
if (split) {
|
||||
ParsePositiveIntResult wholePartParsed = parsePositiveInt(wholePartStr, lengthPointer);
|
||||
*lengthPointer += 1;
|
||||
ParsePositiveIntResult fractionalPartParsed = parsePositiveInt(fractionalPartStr, lengthPointer);
|
||||
Int32Result wholePartParsed = parsePositiveInt(wholePartStr);
|
||||
Int32Result fractionalPartParsed = parsePositiveInt(fractionalPartStr);
|
||||
if (wholePartParsed.valid && fractionalPartParsed.valid) {
|
||||
// TODO(dledda): implement powf with intrinsics? or just custom
|
||||
real32 fractionalPartMultiplier = 1.0f / powf(10.0f, (real32)fractionalPartStr.length);
|
||||
@@ -281,7 +279,7 @@ ParsePositiveReal32Result parsePositiveReal32(string str, size_t *lengthPointer)
|
||||
result.valid = true;
|
||||
}
|
||||
} else if (c > 0) {
|
||||
ParsePositiveIntResult intPartParsed = parsePositiveInt(str, lengthPointer);
|
||||
Int32Result intPartParsed = parsePositiveInt(str);
|
||||
if (intPartParsed.valid) {
|
||||
result.result = (real32)intPartParsed.result;
|
||||
result.valid = true;
|
||||
|
||||
Reference in New Issue
Block a user