public void VisitConstant(Constant c) { if (!c.IsValid) { writer.Write("<invalid>"); return; } PrimitiveType t = c.DataType as PrimitiveType; if (t != null) { if (t.Domain == Domain.Boolean) { writer.Write(Convert.ToBoolean(c.GetValue()) ? "true" : "false"); } else { object v = c.GetValue(); writer.Write(FormatString(t, v), v); } return; } StringConstant s = c as StringConstant; if (s != null) { writer.Write("{0}{1}{0}", '"', s.GetValue()); } }
public virtual void VisitConstant(Constant c) { if (!c.IsValid) { writer.Write("<invalid>"); return; } var pt = c.DataType.ResolveAs <PrimitiveType>(); if (pt != null) { if (pt.Domain == Domain.Boolean) { writer.Write(Convert.ToBoolean(c.GetValue()) ? "true" : "false"); } else if (pt.Domain == Domain.Real) { string sr; if (pt.Size == 4) { sr = c.ToFloat().ToString("g", CultureInfo.InvariantCulture); } else { sr = c.ToReal64().ToString("g", CultureInfo.InvariantCulture); } if (sr.IndexOfAny(nosuffixRequired) < 0) { sr += ".0"; } if (pt.Size == 4) { sr += "F"; } writer.Write(sr); } else { object v = c.GetValue(); writer.Write(FormatString(pt, v), v); } return; } StringConstant s = c as StringConstant; if (s != null) { writer.Write("{0}{1}{0}", '"', s.GetValue()); } }
public virtual void VisitConstant(Constant c) { if (!c.IsValid) { writer.Write("<invalid>"); return; } var pt = c.DataType.ResolveAs <PrimitiveType>(); if (pt != null) { if (pt.Domain == Domain.Boolean) { writer.Write(Convert.ToBoolean(c.GetValue()) ? "true" : "false"); } else if (pt.Domain == Domain.Real) { string sr; if (pt.Size == 4) { sr = c.ToFloat().ToString("g", CultureInfo.InvariantCulture); } else { sr = c.ToReal64().ToString("g", CultureInfo.InvariantCulture); } if (sr.IndexOfAny(nosuffixRequired) < 0) { sr += ".0"; } if (pt.Size == 4) { sr += "F"; } writer.Write(sr); } else { object v = c.GetValue(); writer.Write(FormatString(pt, v), v); } return; } StringConstant s = c as StringConstant; if (s != null) { writer.Write('"'); foreach (var ch in (string)s.GetValue()) { switch (ch) { case '\0': writer.Write("\\0"); break; case '\a': writer.Write("\\a"); break; case '\b': writer.Write("\\b"); break; case '\f': writer.Write("\\f"); break; case '\n': writer.Write("\\n"); break; case '\r': writer.Write("\\r"); break; case '\t': writer.Write("\\t"); break; case '\v': writer.Write("\\v"); break; case '\"': writer.Write("\\\""); break; case '\\': writer.Write("\\\\"); break; default: // The awful hack allows us to reuse .NET encodings // while encoding the original untranslateable // code points into the Private use area. //$TODO: Clearly if the string was UTF8 or // UTF-16 to begin with, we want to preserve the // private use area points. if (0xE000 <= ch && ch <= 0xE100) { writer.Write("\\x{0:X2}", (ch - 0xE000)); } else if (0 <= ch && ch < ' ' || ch >= 0x7F) { writer.Write("\\x{0:X2}", (int)ch); } else { writer.Write(ch); } break; } } writer.Write('"'); } }
public virtual void VisitConstant(Constant c) { if (!c.IsValid) { writer.Write("<invalid>"); return; } var pt = c.DataType.ResolveAs <PrimitiveType>(); if (pt != null) { if (pt.Domain == Domain.Boolean) { writer.Write(Convert.ToBoolean(c.GetValue()) ? "true" : "false"); } else if (pt.Domain == Domain.Real) { string sr; if (pt.Size == 4) { sr = c.ToFloat().ToString("g", CultureInfo.InvariantCulture); } else { sr = c.ToReal64().ToString("g", CultureInfo.InvariantCulture); } if (sr.IndexOfAny(nosuffixRequired) < 0) { sr += ".0"; } if (pt.Size == 4) { sr += "F"; } writer.Write(sr); } else { object v = c.GetValue(); writer.Write(FormatString(pt, v), v); } return; } StringConstant s = c as StringConstant; if (s != null) { writer.Write('"'); foreach (var ch in (string)s.GetValue()) { switch (ch) { case '\0': writer.Write("\\0"); break; case '\a': writer.Write("\\a"); break; case '\b': writer.Write("\\b"); break; case '\f': writer.Write("\\f"); break; case '\n': writer.Write("\\n"); break; case '\r': writer.Write("\\r"); break; case '\t': writer.Write("\\t"); break; case '\v': writer.Write("\\v"); break; case '\"': writer.Write("\\\""); break; case '\\': writer.Write("\\\\"); break; default: //$REVIEW: these are ASCII codes. EBCDIC? if (0 <= ch && ch < ' ' || ch >= 0x7F) { writer.Write("\\x{0:X2}", (int)ch); } else { writer.Write(ch); } break; } } writer.Write('"'); } }