コード例 #1
0
        public static AskReplacementWriter Create(
            ContentDisplayStyle contentDisplayStyle,
            string input,
            ReplaceOptions replaceOptions,
            Lazy <TextWriter> lazyWriter,
            ContentWriterOptions options,
            MatchOutputInfo outputInfo)
        {
            switch (contentDisplayStyle)
            {
            case ContentDisplayStyle.Value:
            case ContentDisplayStyle.ValueDetail:
                return(new AskValueReplacementWriter(input, replaceOptions, lazyWriter, options, outputInfo));

            case ContentDisplayStyle.Line:
                return(new AskLineReplacementWriter(input, replaceOptions, lazyWriter, options));

            case ContentDisplayStyle.UnmatchedLines:
            case ContentDisplayStyle.AllLines:
                throw new InvalidOperationException();

            default:
                throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'.");
            }
        }
コード例 #2
0
ファイル: FindCommand`1.cs プロジェクト: fjsnogueira/Orang
        protected override void ExecuteResult(
            FileSystemFinderResult result,
            SearchContext context,
            ContentWriterOptions writerOptions,
            Match match,
            string input,
            Encoding encoding,
            string baseDirectoryPath  = null,
            ColumnWidths columnWidths = null)
        {
            string indent = GetPathIndent(baseDirectoryPath);

            if (!Options.OmitPath)
            {
                WritePath(context, result, baseDirectoryPath, indent, columnWidths);
            }

            if (ContentFilter.IsNegative)
            {
                WriteLineIf(!Options.OmitPath, Verbosity.Minimal);
            }
            else
            {
                WriteMatches(input, match, writerOptions, context);
            }

            AskToContinue(context, indent);
        }
コード例 #3
0
ファイル: ContentWriter.cs プロジェクト: Rynaret/Orang
        public static ContentWriter CreateReplace(
            ContentDisplayStyle contentDisplayStyle,
            string input,
            ReplaceOptions replaceOptions,
            ContentWriterOptions options,
            TextWriter?textWriter      = null,
            MatchOutputInfo?outputInfo = null)
        {
            switch (contentDisplayStyle)
            {
            case ContentDisplayStyle.Value:
            case ContentDisplayStyle.ValueDetail:
                return(new ValueReplacementWriter(input, replaceOptions, options, textWriter, outputInfo));

            case ContentDisplayStyle.Line:
                return(new LineReplacementWriter(input, replaceOptions, options, textWriter));

            case ContentDisplayStyle.AllLines:
                return(new AllLinesReplacementWriter(input, replaceOptions, options, textWriter));

            case ContentDisplayStyle.UnmatchedLines:
                throw new NotSupportedException($"Value '{contentDisplayStyle}' is not supported.");

            default:
                throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'.");
            }
        }
コード例 #4
0
        private void ExecuteInput(SearchContext context, string input)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            Match?match = ContentFilter !.Match(input);

            ContentWriterOptions writerOptions = CreateContentWriterOptions("");

            if (match != null)
            {
                WriteContent(
                    context,
                    match,
                    input,
                    writerOptions,
                    fileMatch: null,
                    baseDirectoryPath: null,
                    isPathDisplayed: false);
            }

            stopwatch.Stop();

            if (ShouldWriteSummary())
            {
                context.Telemetry.Elapsed = stopwatch.Elapsed;

                Verbosity verbosity = (Options.IncludeSummary) ? Verbosity.Quiet : Verbosity.Detailed;

                WriteLine(verbosity);
                WriteContentSummary(context.Telemetry, verbosity);
                WriteLine(verbosity);
            }
        }
コード例 #5
0
ファイル: ReplaceCommand.cs プロジェクト: atifaziz/Orang
        private void ProcessResult(
            FileSystemFinderResult result,
            SearchContext context,
            ContentWriterOptions writerOptions,
            string baseDirectoryPath = null)
        {
            string indent = GetPathIndent(baseDirectoryPath);

            Encoding encoding = Options.DefaultEncoding;

            string input = ReadFile(result.Path, baseDirectoryPath, ref encoding, context, indent);

            if (input == null)
            {
                return;
            }

            Match match = Options.ContentFilter.Match(input, context.CancellationToken);

            if (match == null)
            {
                return;
            }

            ExecuteOrAddResult(result, context, writerOptions, match, input, encoding, baseDirectoryPath);
        }
コード例 #6
0
        public static AskReplacementWriter Create(
            ContentDisplayStyle contentDisplayStyle,
            string input,
            IReplacer replacer,
            Lazy <TextWriter>?lazyWriter,
            ContentWriterOptions options,
            MatchOutputInfo?outputInfo,
            bool isInteractive,
            SpellcheckState?spellcheckState = null)
        {
            switch (contentDisplayStyle)
            {
            case ContentDisplayStyle.Value:
            case ContentDisplayStyle.ValueDetail:
                return(new AskValueReplacementWriter(
                           input,
                           replacer,
                           lazyWriter,
                           options,
                           outputInfo,
                           isInteractive,
                           spellcheckState));

            case ContentDisplayStyle.Line:
                return(new AskLineReplacementWriter(input, replacer, lazyWriter, options, isInteractive, spellcheckState));

            case ContentDisplayStyle.UnmatchedLines:
            case ContentDisplayStyle.AllLines:
                throw new InvalidOperationException();

            default:
                throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'.");
            }
        }
コード例 #7
0
 public EmptyContentWriter(
     string input,
     ContentWriterOptions options,
     IResultStorage resultStorage = null) : base(input, options)
 {
     ResultStorage = resultStorage;
 }
コード例 #8
0
 public ValueContentWriter(
     string input,
     ContentWriterOptions options = null,
     IResultStorage storage       = null,
     MatchOutputInfo outputInfo   = null) : this(input, ContentTextWriter.Default, options, storage, outputInfo)
 {
 }
コード例 #9
0
 public AskLineContentWriter(
     string input,
     ContentWriterOptions options,
     IResultStorage?storage = null) : base(input, options, storage)
 {
     Ask = true;
 }
コード例 #10
0
 public AllLinesContentWriter(
     string input,
     ContentTextWriter?writer,
     ContentWriterOptions options,
     IResultStorage?storage = null) : base(input, writer, options)
 {
     ResultStorage = storage;
 }
コード例 #11
0
 public AskLineReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter> lazyWriter,
     ContentWriterOptions options) : base(input, replaceOptions, lazyWriter, options)
 {
     MatchingLineCount = 0;
 }
コード例 #12
0
 public AskValueContentWriter(
     string input,
     ContentWriterOptions options = null,
     IResultStorage storage       = null,
     MatchOutputInfo outputInfo   = null) : base(input, options, storage, outputInfo)
 {
     Ask = true;
 }
コード例 #13
0
 public LineReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     ContentWriterOptions options = null,
     TextWriter textWriter        = null) : base(input, options)
 {
     ReplaceOptions = replaceOptions;
     _textWriter    = textWriter;
 }
コード例 #14
0
 public TextWriterContentWriter(
     string input,
     ReplaceOptions replaceOptions,
     TextWriter textWriter,
     ContentWriterOptions options) : base(input, options)
 {
     ReplaceOptions = replaceOptions;
     _textWriter    = textWriter;
 }
コード例 #15
0
 public AskLineReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter>?lazyWriter,
     ContentWriterOptions options,
     bool isInteractive) : base(input, replaceOptions, lazyWriter, options, isInteractive)
 {
     MatchingLineCount = 0;
 }
コード例 #16
0
 public AskValueReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter> lazyWriter,
     ContentWriterOptions options,
     MatchOutputInfo outputInfo) : base(input, replaceOptions, lazyWriter, options)
 {
     OutputInfo = outputInfo;
 }
コード例 #17
0
 public UnmatchedLineWriter(
     string input,
     ContentTextWriter?writer,
     ContentWriterOptions options,
     IResultStorage?storage = null) : base(input, writer, options)
 {
     ResultStorage     = storage;
     MatchingLineCount = 0;
 }
コード例 #18
0
 protected override void ExecuteMatchWithContentCore(
     FileMatch fileMatch,
     SearchContext context,
     ContentWriterOptions writerOptions,
     string?baseDirectoryPath  = null,
     ColumnWidths?columnWidths = null)
 {
     ExecuteMatchCore(fileMatch, context, baseDirectoryPath, columnWidths);
 }
コード例 #19
0
        protected override void ExecuteMatchWithContentCore(
            FileMatch fileMatch,
            SearchContext context,
            ContentWriterOptions writerOptions,
            string?baseDirectoryPath  = null,
            ColumnWidths?columnWidths = null)
        {
            List <Capture>?groups = null;

            try
            {
                groups = ListCache <Capture> .GetInstance();

                MaxReason maxReason = GetCaptures(
                    fileMatch.ContentMatch !,
                    writerOptions.GroupNumber,
                    context,
                    isPathDisplayed: false,
                    predicate: Options.ContentFilter !.Predicate,
                    captures: groups);

                List <ICapture>?captures = GetCaptures(groups, context.CancellationToken);

                using (IEnumerator <ICapture> en = (captures ?? groups.Select(f => (ICapture) new RegexCapture(f))).GetEnumerator())
                {
                    if (en.MoveNext())
                    {
                        if (SpellcheckState != null)
                        {
                            SpellcheckState.CurrentPath = fileMatch.Path;
                        }

                        ExecuteMatchWithContentCore(
                            en,
                            captures?.Count ?? groups.Count,
                            maxReason,
                            fileMatch,
                            context,
                            writerOptions,
                            baseDirectoryPath,
                            columnWidths);
                    }
                }
            }
            finally
            {
                if (groups != null)
                {
                    ListCache <Capture> .Free(groups);
                }

                if (SpellcheckState != null)
                {
                    SpellcheckState.CurrentPath = null;
                }
            }
        }
コード例 #20
0
 protected AskReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter> lazyWriter,
     ContentWriterOptions options) : base(input, options)
 {
     ReplaceOptions = replaceOptions;
     _lazyWriter    = lazyWriter;
 }
コード例 #21
0
 public LineContentWriter(
     string input,
     ContentTextWriter writer,
     ContentWriterOptions options = null,
     IResultStorage storage       = null) : base(input, writer, options)
 {
     ResultStorage     = storage;
     MatchingLineCount = 0;
 }
コード例 #22
0
 private ContentWriter CreateReplacementWriter(
     ContentDisplayStyle contentDisplayStyle,
     string input,
     IReplacer replacer,
     ContentWriterOptions options,
     TextWriter?textWriter      = null,
     MatchOutputInfo?outputInfo = null)
 {
     return(ContentWriter.CreateReplace(contentDisplayStyle, input, replacer, options, textWriter, outputInfo, SpellcheckState));
 }
コード例 #23
0
 public AskLineReplacementWriter(
     string input,
     IReplacer replacer,
     Lazy <TextWriter>?lazyWriter,
     ContentWriterOptions options,
     bool isInteractive,
     SpellcheckState?spellcheckState = null) : base(input, replacer, lazyWriter, options, isInteractive, spellcheckState)
 {
     MatchingLineCount = 0;
 }
コード例 #24
0
ファイル: ContentWriter.cs プロジェクト: Rynaret/Orang
 protected ContentWriter(
     string input,
     ContentTextWriter?writer,
     ContentWriterOptions options)
 {
     Input             = input;
     Options           = options;
     MatchingLineCount = -1;
     Writer            = writer;
 }
コード例 #25
0
 public ValueContentWriter(
     string input,
     ContentTextWriter writer,
     ContentWriterOptions options = null,
     IResultStorage storage       = null,
     MatchOutputInfo outputInfo   = null) : base(input, writer, options)
 {
     ResultStorage = storage;
     OutputInfo    = outputInfo;
 }
コード例 #26
0
 public ValueReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     ContentWriterOptions options,
     TextWriter?textWriter      = null,
     MatchOutputInfo?outputInfo = null) : base(input, options, outputInfo: outputInfo)
 {
     ReplaceOptions = replaceOptions;
     _textWriter    = textWriter;
 }
コード例 #27
0
 public AskValueReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter>?lazyWriter,
     ContentWriterOptions options,
     MatchOutputInfo?outputInfo,
     bool isInteractive) : base(input, replaceOptions, lazyWriter, options, isInteractive)
 {
     OutputInfo = outputInfo;
 }
コード例 #28
0
 public AskValueReplacementWriter(
     string input,
     IReplacer replacer,
     Lazy <TextWriter>?lazyWriter,
     ContentWriterOptions options,
     MatchOutputInfo?outputInfo,
     bool isInteractive,
     SpellcheckState?spellcheckState = null) : base(input, replacer, lazyWriter, options, isInteractive, spellcheckState)
 {
     OutputInfo = outputInfo;
 }
コード例 #29
0
 public LineReplacementWriter(
     string input,
     IReplacer replacer,
     ContentWriterOptions options,
     TextWriter?textWriter           = null,
     SpellcheckState?spellcheckState = null) : base(input, options)
 {
     Replacer        = replacer;
     _textWriter     = textWriter;
     SpellcheckState = spellcheckState;
 }
コード例 #30
0
 public ValueReplacementWriter(
     string input,
     IReplacer replacer,
     ContentWriterOptions options,
     TextWriter?textWriter           = null,
     MatchOutputInfo?outputInfo      = null,
     SpellcheckState?spellcheckState = null) : base(input, options, outputInfo: outputInfo)
 {
     Replacer        = replacer;
     _textWriter     = textWriter;
     SpellcheckState = spellcheckState;
 }