Packet abstract class
abstract class Packet { /// Transition table used to escape strings static Map<String, String> transTable = { r"/": r"\/", r" ": r"\s", r"|": r"\p", "\x07": r"\a", "\b": r"\b", "\f": r"\f", "\n": r"\n", "\r": r"\r", "\t": r"\t", "\v": r"\v", r"\": r"\\" }; /// Parses a string that holds key-value-pairs. These are escaped according to the /// TeamSpeak-Protocol. static Map<String, String> parseItem(String pItem){ Map<String, String> lMap = new Map(); pItem.split(" ").forEach((String pString){ final int lIndex = pString.indexOf("="); if(lIndex < 0){ throw new Exception("Missing '='"); } String lKey = unescape(pString.substring(0, lIndex)); String lValue = unescape(pString.substring(pString.indexOf("=")+1)); lMap[lKey] = lValue; }); return lMap; } /// Escapes a string so according to the TeamSpeak-protocol static String escape(String pString){ String lString = pString; transTable.forEach((String pKey, String pValue){ lString = lString.replaceAll(pKey, pValue); }); return lString; } /// Unescapes a string that was previously escaped according to the TeamSpeak-protocol static String unescape(String pString){ String lString = pString; transTable.forEach((String pKey, String pValue){ lString = lString.replaceAll(pValue, pKey); }); return lString; } }
Subclasses
Static Properties
Static Methods
Map<String, String> parseItem(String pItem) #
Parses a string that holds key-value-pairs. These are escaped according to the TeamSpeak-Protocol.
static Map<String, String> parseItem(String pItem){ Map<String, String> lMap = new Map(); pItem.split(" ").forEach((String pString){ final int lIndex = pString.indexOf("="); if(lIndex < 0){ throw new Exception("Missing '='"); } String lKey = unescape(pString.substring(0, lIndex)); String lValue = unescape(pString.substring(pString.indexOf("=")+1)); lMap[lKey] = lValue; }); return lMap; }