summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-06-29 23:29:56 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-06-29 23:29:56 (GMT)
commit3296e696db4e46f63f7a5348ac977b2b0a32ecbc (patch)
tree1d3c84dcc09208485d3ecc8e4749fa8bdb2786a1 /Objects
parentd4128f397dbfe400e34d399d6b4595240b3de546 (diff)
downloadcpython-3296e696db4e46f63f7a5348ac977b2b0a32ecbc.zip
cpython-3296e696db4e46f63f7a5348ac977b2b0a32ecbc.tar.gz
cpython-3296e696db4e46f63f7a5348ac977b2b0a32ecbc.tar.bz2
SF bug #1224347: int/long unification and hex()
Hex longs now print with lowercase letters like their int counterparts.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c4
-rw-r--r--Objects/stringobject.c16
2 files changed, 7 insertions, 13 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index e4fc553..1f328dd3 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -1090,7 +1090,7 @@ long_format(PyObject *aa, int base, int addL)
assert(accumbits >= basebits);
do {
char cdigit = (char)(accum & (base - 1));
- cdigit += (cdigit < 10) ? '0' : 'A'-10;
+ cdigit += (cdigit < 10) ? '0' : 'a'-10;
assert(p > PyString_AS_STRING(str));
*--p = cdigit;
accumbits -= basebits;
@@ -1144,7 +1144,7 @@ long_format(PyObject *aa, int base, int addL)
digit nextrem = (digit)(rem / base);
char c = (char)(rem - nextrem * base);
assert(p > PyString_AS_STRING(str));
- c += (c < 10) ? '0' : 'A'-10;
+ c += (c < 10) ? '0' : 'a'-10;
*--p = c;
rem = nextrem;
--ntostore;
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 176e0d2b..8a9dc52 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -3753,18 +3753,12 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
}
/* Fix up case for hex conversions. */
- switch (type) {
- case 'x':
- /* Need to convert all upper case letters to lower case. */
+ if (type == 'X') {
+ /* Need to convert all lower case letters to upper case.
+ and need to convert 0x to 0X (and -0x to -0X). */
for (i = 0; i < len; i++)
- if (buf[i] >= 'A' && buf[i] <= 'F')
- buf[i] += 'a'-'A';
- break;
- case 'X':
- /* Need to convert 0x to 0X (and -0x to -0X). */
- if (buf[sign + 1] == 'x')
- buf[sign + 1] = 'X';
- break;
+ if (buf[i] >= 'a' && buf[i] <= 'x')
+ buf[i] -= 'a'-'A';
}
*pbuf = buf;
*plen = len;