mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: FormatIntBase changed to work with int64, Esc: Fixed int64 constant issue
This commit is contained in:
parent
cebc09872d
commit
58c298b8a9
4 changed files with 18 additions and 16 deletions
|
|
@ -171,18 +171,17 @@ String FormatInt64(int64 i)
|
|||
return String::Make(20, [&](char *s) { return utoa64(i, s); });
|
||||
}
|
||||
|
||||
String FormatIntBase(int i, int base, int width, char lpad, int sign, bool upper)
|
||||
String FormatIntBase(int64 i, int base, int width, char lpad, int sign, bool upper)
|
||||
{
|
||||
enum { BUFFER = sizeof(int) * 8 + 1 };
|
||||
enum { BUFFER = sizeof(int64) * 8 + 1 };
|
||||
if(base < 2 || base > 36)
|
||||
return "<invalid base>";
|
||||
char buffer[BUFFER];
|
||||
char *const e = buffer + (int)BUFFER;
|
||||
char *p = e;
|
||||
const char *itoc = upper ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
if(sign < 0 || !IsNull(i))
|
||||
{
|
||||
unsigned x = i;
|
||||
if(sign < 0 || !IsNull(i)) {
|
||||
uint64 x = i;
|
||||
if(sign >= 0 && i < 0)
|
||||
x = -i;
|
||||
do
|
||||
|
|
@ -193,8 +192,7 @@ String FormatIntBase(int i, int base, int width, char lpad, int sign, bool upper
|
|||
bool do_sign = (sign > 0 || sign >= 0 && minus);
|
||||
if(do_sign && lpad != '0')
|
||||
*--p = (minus ? '-' : '+');
|
||||
if(width > e - p)
|
||||
{
|
||||
if(width > e - p) {
|
||||
char *b = e - min<int>(width, BUFFER);
|
||||
while(p > b)
|
||||
*--p = lpad;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ String FormatInt(int i);
|
|||
String FormatUInt64(uint64 w);
|
||||
String FormatInt64(int64 i);
|
||||
|
||||
String FormatIntBase(int i, int base, int width = 0, char lpad = ' ', int sign = 0, bool upper = false);
|
||||
String FormatIntBase(int64 i, int base, int width = 0, char lpad = ' ', int sign = 0, bool upper = false);
|
||||
String FormatIntDec(int i, int width, char lpad = ' ', bool always_sign = false);
|
||||
String FormatIntHex(int i, int width = 8, char lpad = '0');
|
||||
String FormatIntHexUpper(int i, int width = 8, char lpad = '0');
|
||||
|
|
@ -134,3 +134,4 @@ inline String Format64(uint64 a) { return FormatUInt6
|
|||
|
||||
inline String FormatDoubleFix(double x, int digits) { return FormatF(x, digits); }
|
||||
inline String FormatDoubleExp(double x, int digits) { return FormatE(x, digits); }
|
||||
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ int64]_[*@3 w])&]
|
|||
[s2; Returns integer as decimal string. If argument is Null, returns
|
||||
empty string.&]
|
||||
[s3; &]
|
||||
[s4; &]
|
||||
[s5;:FormatIntBase`(int`,int`,int`,char`,int`,bool`):%- String_[* FormatIntBase]([@(0.0.255) i
|
||||
nt]_[*@3 i], [@(0.0.255) int]_[*@3 radix], [@(0.0.255) int]_[*@3 width]_`=_[@3 0],
|
||||
[@(0.0.255) char]_[*@3 lpad]_`=_`'_`', [@(0.0.255) int]_[*@3 sign]_`=_[@3 0],
|
||||
[@(0.0.255) bool]_[*@3 upper]_`=_[@(0.0.255) false])&]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:FormatIntBase`(int64`,int`,int`,char`,int`,bool`):%- String
|
||||
[* FormatIntBase](int64 [*@3 i], [@(0.0.255) int] [*@3 base], [@(0.0.255) int]
|
||||
[*@3 width], [@(0.0.255) char] [*@3 lpad], [@(0.0.255) int] [*@3 sign],
|
||||
[@(0.0.255) bool] [*@3 upper])&]
|
||||
[s2; Formats a signed or unsigned integer [%-*@3 i] in a given [%-*@3 radix]
|
||||
with left padding to given [%-*@3 width] with a given [%-*@3 lpad]
|
||||
character. If [*@3 sign ]is `+1 `= always prepend `'`+`'/`-, if
|
||||
|
|
@ -44,7 +44,6 @@ character. If [*@3 sign ]is `+1 `= always prepend `'`+`'/`-, if
|
|||
is true, letters for base > 10 are uppercase. If [%-*@3 i] is Null,
|
||||
returns empty String.&]
|
||||
[s3; &]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:FormatIntDec`(int`,int`,char`,bool`):%- [_^String^ String]_[* FormatIntDec]([@(0.0.255) i
|
||||
nt]_[*@3 i], [@(0.0.255) int]_[*@3 width], [@(0.0.255) char]_[*@3 lpad]_`=_`'_`',
|
||||
|
|
|
|||
|
|
@ -315,8 +315,12 @@ void Esc::Term(SRVal& r)
|
|||
return;
|
||||
}
|
||||
if(IsNumber()) {
|
||||
// TODO: int64 !
|
||||
r = ReadDouble();
|
||||
Pos p = GetPos();
|
||||
r = ReadInt64();
|
||||
if(Char('.')) {
|
||||
SetPos(p);
|
||||
r = ReadDouble();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(IsString()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue