예제 #1
0
        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);
        }
예제 #2
0
 public void VisitImport(JImport node)
 {
     InnerWriter.Write("import ");
     Visit(node.Type);
     WriteSemicolon();
     WriteLine();
 }
예제 #3
0
        /// <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);
        }
예제 #4
0
 private void EnsureInQuotes(ref bool inQuotes)
 {
     if (!inQuotes)
     {
         InnerWriter.Write("&\"");
         inQuotes = true;
     }
 }
예제 #5
0
 private void EnsureOutOfQuotes(ref bool inQuotes)
 {
     if (inQuotes)
     {
         InnerWriter.Write("\"");
         inQuotes = false;
     }
 }
예제 #6
0
 public override void WriteHelperHeaderPrefix(string templateTypeName, bool isStatic)
 {
     InnerWriter.Write("Public ");
     if (isStatic)
     {
         InnerWriter.Write("Shared ");
     }
     InnerWriter.Write("Function ");
 }
예제 #7
0
 public override void WriteHelperHeaderPrefix(string templateTypeName, bool isStatic)
 {
     InnerWriter.Write("public ");
     if (isStatic)
     {
         InnerWriter.Write("static ");
     }
     InnerWriter.Write(templateTypeName);
     InnerWriter.Write(" ");
 }
예제 #8
0
 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} ");
     }
 }
예제 #9
0
 public override void WriteObjectEnd()
 {
     if (WritingFormat == WritingFormat.Indented)
     {
         InnerWriter.WriteLine($"{StgFormat.OBJECT_TAG_END} ");
     }
     else
     {
         InnerWriter.Write($"{StgFormat.OBJECT_TAG_END} ");
     }
 }
예제 #10
0
 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} ");
     }
 }
예제 #11
0
 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]);
     }
 }
예제 #12
0
        protected internal override void EmitStartConstructor(string typeName)
        {
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            InnerWriter.Write("new ");
            InnerWriter.Write(typeName);
            InnerWriter.Write("(");
        }
예제 #13
0
 protected override void CoreWrite(char c)
 {
     if (IsDelayed)
     {
         _buf.Append(c);
     }
     else
     {
         InnerWriter.Write(c);
     }
 }
예제 #14
0
 public override void WriteStgStart()
 {
     if (WritingFormat == WritingFormat.Indented)
     {
         InnerWriter.WriteLine($"{StgFormat.STG_START} ");
     }
     else
     {
         InnerWriter.Write($"{StgFormat.STG_START} ");
     }
 }
예제 #15
0
        protected override void BeforeWrite(object o, Type t)
        {
            if (TabsPending)
            {
                for (var i = 0; i < Indent; i++)
                {
                    InnerWriter.Write(TabString);
                }

                TabsPending = false;
            }
        }
예제 #16
0
 public override void WriteStgEnd()
 {
     if (WritingFormat == WritingFormat.Indented)
     {
         InnerWriter.WriteLine(StgFormat.STG_END);
     }
     else
     {
         InnerWriter.Write(StgFormat.STG_END);
     }
     Dispose();
 }
예제 #17
0
        protected virtual void OutputTabs()
        {
            if (!_tabsPending)
            {
                return;
            }

            for (int index = 0; index < _indentLevel; index++)
            {
                InnerWriter.Write(TabString);
            }

            _tabsPending = false;
        }
예제 #18
0
        public void SupressLineBreak(Action action)
        {
            //Debugger.Break();
            if (sbSupressLineBreak != null)
            {
                action();
                return;
            }

            sbSupressLineBreak = new StringBuilder();
            action();
            InnerWriter.Write(sbSupressLineBreak.ToString());
            sbSupressLineBreak = null;
        }
예제 #19
0
 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} ");
         }
     }
 }
예제 #20
0
 public override void Write(string value)
 {
     try
     {
         InstallConsole console;
         if (Console.TryGetTarget(out console))
         {
             console.Write(value);
         }
     }
     finally
     {
         InnerWriter.Write(value);
     }
 }
예제 #21
0
 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");
     }
 }
예제 #22
0
 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);
 }
예제 #23
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("\"");
 }
예제 #24
0
 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");
     }
 }
예제 #25
0
        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(" => ");
        }
예제 #26
0
        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("(");
        }
예제 #27
0
        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);
        }
예제 #28
0
        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();
            }
        }
예제 #29
0
 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} ");
         }
     }
 }
예제 #30
0
 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} ");
         }
     }
 }