示例#1
0
        private static int Spellcheck(SpellcheckCommandLineOptions commandLineOptions)
        {
            var options = new SpellcheckCommandOptions();

            if (!commandLineOptions.TryParse(options))
            {
                return(ExitCodes.Error);
            }

            return(Execute(new SpellcheckCommand(options), commandLineOptions));
        }
示例#2
0
        public bool TryParse(SpellcheckCommandOptions options)
        {
            var baseOptions = (CommonReplaceCommandOptions)options;

            if (!TryParse(baseOptions))
            {
                return(false);
            }

            options = (SpellcheckCommandOptions)baseOptions;

            Regex?wordRegex = null;

            if (!TryEnsureFullPath(Words, out ImmutableArray <string> wordListPaths))
            {
                return(false);
            }
#if DEBUG
            if (Word.Any())
            {
                if (!FilterParser.TryParse(
                        Word,
                        OptionNames.Word,
                        OptionValueProviders.PatternOptions_Word_Provider,
                        out Filter? wordFilter))
                {
                    return(false);
                }

                wordRegex = wordFilter !.Regex;
            }
#endif
            WordListLoaderResult result = WordListLoader.Load(
                wordListPaths,
                minWordLength: MinWordLength,
                (CaseSensitive) ? WordListLoadOptions.None : WordListLoadOptions.IgnoreCase);

            var data = new SpellingData(result.List, result.CaseSensitiveList, result.FixList);

            var spellcheckerOptions = new SpellcheckerOptions(
                SplitMode.CaseAndHyphen,
                MinWordLength);

            var spellchecker = new Spellchecker(data, wordRegex, spellcheckerOptions);

            options.Replacer = new SpellcheckState(spellchecker, data);

            return(true);
        }
示例#3
0
        internal static void WriteSpellcheckCommand(SpellcheckCommandOptions options)
        {
            var spellcheckState = (SpellcheckState)options.Replacer;

            WriteOption("ask", options.AskMode);
            WriteOption("attributes", options.Attributes);
            WriteOption("attributes to skip", options.AttributesToSkip);
            WriteFilter("content filter", options.ContentFilter);
            WriteEncoding("default encoding", options.DefaultEncoding);
            WriteFilter("directory filter", options.DirectoryFilter, options.DirectoryNamePart);
            WriteDisplayFormat("display", options.Format);
            WriteOption("dry run", options.DryRun);
            WriteOption("empty", options.EmptyOption);
            WriteFilter("extension filter", options.ExtensionFilter);
            WriteFilePropertyFilter(
                "file properties",
                options.SizePredicate,
                options.CreationTimePredicate,
                options.ModifiedTimePredicate);
            WriteOption("fixes", spellcheckState.Data.Fixes.Items.Sum(f => f.Value.Count));
            WriteOption("highlight options", options.HighlightOptions);
            WriteInput(options.Input);
            WriteOption("interactive", options.Interactive);
            WriteOption("max matching files", options.MaxMatchingFiles);
            WriteOption("max matches in file", options.MaxMatchesInFile);
            WriteOption("min word length", spellcheckState.Spellchecker.Options.MinWordLength);
            WriteFilter("name filter", options.NameFilter, options.NamePart);
            WritePaths("paths", options.Paths);
            WriteOption("progress", options.Progress);
            WriteOption("recurse subdirectories", options.RecurseSubdirectories);
            WriteOption("search target", options.SearchTarget);
            WriteSortOptions("sort", options.SortOptions);
            WriteOption("split mode", spellcheckState.Spellchecker.Options.SplitMode);
#if DEBUG
            WriteRegex("word", spellcheckState.Spellchecker.WordRegex);
#endif
            WriteOption("words", spellcheckState.Data.Words.Values.Count + spellcheckState.Data.CaseSensitiveWords.Values.Count);
        }