public void TestGetUtf8ByteCount() { Byte[] encoded = new Byte[16]; //Char[] chars = new Char[] { '"', '\\', 'u', 'x', 'x', 'x', 'x', '"' }; //String hexMap = "0123456789ABCDEF"; for (int i = 0; i < 1; i++) { //chars[3] = hexMap[i]; for (int j = 0; j < 16; j++) { //chars[4] = hexMap[j]; for (int k = 0; k < 16; k++) { //chars[5] = hexMap[k]; for (int l = 0; l < 16; l++) { //chars[6] = hexMap[l]; Char unicodeChar = (Char)( (i << 12) | (j << 8) | (k << 4) | l); Assert.AreEqual(Encoding.UTF8.GetByteCount(new Char[] { unicodeChar }), Utf8.GetCharEncodeLength(unicodeChar)); UInt32 length = Utf8.EncodeChar(unicodeChar, encoded, 0); String decoded = Encoding.UTF8.GetString(encoded, 0, (Int32)length); Assert.AreEqual(unicodeChar, decoded[0]); //Console.WriteLine("Decoded = '{0}'", decoded); //Assert.AreEqual((Byte)((i << 4) | j), encoded } } } } }
// The caller is guaranteeing that every char in str is between 0 and 127 (inclusive) //public void AppendFormatAscii(String format, params Object[] obj) //{ // String.Format( // builder.AppendFormat(format, obj); //} public void AppendUtf8(Char c) { EnsureTotalCapacity(contentLength + Utf8.MaxCharEncodeLength); contentLength = Utf8.EncodeChar(c, bytes, contentLength); }