Clean up and streamline thousands separator function.

This commit is contained in:
Mari the Deer 2022-09-20 16:01:57 +02:00
commit 5c19c6fe50
2 changed files with 11 additions and 17 deletions

View file

@ -1,3 +1,3 @@
[default]
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r485 \cu(Tue 20 Sep 13:00:26 CEST 2022)\c-";
SWWM_SHORTVER="\cw1.3pre r485 \cu(2022-09-20 13:00:26)\c-";
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r486 \cu(Tue 20 Sep 16:01:57 CEST 2022)\c-";
SWWM_SHORTVER="\cw1.3pre r486 \cu(2022-09-20 16:01:57)\c-";

View file

@ -279,9 +279,11 @@ Class SWWMUtility
return c;
}
// not sure if I should use this, looks a bit ugly
static clearscope void ThousandsStr( out String s, int col = -1 )
// bit ugly, but it works
static clearscope void ThousandsStr( out String s, int col = Font.CR_UNDEFINED, String colstr = "" )
{
if ( (col < Font.CR_UNDEFINED) || (col >= Font.NUM_TEXT_COLORS) )
ThrowAbortException("col parameter out of range, use colstr for non-standard font colors.");
String nstr = s;
s.Truncate(0);
int len = nstr.CodePointCount();
@ -295,26 +297,18 @@ Class SWWMUtility
t = (t-1)%3;
if ( (pos < len) && !t )
{
if ( col != -1 )
{
s.AppendCharacter(0x1C);
s.AppendCharacter(0x61+col);
}
s.AppendCharacter(0x2C);
if ( col != -1 )
{
s.AppendCharacter(0x1C);
s.AppendCharacter(0x2D);
}
if ( colstr != "" ) s.AppendFormat("\c[%s],\c-",colstr);
else if ( col != Font.CR_UNDEFINED ) s.AppendFormat("\c%c,\c-",0x61+col);
else s.AppendCharacter(0x2C);
}
}
}
static clearscope String ThousandsNum( int n, int col = -1, int digits = 0 )
static clearscope String ThousandsNum( int n, int col = Font.CR_UNDEFINED, String colstr = "", int digits = 0 )
{
String nstr;
if ( digits > 0 ) nstr = String.Format("%0*d",digits,n);
else nstr = String.Format("%d",n);
ThousandsStr(nstr,col);
ThousandsStr(nstr,col,colstr);
return nstr;
}