static public int CalculateSpecificity(StringSlice inMatchRule, bool inbCaseSensitive, char inWildcard = '*') { if (inMatchRule.IsEmpty) { return(0); } int specificity = (int.MaxValue / 2) - inMatchRule.Length; bool bWildcardStart = inMatchRule.StartsWith(inWildcard); bool bWildcardEnd = inMatchRule.EndsWith(inWildcard); if (bWildcardStart && bWildcardEnd) { specificity = inMatchRule.Length - 2; } else if (bWildcardStart || bWildcardEnd) { specificity = inMatchRule.Length - 1; } if (specificity < 0) { specificity = 0; } if (inbCaseSensitive) { specificity *= 2; } return(specificity); }
/// <summary> /// Determines if a string matches the given filter. /// Wildcard characters are supported at the start and end of the filter. /// </summary> /// <remarks> /// This does not yet support wildcards in the middle of the filter. /// </remarks> static public bool WildcardMatch(StringSlice inString, string inFilter, char inWildcard = '*', bool inbIgnoreCase = false) { if (string.IsNullOrEmpty(inFilter)) { return(inString.IsEmpty); } int filterLength = inFilter.Length; if (filterLength == 1 && inFilter[0] == inWildcard) { return(true); } if (filterLength == 2 && inFilter[0] == inWildcard && inFilter[1] == inWildcard) { return(true); } bool bStart = inFilter[0] == inWildcard; bool bEnd = inFilter[filterLength - 1] == inWildcard; if (bStart || bEnd) { string filterStr = inFilter; int startIdx = 0; if (bStart) { ++startIdx; --filterLength; } if (bEnd) { --filterLength; } filterStr = filterStr.Substring(startIdx, filterLength); if (bStart && bEnd) { return(inString.Contains(filterStr, inbIgnoreCase)); } if (bStart) { return(inString.EndsWith(filterStr, inbIgnoreCase)); } return(inString.StartsWith(filterStr, inbIgnoreCase)); } return(inString.Equals(inFilter, inbIgnoreCase)); }
public StringSlice Process(StringSlice inSlice) { StringSlice slice = inSlice.Trim(); if (slice.Length >= 2 && slice.StartsWith('"') && slice.EndsWith('"')) { slice = slice.Substring(1, slice.Length - 2); } // if this contains escaped CSV sequences, unescape it here if (m_Unescape && (slice.Contains("\\") || slice.Contains("\\\""))) { return(slice.Unescape(Escaper.Instance)); } return(slice); }
static public bool TryParse(StringSlice inSlice, out StringHash64 outHash) { if (inSlice.StartsWith(StringHashing.CustomHashPrefix)) { ulong hexVal; if (StringParser.TryParseHex(inSlice.Substring(1), 16, out hexVal)) { outHash = new StringHash64(hexVal); return(true); } } else if (inSlice.StartsWith("0x")) { ulong hexVal; if (StringParser.TryParseHex(inSlice.Substring(2), 16, out hexVal)) { outHash = new StringHash64(hexVal); return(true); } outHash = default(StringHash64); return(false); } else if (inSlice.StartsWith(StringHashing.StringPrefix)) { outHash = inSlice.Substring(1).Hash64(); return(true); } else if (inSlice.StartsWith('"') && inSlice.EndsWith('"')) { outHash = inSlice.Substring(1, inSlice.Length - 2).Hash64(); return(true); } outHash = inSlice.Hash64(); return(true); }