private static void printIdentityFacetOperation(System.IO.StringWriter s, Ice.InputStream str) { try { Ice.ToStringMode toStringMode = Ice.ToStringMode.Unicode; if (str.instance() != null) { toStringMode = str.instance().toStringMode(); } Ice.Identity identity = new Ice.Identity(); identity.ice_readMembers(str); s.Write("\nidentity = " + Ice.Util.identityToString(identity, toStringMode)); string[] facet = str.readStringSeq(); s.Write("\nfacet = "); if (facet.Length > 0) { s.Write(IceUtilInternal.StringUtil.escapeString(facet[0], "", toStringMode)); } string operation = str.readString(); s.Write("\noperation = " + operation); } catch (System.IO.IOException) { Debug.Assert(false); } }
private void warning(Exception ex) { Debug.Assert(_instance != null); using (StringWriter sw = new StringWriter(CultureInfo.CurrentCulture)) { IceUtilInternal.OutputBase output = new IceUtilInternal.OutputBase(sw); Ice.ToStringMode toStringMode = _instance.toStringMode(); output.setUseTab(false); output.print("dispatch exception:"); output.print("\nidentity: " + Ice.Util.identityToString(_current.id, toStringMode)); output.print("\nfacet: " + IceUtilInternal.StringUtil.escapeString(_current.facet, "", toStringMode)); output.print("\noperation: " + _current.operation); if (_current.con != null) { try { for (Ice.ConnectionInfo p = _current.con.getInfo(); p != null; p = p.underlying) { Ice.IPConnectionInfo ipinfo = p as Ice.IPConnectionInfo; output.print("\nremote host: " + ipinfo.remoteAddress + " remote port: " + ipinfo.remotePort); } } catch (Ice.LocalException) { } } output.print("\n"); output.print(ex.ToString()); _instance.initializationData().logger.warning(sw.ToString()); } }
private static void PrintIdentityFacetOperation(System.IO.StringWriter s, Ice.InputStream str) { try { Ice.ToStringMode toStringMode = str.Communicator.ToStringMode; var identity = new Ice.Identity(str); s.Write("\nidentity = " + identity.ToString(toStringMode)); string[] facet = str.ReadStringArray(); s.Write("\nfacet = "); if (facet.Length > 0) { s.Write(IceUtilInternal.StringUtil.EscapeString(facet[0], "", toStringMode)); } string operation = str.ReadString(); s.Write("\noperation = " + operation); } catch (System.IO.IOException) { Debug.Assert(false); } }
encodeChar(char c, StringBuilder sb, string special, Ice.ToStringMode toStringMode) { switch (c) { case '\\': { sb.Append("\\\\"); break; } case '\'': { sb.Append("\\'"); break; } case '"': { sb.Append("\\\""); break; } case '\a': { if (toStringMode == Ice.ToStringMode.Compat) { // Octal escape for compatibility with 3.6 and earlier sb.Append("\\007"); } else { sb.Append("\\a"); } break; } case '\b': { sb.Append("\\b"); break; } case '\f': { sb.Append("\\f"); break; } case '\n': { sb.Append("\\n"); break; } case '\r': { sb.Append("\\r"); break; } case '\t': { sb.Append("\\t"); break; } case '\v': { if (toStringMode == Ice.ToStringMode.Compat) { // Octal escape for compatibility with 3.6 and earlier sb.Append("\\013"); } else { sb.Append("\\v"); } break; } default: { if (special != null && special.IndexOf(c) != -1) { sb.Append('\\'); sb.Append(c); } else { int i = (int)c; if (i < 32 || i > 126) { if (toStringMode == Ice.ToStringMode.Compat) { // // When ToStringMode=Compat, c is a UTF-8 byte // Debug.Assert(i < 256); sb.Append('\\'); string octal = System.Convert.ToString(i, 8); // // Add leading zeroes so that we avoid problems during // decoding. For example, consider the encoded string // \0013 (i.e., a character with value 1 followed by // the character '3'). If the leading zeroes were omitted, // the result would be incorrectly interpreted by the // decoder as a single character with value 11. // for (int j = octal.Length; j < 3; j++) { sb.Append('0'); } sb.Append(octal); } else if (i < 32 || i == 127 || toStringMode == Ice.ToStringMode.ASCII) { // append \\unnnn sb.Append("\\u"); string hex = System.Convert.ToString(i, 16); for (int j = hex.Length; j < 4; j++) { sb.Append('0'); } sb.Append(hex); } else { // keep as is sb.Append(c); } } else { // printable ASCII character sb.Append(c); } } break; } } }
// // Add escape sequences (such as "\n", or "\007") to the input string // public static string escapeString(string s, string special, Ice.ToStringMode toStringMode) { if (special != null) { for (int i = 0; i < special.Length; ++i) { if (special[i] < 32 || special[i] > 126) { throw new System.ArgumentException("special characters must be in ASCII range 32-126", "special"); } } } if (toStringMode == Ice.ToStringMode.Compat) { // Encode UTF-8 bytes UTF8Encoding utf8 = new UTF8Encoding(); byte[] bytes = utf8.GetBytes(s); StringBuilder result = new StringBuilder(bytes.Length); for (int i = 0; i < bytes.Length; i++) { encodeChar((char)bytes[i], result, special, toStringMode); } return(result.ToString()); } else { StringBuilder result = new StringBuilder(s.Length); for (int i = 0; i < s.Length; i++) { char c = s[i]; if (toStringMode == Ice.ToStringMode.Unicode || !char.IsSurrogate(c)) { encodeChar(c, result, special, toStringMode); } else { Debug.Assert(toStringMode == Ice.ToStringMode.ASCII && char.IsSurrogate(c)); if (i + 1 == s.Length) { throw new System.ArgumentException("High surrogate without low surrogate"); } else { i++; int codePoint = char.ConvertToUtf32(c, s[i]); // append \Unnnnnnnn result.Append("\\U"); string hex = System.Convert.ToString(codePoint, 16); for (int j = hex.Length; j < 8; j++) { result.Append('0'); } result.Append(hex); } } } return(result.ToString()); } }