projects
/
u
/
mdw
/
catacomb
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8646ee3
)
Extend the textual format to bases up to 62 by distinguishing case.
author
mdw
<mdw>
Sun, 13 Jan 2002 19:51:28 +0000
(19:51 +0000)
committer
mdw
<mdw>
Sun, 13 Jan 2002 19:51:28 +0000
(19:51 +0000)
mptext.c
patch
|
blob
|
blame
|
history
tests/mptext
patch
|
blob
|
blame
|
history
diff --git
a/mptext.c
b/mptext.c
index
f6bc2e3
..
c479d78
100644
(file)
--- a/
mptext.c
+++ b/
mptext.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: mptext.c,v 1.1
1 2001/06/16 23:42:17
mdw Exp $
+ * $Id: mptext.c,v 1.1
2 2002/01/13 19:51:18
mdw Exp $
*
* Textual representation of multiprecision numbers
*
*
* Textual representation of multiprecision numbers
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: mptext.c,v $
/*----- 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.
*
* Revision 1.11 2001/06/16 23:42:17 mdw
* Typesetting fixes.
*
@@
-192,7
+195,7
@@
mp *mp_read(mp *m, int radix, const mptext_ops *ops, void *p)
/* --- If the radix is zero, look for leading zeros --- */
if (radix > 0) {
/* --- 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) {
rd = radix;
r = -1;
} else if (radix < 0) {
@@
-270,9
+273,12
@@
restart:
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
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;
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'Z')
+ x = ch - 'A' + 36;
else
break;
}
else
break;
}
@@
-364,9
+370,12
@@
restart:
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
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;
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'Z')
+ x = ch - 'A' + 36;
else
break;
}
else
break;
}
@@
-519,8
+528,10
@@
static int simple(mpw n, int radix, unsigned z,
ch = x;
else if (x < 10)
ch = '0' + x;
ch = x;
else if (x < 10)
ch = '0' + x;
- else
+ else
if (x < 36) /* Ascii specific */
ch = 'a' + x - 10;
ch = 'a' + x - 10;
+ else
+ ch = 'A' + x - 36;
buf[--i] = ch;
if (z)
z--;
buf[--i] = ch;
if (z)
z--;
@@
-639,8
+650,10
@@
static int binary(mp *m, int bit, int radix, const mptext_ops *ops, void *p)
ch = x;
else if (x < 10)
ch = '0' + x;
ch = x;
else if (x < 10)
ch = '0' + x;
+ else if (x < 36)
+ ch = 'a' + x - 10; /* Ascii specific */
else
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)
*q++ = ch;
if (q >= buf + sizeof(buf)) {
if ((rc = ops->put(buf, sizeof(buf), p)) != 0)
@@
-655,8
+668,10
@@
static int binary(mp *m, int bit, int radix, const mptext_ops *ops, void *p)
ch = x;
else if (x < 10)
ch = '0' + x;
ch = x;
else if (x < 10)
ch = '0' + x;
+ else if (x < 36)
+ ch = 'a' + x - 10; /* Ascii specific */
else
else
- ch = '
a' + x - 10
;
+ ch = '
A' + x - 36
;
*q++ = ch;
rc = ops->put(buf, q - buf, p);
*q++ = ch;
rc = ops->put(buf, q - buf, p);
@@
-681,7
+696,7
@@
int mp_write(mp *m, int radix, const mptext_ops *ops, void *p)
/* --- Check the radix for sensibleness --- */
if (radix > 0)
/* --- 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
else if (radix < 0)
assert(((void)"binary radix must fit in a byte", -radix < UCHAR_MAX));
else
diff --git
a/tests/mptext
b/tests/mptext
index
1d9168a
..
a81cfa9
100644
(file)
--- a/
tests/mptext
+++ b/
tests/mptext
@@
-1,6
+1,6
@@
# Test vectors for MP textual I/O
#
# 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 ---
mptext-ascii {
# --- Perfectly valid things ---
@@
-28,6
+28,16
@@
mptext-ascii {
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
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;
# --- Word-boundary tests for binary-radix translation ---
8 1234567012 8 1234567012;