package net.sf.openrocket.util;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
public class TextUtil {
+
+
private static final char[] HEX = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
-
+
+ /**
+ * Return the byte array for the string in the given charset.
+ *
+ * This function is implemented because Froyo (Android API 8) does not support
+ * String.getBytes(Charset)
+ *
+ * @param string
+ * @param charSet
+ * @return
+ */
+ public static byte[] convertStringToBytes( String string, Charset charSet ) {
+ ByteBuffer encoded = charSet.encode(string);
+ return encoded.array();
+ }
+
/**
* Return the bytes formatted as a hexadecimal string. The length of the
s = s.replace(">", ">");
return s;
}
+
+ /*
+ * Returns a word-wrapped version of given input string using HTML syntax, wrapped to len characters.
+ */
+ public static String wrap(String in,int len) {
+ in=in.trim();
+ if(in.length()<len) return in;
+ if(in.substring(0, len).contains("\n"))
+ return in.substring(0, in.indexOf("\n")).trim() + "\n\n" + wrap(in.substring(in.indexOf("\n") + 1), len);
+ int place=Math.max(Math.max(in.lastIndexOf(" ",len),in.lastIndexOf("\t",len)),in.lastIndexOf("-",len));
+ return "<html>"+in.substring(0,place).trim()+"<br>"+wrap(in.substring(place),len);
+ }
+
}