using System.Collections.Generic; namespace CollabVMSharp { /// /// Utilities for converting lists of strings to and from Guacamole format /// public static class Guacutils { /// /// Encode an array of strings to guacamole format /// /// List of strings to be encoded /// A guacamole string array containing the provided strings public static string Encode(params string[] msgArr) { string res = ""; int i = 0; foreach (string s in msgArr) { res += s.Length.ToString(); res += "."; res += s; if (i == msgArr.Length - 1) res += ";"; else res += ","; i++; } return res; } /// /// Decode a guacamole string array /// /// String containing a guacamole array /// An array of strings public static string[] Decode(string msg) { List outArr = new List(); int pos = 0; while (pos < msg.Length - 1) { int dotpos = msg.IndexOf('.', pos + 1); string lenstr = msg.Substring(pos, dotpos - pos); int len = int.Parse(lenstr); string str = msg.Substring(dotpos + 1, len); outArr.Add(str); pos = dotpos + len + 2; } return outArr.ToArray(); } } }