/* -*-c-*-
*
- * $Id: mptext.c,v 1.11 2001/06/16 23:42:17 mdw Exp $
+ * $Id: mptext.c,v 1.12 2002/01/13 19:51:18 mdw Exp $
*
* Textual representation of multiprecision numbers
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mptext.c,v $
+ * Revision 1.12 2002/01/13 19:51:18 mdw
+ * Extend the textual format to bases up to 62 by distinguishing case.
+ *
* Revision 1.11 2001/06/16 23:42:17 mdw
* Typesetting fixes.
*
/* --- If the radix is zero, look for leading zeros --- */
if (radix > 0) {
- assert(((void)"ascii radix must be <= 36", radix <= 36));
+ assert(((void)"ascii radix must be <= 62", radix <= 62));
rd = radix;
r = -1;
} else if (radix < 0) {
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
- ch = tolower(ch);
+ if (rd <= 36)
+ ch = tolower(ch);
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'Z')
+ x = ch - 'A' + 36;
else
break;
}
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
- ch = tolower(ch);
+ if (rd <= 36)
+ ch = tolower(ch);
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'Z')
+ x = ch - 'A' + 36;
else
break;
}
ch = x;
else if (x < 10)
ch = '0' + x;
- else
+ else if (x < 36) /* Ascii specific */
ch = 'a' + x - 10;
+ else
+ ch = 'A' + x - 36;
buf[--i] = ch;
if (z)
z--;
ch = x;
else if (x < 10)
ch = '0' + x;
+ else if (x < 36)
+ ch = 'a' + x - 10; /* Ascii specific */
else
- ch = 'a' + x - 10;
+ ch = 'A' + x - 36;
*q++ = ch;
if (q >= buf + sizeof(buf)) {
if ((rc = ops->put(buf, sizeof(buf), p)) != 0)
ch = x;
else if (x < 10)
ch = '0' + x;
+ else if (x < 36)
+ ch = 'a' + x - 10; /* Ascii specific */
else
- ch = 'a' + x - 10;
+ ch = 'A' + x - 36;
*q++ = ch;
rc = ops->put(buf, q - buf, p);
/* --- Check the radix for sensibleness --- */
if (radix > 0)
- assert(((void)"ascii radix must be <= 36", radix <= 36));
+ assert(((void)"ascii radix must be <= 62", radix <= 62));
else if (radix < 0)
assert(((void)"binary radix must fit in a byte", -radix < UCHAR_MAX));
else
# Test vectors for MP textual I/O
#
-# $Id: mptext,v 1.7 2001/06/16 13:22:40 mdw Exp $
+# $Id: mptext,v 1.8 2002/01/13 19:51:28 mdw Exp $
mptext-ascii {
# --- Perfectly valid things ---
0 37_ 10 37; # 37 is an invalid base, so stop at `_'
0 36_ 0 0; # 36 is a valid base, so restart and fail
+ # --- Big bases ---
+
+ 62 0 10 0;
+ 10 0 62 0;
+ 36 A 10 10;
+ 36 Z 10 35;
+ 37 A 10 36;
+ 10 36 37 A;
+ 62 Z 10 61;
+
# --- Word-boundary tests for binary-radix translation ---
8 1234567012 8 1234567012;