Exemple #1
0
                public StringSlice Process(StringSlice inSlice)
                {
                    StringSlice slice = inSlice.TrimStart().Trim(QuoteTrim);

                    // if this contains escaped CSV sequences, unescape it here
                    if (m_Unescape && (slice.Contains("\\") || slice.Contains("\"\"")))
                    {
                        return(slice.Unescape(Escaper.Instance));
                    }
                    return(slice);
                }
Exemple #2
0
                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);
                }
Exemple #3
0
        /// <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));
        }