static private EscapeText ( string input ) : string | ||
input | string | |
리턴 | string |
public void Escape() { // Escape sequences. Assert.AreEqual("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"", TextFormat.EscapeBytes(Bytes("\0\u0001\u0007\b\f\n\r\t\v\\\'\""))); Assert.AreEqual("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"", TextFormat.EscapeText("\0\u0001\u0007\b\f\n\r\t\v\\\'\"")); Assert.AreEqual(Bytes("\0\u0001\u0007\b\f\n\r\t\v\\\'\""), TextFormat.UnescapeBytes("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"")); Assert.AreEqual("\0\u0001\u0007\b\f\n\r\t\v\\\'\"", TextFormat.UnescapeText("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"")); // Unicode handling. Assert.AreEqual("\\341\\210\\264", TextFormat.EscapeText("\u1234")); Assert.AreEqual("\\341\\210\\264", TextFormat.EscapeBytes(Bytes(0xe1, 0x88, 0xb4))); Assert.AreEqual("\u1234", TextFormat.UnescapeText("\\341\\210\\264")); Assert.AreEqual(Bytes(0xe1, 0x88, 0xb4), TextFormat.UnescapeBytes("\\341\\210\\264")); Assert.AreEqual("\u1234", TextFormat.UnescapeText("\\xe1\\x88\\xb4")); Assert.AreEqual(Bytes(0xe1, 0x88, 0xb4), TextFormat.UnescapeBytes("\\xe1\\x88\\xb4")); // Errors. AssertFormatException(() => TextFormat.UnescapeText("\\x")); AssertFormatException(() => TextFormat.UnescapeText("\\z")); AssertFormatException(() => TextFormat.UnescapeText("\\")); }
public void WriteArray(FieldType fieldType, int fieldNumber, string fieldName, IEnumerable list) { output.WriteLine("{0}: [", fieldName); output.Indent(); int objcount = 0; foreach (object element in list) { if (objcount != 0) { output.Write(" "); } switch (fieldType) { case FieldType.String: output.WriteLine("\"{0}\"", TextFormat.EscapeText((string)element)); break; case FieldType.Bytes: output.WriteLine("\"{0}\"", TextFormat.EscapeBytes((ByteString)element)); break; case FieldType.Message: output.WriteLine("{"); output.Indent(); ((IMessageLite)element).WriteTo(this); output.Outdent(); output.WriteLine("}"); break; case FieldType.Group: output.WriteLine("{"); output.Indent(); ((IMessageLite)element).WriteTo(this); output.Outdent(); output.WriteLine("}"); break; default: output.Write("{0}", element); if (++objcount > 10) { objcount = 0; output.WriteLine(""); } break; } } if (objcount != 0) { output.WriteLine(""); } output.Outdent(); output.WriteLine("]"); }
/// <summary> /// Writes a string field value, including tag, to the stream. /// </summary> public void WriteString(int fieldNumber, string fieldName, string value) { output.WriteLine("{0}: \"{1}\"", fieldName, TextFormat.EscapeText(value)); }