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"); }
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)); }
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); }