Esempio n. 1
0
 private static void TEst()
 {
   var encoding = new CustomEncoding(); // Encoding.GetEncoding(1252);
   //get characters for the byte - should be only one
   char[] charsForByte = encoding.GetChars(new[] { (byte)128 });
   string s = encoding.GetString(new[] {(byte) 128});
   
   //this will blow if we got more than one character
   char character = charsForByte.Single();
   Console.Out.WriteLine("character = {0}", character);
   Console.Out.WriteLine("character = {0}", (char)character);
   Console.ReadLine();
 }
Esempio n. 2
0
    static void Main(string[] args)
    {
      TEst();

      var encoding = Encoding.GetEncoding("iso-8859-1");
      var copy = new CustomEncoding();
      Verification.Compare(copy, encoding, CustomEncoding.CharacterCount);

     
      var bytes = copy.GetBytes(new[] {'a', 'x', 'b'});



      char[] chars = new char[256];
      char[] chars2 = new char[256];

      for (int i = 0; i < 256; i++)
      {
        var singleChar = encoding.GetChars(new[] {(byte)i});
        if(singleChar.Length != 1) throw new InvalidOperationException();
        chars[i] = singleChar[0];

        chars2[i] = copy.GetChars(new[] {(byte)i})[0];
      }

      Console.Out.WriteLine("encoding = {0}", encoding.GetMaxByteCount(256));
      Console.Out.WriteLine("encoding = {0}", encoding.GetMaxCharCount(256));


      StringBuilder builder = new StringBuilder();
      for (int i  = 0; i < chars.Length; i++)
      {
        var c = chars[i];
        builder.Append(c);
        Console.Out.Write(c);
        Console.Out.Write(chars2[i]);
        Console.Out.Write("\n");
      }


      string s = builder.ToString();
      Console.Out.WriteLine("s.Length = {0}", s.Length);
      byte[] a = encoding.GetBytes(s);
      byte[] b = copy.GetBytes(s);

      Stopwatch w = new Stopwatch();
      w.Start();
      for (int i = 0; i < 10000; i++)
      {
        encoding.GetBytes(s);
      }
      w.Stop();
      Console.Out.WriteLine("TOTAL: " + w.ElapsedMilliseconds);

      w = new Stopwatch();
      w.Start();
      for (int i = 0; i < 10000; i++)
      {
        encoding.GetString(a);
      }
      w.Stop();
      Console.Out.WriteLine("TOTAL: " + w.ElapsedMilliseconds);


      w = new Stopwatch();
      w.Start();
      for (int i = 0; i < 10000; i++)
      {
        copy.GetBytes(s);
      }
      w.Stop();
      Console.Out.WriteLine("TOTAL: " + w.ElapsedMilliseconds);

      w = new Stopwatch();
      w.Start();
      for (int i = 0; i < 10000; i++)
      {
        copy.GetString(a);
      }
      w.Stop();
      Console.Out.WriteLine("TOTAL: " + w.ElapsedMilliseconds);

      return;


      Debug.Assert(a.Length == b.Length, "Not the same length: " + a.Length + "," + b.Length);
      for (int i = 0; i < a.Length; i++)
      {
        byte ba = a[i];
        byte bb = b[i];
        Console.Out.WriteLine("ba, bb = {0}, {1}", ba, bb);
        Debug.Assert(ba == bb, "Difference at index " + i + " " + ba + "," + bb);
      }


      Console.ReadLine();
    }
Esempio n. 3
0
 public void Init()
 {
     myEncoding        = new CustomEncoding();
     referenceEncoding = Encoding.GetEncoding(28591);
 }
Esempio n. 4
0
 public void Init()
 {
   myEncoding = new CustomEncoding();
   referenceEncoding = Encoding.GetEncoding(myEncoding.WebName);
 }
Esempio n. 5
0
 public void Init()
 {
   myEncoding = new CustomEncoding();
   referenceEncoding = Encoding.GetEncoding(28591);
 }