From: Finn B. <bc...@us...> - 2002-05-26 20:41:16
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv6639 Modified Files: PyString.java Log Message: Fix several bugs in string->complex conversion. Fixes patch "[ 511321 ] Jython complex from string". Index: PyString.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyString.java,v retrieving revision 2.54 retrieving revision 2.55 diff -C2 -d -r2.54 -r2.55 *** PyString.java 6 Jan 2002 21:19:13 -0000 2.54 --- PyString.java 26 May 2002 20:41:13 -0000 2.55 *************** *** 760,781 **** char c = string.charAt(s); switch (c) { - case '\0': - if (s != n) - throw Py.ValueError("null byte in argument for " + - "complex()"); - if (!done) - sw_error = true; - break; - case '-': sign = -1; /* Fallthrough */ case '+': ! if (done) sw_error = true; ! s++; ! c = string.charAt(s); ! if (c == '\0' || c == '+' || c == '-' || ! Character.isSpaceChar(c)) sw_error = true; break; --- 760,776 ---- char c = string.charAt(s); switch (c) { case '-': sign = -1; /* Fallthrough */ case '+': ! if (done || s+1 == n) { sw_error = true; ! break; ! } ! // a character is guaranteed, but it better be a digit ! // or J or j ! c = string.charAt(++s); // eat the sign character ! // and check the next ! if (!Character.isDigit(c) && c!='J' && c!='j') sw_error = true; break; *************** *** 793,816 **** } got_im = true; ! s++; ! c = string.charAt(s); ! if (c != '+' && c != '-') ! done = true; break; default: - if (Character.isSpaceChar(c)) { - while (s < n && Character.isSpaceChar(string.charAt(s))) - s++; - if (s != n) - sw_error = true; - else - done = true; - break; - } - c = string.charAt(s); boolean digit_or_dot = (c == '.' || Character.isDigit(c)); ! if (done || !digit_or_dot) { sw_error = true; break; --- 788,806 ---- } got_im = true; ! done = got_re; ! sign = 1; ! s++; // eat the J or j ! break; ! case ' ': ! while (s < n && Character.isSpaceChar(string.charAt(s))) ! s++; ! if (s != n) ! sw_error = true; break; default: boolean digit_or_dot = (c == '.' || Character.isDigit(c)); ! if (!digit_or_dot) { sw_error = true; break; *************** *** 819,825 **** z = Double.valueOf(string.substring(s, end)).doubleValue(); s=end; ! c = string.charAt(s); ! if (c == 'J' || c == 'j') { ! break; } if (got_re) { --- 809,817 ---- z = Double.valueOf(string.substring(s, end)).doubleValue(); s=end; ! if (s < n) { ! c = string.charAt(s); ! if (c == 'J' || c == 'j') { ! break; ! } } if (got_re) { *************** *** 831,836 **** x = sign * z; got_re = true; ! if (got_im) ! done = true; z = -1.0; sign = 1; --- 823,827 ---- x = sign * z; got_re = true; ! done = got_im; z = -1.0; sign = 1; *************** *** 859,870 **** if (c == 'e' || c == 'E') { if (s < n) { ! c = string.charAt(s++); if (c == '+' || c == '-') ! continue; } } ! break; } ! return s-1; } --- 850,862 ---- if (c == 'e' || c == 'E') { if (s < n) { ! c = string.charAt(s); if (c == '+' || c == '-') ! s++; ! continue; } } ! return s-1; } ! return s; } |