/// <exclude />
        public static string EncodeUrlInvalidCharacters(string value)
        {
            const char separator        = '|';
            const char spaceReplacement = '-';

            var symbolsToEncode = new Hashset <char>(new[] { '<', '>', '*', '%', '&', '\\', '?', '/' });

            symbolsToEncode.Add(separator);
            symbolsToEncode.Add(spaceReplacement);

            var sb = new StringBuilder(value.Length);

            foreach (var ch in value)
            {
                if (!symbolsToEncode.Contains(ch))
                {
                    sb.Append(ch);
                    continue;
                }

                int code = (int)ch;
                Verify.That(code <= 256, "1 byte ASCII code expected");

                sb.Append(separator).Append(code.ToString("X2"));
            }

            return(sb.Replace(' ', spaceReplacement).ToString());
        }
 public bool Contains(T item)
 {
     _lock.EnterWriteLock();
     try
     {
         return(hashset.Contains(item));
     }
     finally
     {
         if (_lock.IsWriteLockHeld)
         {
             _lock.ExitWriteLock();
         }
     }
 }
Beispiel #3
0
    public static IEnumerable <string> ReplaceFirstOccurrencesWithEmpty(this IEnumerable <string> @this, IEnumerable <string> a)
    {
        // prepare a HashSet<string> to know how many A elements there still exist
        var set = new Hashset <string>(a);

        // iterate and apply the rule you asked about
        // virtually forever (if needed)
        foreach (var value in @this)
        {
            if (set.Contains(value))
            {
                set.Remove(value);
                yield return("");
            }
            else
            {
                yield return(value);
            }
        }
    }
Beispiel #4
0
        /// <exclude />
        public static string EncodeUrlInvalidCharacters(string value)
        {
            const char separator = '|';
            const char spaceReplacement = '-';

            var symbolsToEncode = new Hashset<char>(new[] { '<', '>', '*', '%', '&', '\\', '?' });

            symbolsToEncode.Add(separator);
            symbolsToEncode.Add(spaceReplacement);

            var sb = new StringBuilder(value.Length);

            foreach (var ch in value)
            {
                if (!symbolsToEncode.Contains(ch))
                {
                    sb.Append(ch);
                    continue;
                }

                int code = (int)ch;
                Verify.That(code <= 256, "1 byte ASCII code expected");

                sb.Append(separator).Append(code.ToString("X2"));
            }

            return sb.Replace(' ', spaceReplacement).ToString();
        }