(svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
authorrubidium
Sun, 29 Jul 2007 12:13:22 +0000
changeset 7356 2f277ca36d46
parent 7355 fde614d360ea
child 7357 de2fe2f2462c
(svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
src/strings.cpp
--- a/src/strings.cpp	Sun Jul 29 12:11:50 2007 +0000
+++ b/src/strings.cpp	Sun Jul 29 12:13:22 2007 +0000
@@ -224,27 +224,14 @@
 	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint64));
 }
 
-static const uint32 _divisor_table[] = {
-	1000000000,
-	100000000,
-	10000000,
-	1000000,
-
-	100000,
-	10000,
-	1000,
-	100,
-	10,
-	1
-};
-
 // TODO
-static char *FormatCommaNumber(char *buff, int32 number, const char* last)
+static char *FormatCommaNumber(char *buff, int64 number, const char *last)
 {
-	uint32 quot;
+	uint64 divisor = 10000000000000000000ULL;
+	uint64 quot;
 	int i;
-	uint32 tot;
-	uint32 num;
+	uint64 tot;
+	uint64 num;
 
 	if (number < 0) {
 		*buff++ = '-';
@@ -254,16 +241,18 @@
 	num = number;
 
 	tot = 0;
-	for (i = 0; i != 10; i++) {
+	for (i = 0; i < 20; i++) {
 		quot = 0;
-		if (num >= _divisor_table[i]) {
-			quot = num / _divisor_table[i];
-			num = num % _divisor_table[i];
+		if (num >= divisor) {
+			quot = num / divisor;
+			num = num % divisor;
 		}
-		if (tot |= quot || i == 9) {
+		if (tot |= quot || i == 19) {
 			*buff++ = '0' + quot;
-			if (i == 0 || i == 3 || i == 6) *buff++ = ',';
+			if ((i % 3) == 1 && i != 19) *buff++ = ',';
 		}
+
+		divisor /= 10;
 	}
 
 	*buff = '\0';
@@ -272,12 +261,13 @@
 }
 
 // TODO
-static char *FormatNoCommaNumber(char *buff, int32 number, const char* last)
+static char *FormatNoCommaNumber(char *buff, int64 number, const char *last)
 {
-	uint32 quot;
+	uint64 divisor = 10000000000000000000ULL;
+	uint64 quot;
 	int i;
-	uint32 tot;
-	uint32 num;
+	uint64 tot;
+	uint64 num;
 
 	if (number < 0) {
 		buff = strecpy(buff, "-", last);
@@ -287,15 +277,17 @@
 	num = number;
 
 	tot = 0;
-	for (i = 0; i != 10; i++) {
+	for (i = 0; i < 20; i++) {
 		quot = 0;
-		if (num >= _divisor_table[i]) {
-			quot = num / _divisor_table[i];
-			num = num % _divisor_table[i];
+		if (num >= divisor) {
+			quot = num / divisor;
+			num = num % divisor;
 		}
-		if (tot |= quot || i == 9) {
+		if (tot |= quot || i == 19) {
 			*buff++ = '0' + quot;
 		}
+
+		divisor /= 10;
 	}
 
 	*buff = '\0';
@@ -394,10 +386,11 @@
 	return buff;
 }
 
-static int DeterminePluralForm(int32 n)
+static int DeterminePluralForm(int64 cnt)
 {
+	uint64 n = cnt;
 	/* The absolute value determines plurality */
-	if (n < 0) n = -n;
+	if (cnt < 0) n = -cnt;
 
 	switch (_langpack->plural_form) {
 	/* Two forms, singular used for one only
@@ -774,7 +767,7 @@
 			}
 
 			case SCC_COMMA: // {COMMA}
-				buff = FormatCommaNumber(buff, GetInt32(&argv), last);
+				buff = FormatCommaNumber(buff, GetInt64(&argv), last);
 				break;
 
 			case SCC_ARG_INDEX: // Move argument pointer
@@ -782,7 +775,7 @@
 				break;
 
 			case SCC_PLURAL_LIST: { // {P}
-				int32 v = argv_orig[(byte)*str++]; // contains the number that determines plural
+				int64 v = argv_orig[(byte)*str++]; // contains the number that determines plural
 				int len;
 				str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len);
 				buff += len;
@@ -790,7 +783,7 @@
 			}
 
 			case SCC_NUM: // {NUM}
-				buff = FormatNoCommaNumber(buff, GetInt32(&argv), last);
+				buff = FormatNoCommaNumber(buff, GetInt64(&argv), last);
 				break;
 
 			case SCC_CURRENCY: // {CURRENCY}