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

Support for StingBuilder.ensurecapacity and corrected translation for setlength

This commit is contained in:
Kevin Glynn 2010-07-14 15:13:57 -05:00
parent aa8dd21ace
commit 1f2a9adba8
2 changed files with 48 additions and 1 deletions

View File

@ -24,7 +24,16 @@
<Name>Length</Name>
<Type>System.Int32</Type>
<Get>${this}.length()</Get>
<Set>${this}.setlength(${value})</Set>
<Set>StringBuilderSupport.setLength(${this}, ${value})</Set>
<Imports>
<Import>RusticiSoftware.System.Text.StringBuilderSupport</Import>
</Imports>
</Property>
<Property>
<Name>Capacity</Name>
<Type>System.Int32</Type>
<Get>${this}.capacity()</Get>
<Set>${this}.ensureCapacity(${value})</Set>
</Property>
</Properties>
<Methods>
@ -50,6 +59,20 @@
</Params>
<Java>${this}.append((${arg}) + System.getProperty("line.separator"))</Java>
</Method>
<Method>
<Return>System.Int32</Return>
<Name>EnsureCapacity</Name>
<Params>
<Param>
<Name>arg</Name>
<Type>System.Int32</Type>
</Param>
</Params>
<Imports>
<Import>RusticiSoftware.System.Text.StringBuilderSupport</Import>
</Imports>
<Java>StringBuilderSupport.ensureCapacity(${this}, ${arg})</Java>
</Method>
<Method>
<Return>System.Text.StringBuilder</Return>
<Name>Insert</Name>

View File

@ -0,0 +1,24 @@
package RusticiSoftware.System.Text;
public class StringBuilderSupport {
// In C# ensureCapacity returns the new capacity
public static int ensureCapacity(StringBuilder sb, int capacity) {
sb.ensureCapacity(capacity);
return sb.capacity();
}
// In C# setLength pads with spaces
public static void setLength(StringBuilder sb, int newLen) {
if (sb.length() >= newLen) {
sb.setLength(newLen);
}
sb.append(String.format("%1$-" + (newLen - sb.length()) + "s", ""));
}
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("hello");
System.out.println("**" + sb + "**");
StringBuilderSupport.setLength(sb,7);
System.out.println("**" + sb + "**");
}
}