public static string HashWords(this string text, byte[] key) { if (text == null || key == null) { return(text); } using var hmac = new HMACMD5(key); return(WordRegex.Replace(text, match => hmac.HashWord(match.Value.ToLower()))); }
/// <summary> /// Initializes a new instance of the <see cref="SpellingDictionaryBase"/> class. /// </summary> /// <param name="words">The words.</param> /// <param name="objectPool">The object pool.</param> protected SpellingDictionaryBase(string[] words, ObjectPool <StringBuilder> objectPool) { for (int i = 0; i < words.Length; i++) { var TempWords = words[i].Split(new char[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int x = 0; x < TempWords.Length; ++x) { string trimmedWord = TempWords[x].Trim().ToLower(); if (WordRegex.IsMatch(trimmedWord)) { Dictionary.Add(trimmedWord); } } } ObjectPool = objectPool; }
private void AnalyzeText( string value, int startIndex, int length, ref ImmutableArray <SpellingMatch> .Builder?builder) { int sequenceEndIndex = -1; for ( Match match = WordRegex.Match(value, startIndex, length); match.Success; match = match.NextMatch()) { if (sequenceEndIndex >= 0) { if (match.Index <= sequenceEndIndex) { continue; } else { sequenceEndIndex = -1; } } WordSequenceMatch sequenceMatch = Data.GetSequenceMatch(value, startIndex, length, match); if (!sequenceMatch.IsDefault) { sequenceEndIndex = sequenceMatch.EndIndex; continue; } if (match.Length >= Options.MinWordLength) { if (_splitRegex == null) { AnalyzeValue(match.Value, match.Index, null, 0, ref builder); } else { AnalyzeSplit(_splitRegex, match.Value, match.Index, 0, ref builder); } } } }
private static NounSynset CreateSet(string rawSynset) { var line = rawSynset.Substring(0, rawSynset.IndexOf('|')); var referencedSets = from Match match in PointerRegex.Matches(line) let split = match.Value.SplitRemoveEmpty(' ') where split.Length > 1 let linkKind = linkMap[split[0]] where consideredSetLinks.Contains(linkKind) let referenced = int.Parse(split[1]) select new SetReference(linkKind, referenced); return(new NounSynset( id: int.Parse(line.Substring(0, 8)), words: from Match m in WordRegex.Matches(line) select m.Value.Replace( '_', ' ' ), category: (NounCategory)int.Parse(line.Substring(9, 2)), pointerRelationships: referencedSets )); }
private static string EscapeKeywords(this string text) => text == null ? null : WordRegex.Replace(text, match => match.Value.EscapeKeyword());