Example #1
0
        /// <summary>
        /// Also print character value to debug unreadable unicode symbols
        /// </summary>
        /// <param name="value">Value t obe converted</param>
        /// <param name="baseChars">The characters to be used for encoding</param>
        /// <returns>An encoded value</returns>
        public static string IntToStringFastDebug(ulong value, BaseEncoder encoder)
        {
            // 64 is the worst cast buffer size for base 2 and UInt64.MaxValue
            int i = 64;
            char[] buffer = new char[i];
            int[] bufferVal = new int[i];
            UInt64 targetBase = (UInt64)encoder.Characters.Length;

            do
            {
                buffer[--i] = encoder.Characters[(int)(value % targetBase)];
                bufferVal[i] = (int)(value % targetBase);
                value = value / targetBase;
            }
            while (value > 0);

            char[] result = new char[64 - i];
            int[] resultVal = new int[64 - i];

            Array.Copy(buffer, i, result, 0, 64 - i);
            Array.Copy(bufferVal, i, resultVal, 0, 64 - i);

            StringBuilder b = new StringBuilder();
            b.Append(new string(result));
            b.Append("\n");

            foreach (int val in resultVal)
                b.AppendFormat("{0},", val);

            b.Append("\n");
            return b.ToString();
        }
Example #2
0
 /// <summary>
 /// Encode an integer using a custom encoder
 /// </summary>
 /// <param name="value">Value to be encoded</param>
 /// <param name="encoder">The custom encoder to be used</param>
 /// <returns>An integer encoded to a string</returns>
 public static string Encode(ulong value, BaseEncoder encoder)
 {
     return encoder.Encode(value);
 }
Example #3
0
 /// <summary>
 /// Decode a string using a custom encoder
 /// </summary>
 /// <param name="encodedValue">The encoded string</param>
 /// <param name="encoder">The custom encoder to be used</param>
 /// <returns>A converted integer</returns>
 public static ulong Decode(string encodedValue, BaseEncoder encoder)
 {
     return encoder.Decode(encodedValue);
 }
Example #4
0
 /// <summary>
 /// An optimized method using an array as buffer instead of 
 /// string concatenation. This is faster for return values having 
 /// </summary>
 /// <param name="value">Value to be converted</param>
 /// <param name="encoder"></param>
 /// <returns></returns>
 public static string IntToStringFast(ulong value, BaseEncoder encoder)
 {
     return IntToStringFast(value, encoder.Characters);
 }
Example #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="encodedValue">The encoded string</param>
 /// <param name="encoder">The encoder used to encode this string</param>
 /// <returns>A converted integer</returns>
 public static ulong StringToIntFast(string encodedValue, BaseEncoder encoder)
 {
     return StringToIntFast(encodedValue, encoder.CharactersToValues);
 }