public override void WriteStringLiteral(string literal) { bool inQuotes = true; InnerWriter.Write("\""); for (int i = 0; i < literal.Length; i++) { switch (literal[i]) { case '\t': case '\n': case '\r': case '\0': case '\u2028': case '\u2029': // Exit quotes EnsureOutOfQuotes(ref inQuotes); // Write concat character InnerWriter.Write("&"); // Write character literal WriteCharLiteral(literal[i]); break; case '"': case '“': case '”': case (char)0xff02: EnsureInQuotes(ref inQuotes); InnerWriter.Write(literal[i]); InnerWriter.Write(literal[i]); break; default: EnsureInQuotes(ref inQuotes); InnerWriter.Write(literal[i]); break; } if (i > 0 && (i % 80) == 0) { if ( (Char.IsHighSurrogate(literal[i]) && (i < (literal.Length - 1))) && Char.IsLowSurrogate(literal[i + 1]) ) { InnerWriter.Write(literal[++i]); } if (inQuotes) { InnerWriter.Write("\""); } inQuotes = true; InnerWriter.Write("& _ "); InnerWriter.Write(Environment.NewLine); InnerWriter.Write('"'); } } EnsureOutOfQuotes(ref inQuotes); }
public void VisitImport(JImport node) { InnerWriter.Write("import "); Visit(node.Type); WriteSemicolon(); WriteLine(); }
/// <summary> /// Writes a midi event to stream. /// </summary> /// <param name="midiEvent">The midi event data.</param> /// <param name="deltaTime">A time indication of the midi event.</param> /// <param name="longData">Optional long message data. Can be null.</param> /// <remarks>Refer to the Win32 MIDIEVNT structure for more information.</remarks> public void WriteEvent(int midiEvent, int deltaTime, byte[] longData) { ThrowIfDisposed(); if (!CanWriteLong(longData)) { throw new MidiStreamException(Properties.Resources.MidiStream_EndOfStream); } InnerWriter.Write(deltaTime); InnerWriter.Write(0); // streamID InnerWriter.Write(midiEvent); if (longData != null) { InnerWriter.Write(longData, 0, longData.Length); // DWORD aligned records. long length = longData.Length; int rest = (int)(length % 4); for (int i = 0; i < rest; i++) { InnerWriter.Write((byte)0); } } // add to bytes recorded. BaseStream.BytesRecorded += GetMessageSize(longData); }
private void EnsureInQuotes(ref bool inQuotes) { if (!inQuotes) { InnerWriter.Write("&\""); inQuotes = true; } }
private void EnsureOutOfQuotes(ref bool inQuotes) { if (inQuotes) { InnerWriter.Write("\""); inQuotes = false; } }
public override void WriteHelperHeaderPrefix(string templateTypeName, bool isStatic) { InnerWriter.Write("Public "); if (isStatic) { InnerWriter.Write("Shared "); } InnerWriter.Write("Function "); }
public override void WriteHelperHeaderPrefix(string templateTypeName, bool isStatic) { InnerWriter.Write("public "); if (isStatic) { InnerWriter.Write("static "); } InnerWriter.Write(templateTypeName); InnerWriter.Write(" "); }
public override void WriteObjectStart(string name) { if (WritingFormat == WritingFormat.Indented) { InnerWriter.WriteLine($"{StgFormat.OBJECT_START} {name} {StgFormat.OBJECT_TAG_START} "); } else { InnerWriter.Write($"{StgFormat.OBJECT_START} {name} {StgFormat.OBJECT_TAG_START} "); } }
public override void WriteObjectEnd() { if (WritingFormat == WritingFormat.Indented) { InnerWriter.WriteLine($"{StgFormat.OBJECT_TAG_END} "); } else { InnerWriter.Write($"{StgFormat.OBJECT_TAG_END} "); } }
public override void WriteComment(string comment) { if (WritingFormat == WritingFormat.Indented) { InnerWriter.WriteLine($"{StgFormat.COMMENT_FORMAT_START} {comment} {StgFormat.COMMENT_FORMAT_END} "); } else { InnerWriter.Write($"{StgFormat.COMMENT_FORMAT_START} {comment} {StgFormat.COMMENT_FORMAT_END} "); } }
protected internal void WriteCommaSeparatedList <T>(T[] items, Action <T> writeItemAction) { for (int i = 0; i < items.Length; i++) { if (i > 0) { InnerWriter.Write(", "); } writeItemAction(items[i]); } }
protected internal override void EmitStartConstructor(string typeName) { if (typeName == null) { throw new ArgumentNullException("typeName"); } InnerWriter.Write("new "); InnerWriter.Write(typeName); InnerWriter.Write("("); }
protected override void CoreWrite(char c) { if (IsDelayed) { _buf.Append(c); } else { InnerWriter.Write(c); } }
public override void WriteStgStart() { if (WritingFormat == WritingFormat.Indented) { InnerWriter.WriteLine($"{StgFormat.STG_START} "); } else { InnerWriter.Write($"{StgFormat.STG_START} "); } }
protected override void BeforeWrite(object o, Type t) { if (TabsPending) { for (var i = 0; i < Indent; i++) { InnerWriter.Write(TabString); } TabsPending = false; } }
public override void WriteStgEnd() { if (WritingFormat == WritingFormat.Indented) { InnerWriter.WriteLine(StgFormat.STG_END); } else { InnerWriter.Write(StgFormat.STG_END); } Dispose(); }
protected virtual void OutputTabs() { if (!_tabsPending) { return; } for (int index = 0; index < _indentLevel; index++) { InnerWriter.Write(TabString); } _tabsPending = false; }
public void SupressLineBreak(Action action) { //Debugger.Break(); if (sbSupressLineBreak != null) { action(); return; } sbSupressLineBreak = new StringBuilder(); action(); InnerWriter.Write(sbSupressLineBreak.ToString()); sbSupressLineBreak = null; }
public override void WriteString(string name, string value) { if (value != null) { if (WritingFormat == WritingFormat.Indented) { InnerWriter.WriteLine($"{StgFormat.STRING_START} {name} {StgFormat.EQUALS_TO} {StgFormat.STRING_FORMAT}{value}{StgFormat.STRING_FORMAT}{StgFormat.FIELD_END} "); } else { InnerWriter.Write($"{StgFormat.STRING_START} {name} {StgFormat.EQUALS_TO} {StgFormat.STRING_FORMAT}{value}{StgFormat.STRING_FORMAT}{StgFormat.FIELD_END} "); } } }
public override void Write(string value) { try { InstallConsole console; if (Console.TryGetTarget(out console)) { console.Write(value); } } finally { InnerWriter.Write(value); } }
public override void WriteLinePragma(int?lineNumber, string fileName) { InnerWriter.WriteLine(); if (lineNumber != null) { InnerWriter.Write("#ExternalSource(\""); InnerWriter.Write(fileName); InnerWriter.Write("\", "); InnerWriter.Write(lineNumber); InnerWriter.WriteLine(")"); } else { InnerWriter.WriteLine("#End ExternalSource"); } }
public override int WriteVariableDeclaration(string type, string name, string value) { InnerWriter.Write(type); InnerWriter.Write(" "); InnerWriter.Write(name); if (!String.IsNullOrEmpty(value)) { InnerWriter.Write(" = "); InnerWriter.Write(value); } else { InnerWriter.Write(" = null"); } return(0); }
private void WriteVerbatimStringLiteral(string literal) { // From CSharpCodeGenerator.QuoteSnippetStringVerbatim in CodeDOM InnerWriter.Write("@\""); for (int i = 0; i < literal.Length; i++) { if (literal[i] == '\"') { InnerWriter.Write("\"\""); } else { InnerWriter.Write(literal[i]); } } InnerWriter.Write("\""); }
public override void WriteLinePragma(int?lineNumber, string fileName) { InnerWriter.WriteLine(); if (lineNumber != null) { InnerWriter.Write("#line "); InnerWriter.Write(lineNumber); InnerWriter.Write(" \""); InnerWriter.Write(fileName); InnerWriter.Write("\""); InnerWriter.WriteLine(); } else { InnerWriter.WriteLine("#line default"); InnerWriter.WriteLine("#line hidden"); } }
protected internal override void EmitStartLambdaExpression(string[] parameterNames) { if (parameterNames == null) { throw new ArgumentNullException("parameterNames"); } if (parameterNames.Length == 0 || parameterNames.Length > 1) { InnerWriter.Write("("); } WriteCommaSeparatedList(parameterNames, InnerWriter.Write); if (parameterNames.Length == 0 || parameterNames.Length > 1) { InnerWriter.Write(")"); } InnerWriter.Write(" => "); }
protected internal override void EmitStartMethodInvoke(string methodName, params string[] genericArguments) { InnerWriter.Write(methodName); if (genericArguments != null && genericArguments.Length > 0) { WriteStartGenerics(); for (int i = 0; i < genericArguments.Length; i++) { if (i > 0) { WriteParameterSeparator(); } WriteSnippet(genericArguments[i]); } WriteEndGenerics(); } InnerWriter.Write("("); }
public override int WriteVariableDeclaration(string type, string name, string value) { InnerWriter.Write("Dim "); InnerWriter.Write(name); InnerWriter.Write(" As "); int typePos = InnerWriter.GetStringBuilder().Length; InnerWriter.Write(type); if (!String.IsNullOrEmpty(value)) { InnerWriter.Write(" = "); InnerWriter.Write(value); } else { InnerWriter.Write(" = Nothing"); } return(typePos); }
void FlushCurrentLineBuffer(bool newLine = true) { var s = CurrentLineBuffer.ToString(); if (s.Contains(NewLine) || s.Contains("\n")) { var lines = s.Split(new string[] { NewLine, "\n" }, StringSplitOptions.None); var i = 0; foreach (var line in lines) { if (!newLine && lines.Length - 1 == i) { InnerWriter.Write(line); } else { InnerWriter.WriteLine(line); CurrentLine++; } i++; } } else { if (!newLine) { InnerWriter.Write(s); } else { InnerWriter.WriteLine(s); CurrentLine++; } } CurrentLineBuffer.Clear(); if (newLine) { AppendTabs(); } }
public override void WriteArray(string name, Array values) { if (values != null) { InnerWriter.Write($"{StgFormat.ARRAY_START} {name} {StgFormat.EQUALS_TO} {StgFormat.ARRAY_TAG_START} "); string bracket = GetBracketType(values); List <string> arr = new List <string>(values.Length); foreach (var item in values) { if (values.GetType().GetElementType() == typeof(double)) { arr.Add((string)Convert.ChangeType(item, typeof(string), CultureInfo.CreateSpecificCulture("en-US"))); } else { arr.Add((string)Convert.ChangeType(item, typeof(string), CultureInfo.CurrentCulture)); } } for (int i = 0; i < arr.Count; i++) { if (i == arr.Count - 1) { InnerWriter.Write($"{bracket}{arr[i]}{bracket}"); } else { InnerWriter.Write($"{bracket}{arr[i]}{bracket}, "); } } if (WritingFormat == WritingFormat.Indented) { InnerWriter.WriteLine($" {StgFormat.ARRAY_TAG_END}{StgFormat.FIELD_END} "); } else { InnerWriter.Write($" {StgFormat.ARRAY_TAG_END}{StgFormat.FIELD_END} "); } } }
public override void WriteValueType(string name, ValueType value) { if (!HasDefaultValue(value)) { string bracket = GetBracketType(value); if (WritingFormat == WritingFormat.Indented) { if (value is double) { InnerWriter.WriteLine($"{StgFormat.VARIABLES_START} {name} {StgFormat.EQUALS_TO} {bracket}{(string)Convert.ChangeType(value, typeof(string), CultureInfo.CreateSpecificCulture("en-US"))}{bracket}{StgFormat.FIELD_END} "); } else { InnerWriter.WriteLine($"{StgFormat.VARIABLES_START} {name} {StgFormat.EQUALS_TO} {bracket}{(string)Convert.ChangeType(value, typeof(string), CultureInfo.CurrentCulture)}{bracket}{StgFormat.FIELD_END} "); } } else { InnerWriter.Write($"{StgFormat.VARIABLES_START} {name} {StgFormat.EQUALS_TO} {bracket}{(string)Convert.ChangeType(value, typeof(string), CultureInfo.CurrentCulture)}{bracket}{StgFormat.FIELD_END} "); } } }