diff --git a/src/as/com/threerings/util/StringUtil.as b/src/as/com/threerings/util/StringUtil.as index 792160246..ee2d4e9b3 100644 --- a/src/as/com/threerings/util/StringUtil.as +++ b/src/as/com/threerings/util/StringUtil.as @@ -245,6 +245,35 @@ public class StringUtil return array; } + /** + * Turn the specified byte array, containing only ascii characters, into a String. + */ + public static function fromBytes (bytes :ByteArray) :String + { + var s :String = ""; + if (bytes != null) { + for (var ii :int = 0; ii < bytes.length; ii++) { + s += String.fromCharCode(bytes[ii]); + } + } + return s; + } + + /** + * Turn the specified String, containing only ascii characters, into a ByteArray. + */ + public static function toBytes (s :String) :ByteArray + { + if (s == null) { + return null; + } + var ba :ByteArray = new ByteArray(); + for (var ii :int = 0; ii < s.length; ii++) { + ba[ii] = int(s.charCodeAt(ii)) & 0xFF; + } + return ba; + } + /** * Generates a string from the supplied bytes that is the hex encoded * representation of those byts. Returns the empty String for a