This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Format doesn't handle signed numbers properly


In CLTL (22.3.3. Formatted Output to Character Streams) there's the
following sentence:
"The prefix parameters are generally integers, notated as optionally
signed decimal numbers. "

So, numbers like +20 should be parsed. Kawa currently pays attention
to minus signs, but the attached patch adds support for optional +
signs. The current behaviour is to throw a runtime exception: "~+ not
a valid format specifier"

E.g: (format #t "~,+4S" '(1 2 3))

I haven't studied SRFI 48 yet, so I can't be sure whether that has
anything to say on the matter. The check-format target passes with
this patch. (along with the rest of the test suite, of course)

I'm currently working my way through the format docs, the goal is to
integrate it with the pretty printer.

Charles.
(ChangeLog + test cases will be sent if you consider this a worthwhile change)
Index: gnu/kawa/functions/LispFormat.java
===================================================================
--- gnu/kawa/functions/LispFormat.java	(revision 7056)
+++ gnu/kawa/functions/LispFormat.java	(working copy)
@@ -58,10 +58,10 @@
 		stack.push(paramFromList);
 		ch = format[i++];
 	      }
-	    else if (ch == '-' || Character.digit(ch, 10) >= 0)
+	    else if (ch == '-' || ch == '+' || Character.digit(ch, 10) >= 0)
 	      {
 		boolean neg = (ch == '-');
-		if (neg)
+		if (neg || ch == '+')
 		  ch = format[i++];
 		int val = 0;
 		int start = i;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]