IsAscii() public method

public IsAscii ( int off, int l ) : bool
off int
l int
return bool
Ejemplo n.º 1
0
        public void StringTests()
        {
            string   test_ascii = "Hello simple test";
            MemBlock b          = MemBlock.Reference(System.Text.Encoding.UTF8.GetBytes(test_ascii));

            Assert.IsTrue(b.IsAscii(0, b.Length), "IsAscii");
            string test_unicode = "la\u00dfen";

            b = MemBlock.Reference(System.Text.Encoding.UTF8.GetBytes(test_unicode));
            Assert.IsFalse(b.IsAscii(0, b.Length), "Unicode not ascii");
        }
Ejemplo n.º 2
0
        public static string ReadString(MemBlock b, int offset, out int bytelength)
        {
            int null_idx   = b.IndexOf(0, offset);
            int raw_length = null_idx - offset;

            bytelength = raw_length + 1; //One for the null
            Encoding e;

            /*
             * Benchmarks of mono show this to be about twice as fast as just
             * using UTF8.  That really means UTF8 could be optimized in mono
             */
            if (b.IsAscii(offset, raw_length))
            {
                e = Encoding.ASCII;
            }
            else
            {
                e = Encoding.UTF8;
            }
            return(b.GetString(e, offset, raw_length));
        }
Ejemplo n.º 3
0
 public static string ReadString(MemBlock b, int offset, out int bytelength)
 {
   int null_idx = b.IndexOf(0, offset);
   int raw_length = null_idx - offset;
   bytelength = raw_length + 1; //One for the null
   Encoding e;
   /*
    * Benchmarks of mono show this to be about twice as fast as just
    * using UTF8.  That really means UTF8 could be optimized in mono
    */
   if( b.IsAscii(offset, raw_length) ) {
     e = Encoding.ASCII;
   } else {
     e = Encoding.UTF8;
   }
   return b.GetString(e, offset, raw_length);
 }