Ejemplo n.º 1
0
        private static string NormalizeNewLinesInWhitespace(string original, FormatContext context, int minimumNewLines, Func <String> noNewLinesProcessor)
        {
            int nNewLines = 0;
            int idx       = original.IndexOf(Environment.NewLine, StringComparison.OrdinalIgnoreCase);

            while (idx > -1)
            {
                ++nNewLines;
                idx = original.IndexOf(Environment.NewLine, idx + 1, StringComparison.OrdinalIgnoreCase);
            }

            StringBuilder sb = new StringBuilder();

            nNewLines = Math.Max(minimumNewLines, nNewLines);
            for (int i = 0; i < nNewLines; i++)
            {
                sb.Append(Environment.NewLine);
            }
            sb.Append(context.GetIndentString());

            if (nNewLines > 0)
            {
                return(sb.ToString());
            }
            else
            {
                return(noNewLinesProcessor());
            }
        }
        private void DoFormat(string input, FormatOptions options, bool verifyOutput, Action <FormatterVisitor> postFormatAction)
        {
            Validate.IsNotNull(nameof(input), input);
            Validate.IsNotNull(nameof(options), options);

            ParseResult   result  = Parser.Parse(input);
            FormatContext context = new FormatContext(result.Script, options);

            FormatterVisitor visitor = new FormatterVisitor(context, ServiceProvider);

            result.Script.Accept(visitor);
            if (verifyOutput)
            {
                visitor.VerifyFormat();
            }

            postFormatAction?.Invoke(visitor);
        }
Ejemplo n.º 3
0
 internal static string NormalizeNewLinesOrCondenseToOneSpace(string original, FormatContext context)
 {
     return(NormalizeNewLinesOrCondenseToNSpaces(original, context, 1));
 }
Ejemplo n.º 4
0
 internal static string NormalizeNewLinesOrCondenseToNSpaces(string original, FormatContext context, int nSpaces)
 {
     return(NormalizeNewLinesInWhitespace(original, context, 0, () => { return new String(' ', nSpaces); }));
 }
Ejemplo n.º 5
0
 internal static string NormalizeNewLinesEnsureOneNewLineMinimum(string original, FormatContext context)
 {
     return(NormalizeNewLinesInWhitespace(original, context, 1));
 }
Ejemplo n.º 6
0
 private static string NormalizeNewLinesInWhitespace(string original, FormatContext context, int minimumNewLines)
 {
     return(NormalizeNewLinesInWhitespace(original, context, 1, () => { return original; }));
 }
Ejemplo n.º 7
0
 internal static string NormalizeToOneSpace(string original, FormatContext context)
 {
     return(" ");
 }
Ejemplo n.º 8
0
 internal static string NormalizeNewLinesInWhitespace(string original, FormatContext context)
 {
     return(NormalizeNewLinesInWhitespace(original, context, 0));
 }
Ejemplo n.º 9
0
 internal static string StripAllWhitespace(string original, FormatContext context)
 {
     return(String.Empty);
 }
Ejemplo n.º 10
0
 public FormatterVisitor(FormatContext context, IMultiServiceProvider serviceProvider)
     : base()
 {
     Context = context;
     this.serviceProvider = serviceProvider;
 }
 internal override string FormatWhitespace(string original, FormatContext context)
 {
     return(FormatterUtilities.NormalizeNewLinesEnsureOneNewLineMinimum(original, context));
 }
 internal override string FormatWhitespace(string original, FormatContext context)
 {
     return(FormatterUtilities.NormalizeNewLinesOrCondenseToOneSpace(original, context));
 }
 internal abstract string FormatWhitespace(string original, FormatContext context);