mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Made an integer-to-string API for user-space to use.
This commit is contained in:
parent
00f5c627b7
commit
d494dc2d53
2 changed files with 19 additions and 11 deletions
|
@ -28,9 +28,9 @@
|
||||||
|
|
||||||
namespace Maxsi
|
namespace Maxsi
|
||||||
{
|
{
|
||||||
namespace Format
|
namespace String
|
||||||
{
|
{
|
||||||
int UInt8ToString(uint8_t Num, char* Dest)
|
int ConvertUInt8(uint8_t Num, char* Dest)
|
||||||
{
|
{
|
||||||
uint8_t Copy = Num;
|
uint8_t Copy = Num;
|
||||||
int Result = 0;
|
int Result = 0;
|
||||||
|
@ -46,7 +46,7 @@ namespace Maxsi
|
||||||
return Result + 1;
|
return Result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UInt16ToString(uint16_t Num, char* Dest)
|
int ConvertUInt16(uint16_t Num, char* Dest)
|
||||||
{
|
{
|
||||||
uint16_t Copy = Num;
|
uint16_t Copy = Num;
|
||||||
int Result = 0;
|
int Result = 0;
|
||||||
|
@ -62,7 +62,7 @@ namespace Maxsi
|
||||||
return Result + 1;
|
return Result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UInt32ToString(uint32_t Num, char* Dest)
|
int ConvertUInt32(uint32_t Num, char* Dest)
|
||||||
{
|
{
|
||||||
uint32_t Copy = Num;
|
uint32_t Copy = Num;
|
||||||
int Result = 0;
|
int Result = 0;
|
||||||
|
@ -78,7 +78,7 @@ namespace Maxsi
|
||||||
return Result + 1;
|
return Result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UInt64ToString(uint64_t Num, char* Dest)
|
int ConvertUInt64(uint64_t Num, char* Dest)
|
||||||
{
|
{
|
||||||
uint64_t Copy = Num;
|
uint64_t Copy = Num;
|
||||||
int Result = 0;
|
int Result = 0;
|
||||||
|
@ -96,7 +96,7 @@ namespace Maxsi
|
||||||
|
|
||||||
// Missing functions here.
|
// Missing functions here.
|
||||||
|
|
||||||
int UInt32ToString16(uint32_t Num, char* Dest)
|
int ConvertUInt3216(uint32_t Num, char* Dest)
|
||||||
{
|
{
|
||||||
uint32_t Copy = Num;
|
uint32_t Copy = Num;
|
||||||
int Result = 0;
|
int Result = 0;
|
||||||
|
@ -120,7 +120,7 @@ namespace Maxsi
|
||||||
return Result + 1;
|
return Result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UInt64ToString16(uint64_t Num, char* Dest)
|
int ConvertUInt6416(uint64_t Num, char* Dest)
|
||||||
{
|
{
|
||||||
uint64_t Copy = Num;
|
uint64_t Copy = Num;
|
||||||
int Result = 0;
|
int Result = 0;
|
||||||
|
@ -143,7 +143,10 @@ namespace Maxsi
|
||||||
|
|
||||||
return Result + 1;
|
return Result + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Format
|
||||||
|
{
|
||||||
#define READY_SIZE 128
|
#define READY_SIZE 128
|
||||||
|
|
||||||
#define READY_FLUSH() \
|
#define READY_FLUSH() \
|
||||||
|
@ -229,28 +232,28 @@ namespace Maxsi
|
||||||
{
|
{
|
||||||
if ( READY_SIZE - readylen < 10 ) { READY_FLUSH(); }
|
if ( READY_SIZE - readylen < 10 ) { READY_FLUSH(); }
|
||||||
uint32_t num = va_arg(parameters, uint32_t);
|
uint32_t num = va_arg(parameters, uint32_t);
|
||||||
readylen += UInt32ToString(num, ready + readylen);
|
readylen += String::ConvertUInt32(num, ready + readylen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UNSIGNED | BIT64:
|
case UNSIGNED | BIT64:
|
||||||
{
|
{
|
||||||
if ( READY_SIZE - readylen < 20 ) { READY_FLUSH(); }
|
if ( READY_SIZE - readylen < 20 ) { READY_FLUSH(); }
|
||||||
uint64_t num = va_arg(parameters, uint64_t);
|
uint64_t num = va_arg(parameters, uint64_t);
|
||||||
readylen += UInt64ToString(num, ready + readylen);
|
readylen += String::ConvertUInt64(num, ready + readylen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UNSIGNED | HEX:
|
case UNSIGNED | HEX:
|
||||||
{
|
{
|
||||||
if ( READY_SIZE - readylen < 8 ) { READY_FLUSH(); }
|
if ( READY_SIZE - readylen < 8 ) { READY_FLUSH(); }
|
||||||
uint32_t num = va_arg(parameters, uint32_t);
|
uint32_t num = va_arg(parameters, uint32_t);
|
||||||
readylen += UInt32ToString16(num, ready + readylen);
|
readylen += String::ConvertUInt3216(num, ready + readylen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UNSIGNED | BIT64 | HEX:
|
case UNSIGNED | BIT64 | HEX:
|
||||||
{
|
{
|
||||||
if ( READY_SIZE - readylen < 16 ) { READY_FLUSH(); }
|
if ( READY_SIZE - readylen < 16 ) { READY_FLUSH(); }
|
||||||
uint64_t num = va_arg(parameters, uint64_t);
|
uint64_t num = va_arg(parameters, uint64_t);
|
||||||
readylen += UInt64ToString16(num, ready + readylen);
|
readylen += String::ConvertUInt6416(num, ready + readylen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING:
|
case STRING:
|
||||||
|
|
|
@ -39,6 +39,11 @@ namespace Maxsi
|
||||||
int Compare(const char* A, const char* B);
|
int Compare(const char* A, const char* B);
|
||||||
int CompareN(const char* A, const char* B, size_t MaxLength);
|
int CompareN(const char* A, const char* B, size_t MaxLength);
|
||||||
int StartsWith(const char* Haystack, const char* Needle);
|
int StartsWith(const char* Haystack, const char* Needle);
|
||||||
|
|
||||||
|
int ConvertUInt8T(uint8_t num, char* dest);
|
||||||
|
int ConvertUInt16(uint16_t num, char* dest);
|
||||||
|
int ConvertUInt32(uint32_t num, char* dest);
|
||||||
|
int ConvertUInt64(uint64_t num, char* dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue