1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

Add missing import, support another format type

This commit is contained in:
Kevin Glynn 2011-05-31 09:16:48 +02:00
parent 338c56e6ae
commit c785f8985e
2 changed files with 30 additions and 11 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is
@ -28,7 +28,9 @@
<Return>System.String</Return>
</Method>
<Method>
<Imports />
<Imports>
<Import>CS2JNet.System.IntegerSupport</Import>
</Imports>
<Java>IntegerSupport.mkString(${this}, ${str})</Java>
<Params>
<Param>
@ -53,7 +55,7 @@
</Method>
<Method>
<Imports>
<Import>CS2JNet.System.*</Import>
<Import>CS2JNet.System.IntegerSupport</Import>
</Imports>
<Java>IntegerSupport.parse(${str}, ${style})</Java>
<Params>

View File

@ -52,15 +52,32 @@ public class IntegerSupport {
public static String mkString(int i, String style) throws NotImplementedException
{
if (style.toLowerCase().equals("x")) {
String retStr = Integer.toHexString(i);
if (style.equals("X")) {
return retStr.toUpperCase();
}
return retStr;
}
if (style.toLowerCase().equals("x")) {
String retStr = Integer.toHexString(i);
if (style.equals("X")) {
return retStr.toUpperCase();
}
return retStr;
}
if (style.toLowerCase().startsWith("d")) {
String width = "";
if (style.length() > 1)
width = "0" + String.valueOf(Integer.valueOf(style.substring(1)) + (i < 0 ? 1 : 0));
String fmt = "%0$"+width+"d";
String retStr = String.format(fmt, i);
return retStr;
}
throw new NotImplementedException("IntegerSupport.mkString does not support format string '" + style + "'");
}
public static void main(String[] args) throws NotImplementedException {
int integral = 8395;
System.out.printf("D: %0$s\n", mkString(integral, "D"));
System.out.printf("D: %0$s\n", mkString(integral, "D6"));
System.out.printf("D: %0$s\n", mkString(-integral, "D6"));
}
}