Ejemplo n.º 1
0
 @Subroutine(value = "format")
 public static LispString format(LispString formatString, @Optional LispObject... objects) {
   checkFormatCharacters(formatString.getData());
   try {
     Object[] data = new Object[objects.length];
     for (int i = 0; i != objects.length; i++) {
       LispObject object = objects[i];
       data[i] =
           object instanceof LispNumber
               ? ((LispNumber) object).getData()
               : (object instanceof LispString
                   ? ((LispString) object).getData()
                   : object.toString());
     }
     return new LispString(String.format(formatString.getData(), data));
   } catch (MissingFormatArgumentException e1) {
     throw new LispException(JelispBundle.message("few.args.for.format.string"));
   } catch (UnknownFormatConversionException e2) {
     char c = e2.getMessage().charAt(e2.getMessage().length() - 2);
     if (c < 'A') throw new LispException(JelispBundle.message("unexpected.format.string.end"));
     throw new InvalidFormatOperationException(c);
   } catch (IllegalFormatConversionException e3) {
     throw new LispException(JelispBundle.message("format.arg.types.mismatch"));
   }
 }
Ejemplo n.º 2
0
 @Subroutine("message")
 public static LispString message(@Optional LispObject... args) {
   if (args.length == 0) throw new WrongNumberOfArgumentsException("message", 0);
   LispObject formatObj = args[0];
   if (formatObj instanceof LispString) {
     LispObject[] a = new LispObject[args.length - 1];
     System.arraycopy(args, 1, a, 0, args.length - 1);
     myCurrentMessage = format((LispString) formatObj, a);
   } else if (formatObj.equals(LispSymbol.ourNil)) {
     myCurrentMessage = new LispString(LispSymbol.ourNil.toString());
   } else {
     throw new WrongTypeArgumentException("stringp", formatObj);
   }
   GlobalEnvironment.echo(myCurrentMessage.getData(), GlobalEnvironment.MessageType.OUTPUT);
   return myCurrentMessage;
 }