public CSharpSpellingAnalyzer( SpellingData spellingData, SpellingFixerOptions options) { _spellingData = spellingData; _options = options; }
// Use this for initialization void Start() { Application.targetFrameRate = 60; particle.SetActive(false); previewPanel.SetActive(false); audioSource = GetComponent <AudioSource>(); endStartPos = endPos.transform.localPosition; soundVolume = PlayerPrefs.GetFloat("SOUND_VOLUME"); UpdateSoundVolume(soundVolume); if (MusicManager.Instance != null) { MusicManager.Instance.StopMusic(); } // Disable all sond button foreach (var item in btnSounds) { item.SetActive(false); } settingPanel.transform.DOScale(0, 0); // Get the list of the spelling data. spellingData = JsonUtility.FromJson <SpellingData>(spellingJson.text); }
public Spellchecker( SpellingData data, Regex?wordRegex = null, SpellcheckerOptions?options = null) { Data = data; WordRegex = wordRegex ?? _wordRegex; Options = options ?? SpellcheckerOptions.Default; _splitRegex = new Regex("-|" + _splitCasePattern, RegexOptions.IgnorePatternWhitespace); }
public SpellcheckState( Spellchecker spellchecker, SpellingData data, IEnumerable <Filter>?filters = null) { Spellchecker = spellchecker; Data = data; Filters = filters?.ToImmutableArray() ?? ImmutableArray <Filter> .Empty; OriginalFixes = data.Fixes; }
private static async Task <int> SpellcheckAsync(SpellcheckCommandLineOptions options) { if (!TryParseOptionValueAsEnumFlags( options.Scope, OptionNames.Scope, out SpellingScopeFilter scopeFilter, SpellingScopeFilter.Comment | SpellingScopeFilter.Region | SpellingScopeFilter.Symbol)) { return(ExitCodes.Error); } if (!TryParseOptionValueAsEnumFlags(options.IgnoredScope, OptionNames.IgnoredScope, out SpellingScopeFilter ignoredScopeFilter, SpellingScopeFilter.None)) { return(ExitCodes.Error); } scopeFilter &= ~ignoredScopeFilter; if (!TryParseOptionValueAsEnum(options.Visibility, OptionNames.Visibility, out Visibility visibility)) { return(ExitCodes.Error); } if (!options.TryGetProjectFilter(out ProjectFilter projectFilter)) { return(ExitCodes.Error); } if (!ParseHelpers.TryEnsureFullPath(options.Words, out ImmutableArray <string> wordListPaths)) { return(ExitCodes.Error); } if (!TryParsePaths(options.Paths, out ImmutableArray <string> paths)) { return(ExitCodes.Error); } WordListLoaderResult loaderResult = WordListLoader.Load( wordListPaths, options.MinWordLength, options.MaxWordLength, (options.CaseSensitive) ? WordListLoadOptions.None : WordListLoadOptions.IgnoreCase); var data = new SpellingData(loaderResult.List, loaderResult.CaseSensitiveList, loaderResult.FixList); var command = new SpellcheckCommand(options, projectFilter, data, visibility, scopeFilter); CommandStatus status = await command.ExecuteAsync(paths, options.MSBuildPath, options.Properties); return(GetExitCode(status)); }
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); }
public override ImmutableArray <Diagnostic> AnalyzeSpelling( SyntaxNode node, SpellingData spellingData, SpellingFixerOptions options, CancellationToken cancellationToken = default) { var diagnostics = new List <Diagnostic>(); var analysisContext = new SpellingAnalysisContext( diagnostic => diagnostics.Add(diagnostic), spellingData, options, cancellationToken); CSharpSpellingWalker walker = CSharpSpellingWalker.Create(analysisContext); walker.Visit(node); return(diagnostics.ToImmutableArray()); }
public override DiagnosticAnalyzer CreateAnalyzer( SpellingData spellingData, SpellingFixerOptions options) { return(new CSharpSpellingAnalyzer(spellingData, options)); }
public static ImmutableArray <string> SwapLetters(string value, SpellingData spellingData) { int length = value.Length; if (length < 4) { return(ImmutableArray <string> .Empty); } ImmutableArray <string> .Builder?fixes = null; char[] arr = value.ToCharArray(); Array.Sort(arr, (x, y) => x.CompareTo(y)); var key = new string(arr); if (!spellingData.CharMap.TryGetValue(key, out ImmutableHashSet <string>?values)) { return(ImmutableArray <string> .Empty); } int maxCharDiff = (length <= 6) ? 2 : 3; foreach (string value2 in values) { if (length == value2.Length) { int charDiff = 0; int diffStartIndex = -1; int diffEndIndex = -1; for (int i = 0; i < length; i++) { if (value[i] != value2[i]) { if (diffStartIndex == -1) { diffStartIndex = i; } else { diffEndIndex = i; } charDiff++; } if (i > 1 && charDiff > maxCharDiff) { return(ImmutableArray <string> .Empty); } } if (diffEndIndex - diffStartIndex <= 2) { (fixes ??= ImmutableArray.CreateBuilder <string>()).Add(value2); } } } return(fixes?.ToImmutableArray() ?? ImmutableArray <string> .Empty); }
public static ImmutableArray <string> Fuzzy( string value, SpellingData spellingData, CancellationToken cancellationToken = default) { int length = value.Length; if (length <= 3) { return(ImmutableArray <string> .Empty); } ImmutableHashSet <string> .Builder?matches = null; WordCharMap map = spellingData.CharIndexMap; WordCharMap reversedMap = spellingData.ReversedCharIndexMap; var intersects = new ImmutableHashSet <string> [length]; int i = 0; while (true) { cancellationToken.ThrowIfCancellationRequested(); if (!map.TryGetValue(value, i, out ImmutableHashSet <string>?values)) { break; } ImmutableHashSet <string> intersect = (i == 0) ? values : intersects[i - 1].Intersect(values); if (i == length - 2) { TryAddMatches(intersect, length, ref matches); } else if (i == length - 1) { TryAddMatches(intersect, length + 1, ref matches); break; } if (intersect.Count == 0) { break; } intersects[i] = intersect; i++; } int j = length - 1; while (true) { cancellationToken.ThrowIfCancellationRequested(); if (!reversedMap.TryGetValue(value[j], length - j - 1, out ImmutableHashSet <string>?values)) { break; } ImmutableHashSet <string> intersect = (j == length - 1) ? values : values.Intersect(intersects[j + 1]); if (j == 1) { TryAddMatches(intersect, length, ref matches); } else if (j == 0) { TryAddMatches(intersect, length + 1, ref matches); break; } if (intersect.Count == 0) { break; } int diff = j - i; if (diff <= 0) { if (TryAddMatches(intersects[j - 1].Intersect(intersect), length + 1, ref matches)) { break; } } else if (diff == 1 && j > 1) { if (TryAddMatches(intersects[j - 2].Intersect(intersect), length - 1, length, ref matches)) { break; } } intersects[j] = intersect; j--; } if (matches == null) { return(ImmutableArray <string> .Empty); } return(matches .OrderBy(f => f) .ToImmutableArray()); }