Example #1
0
        /// <summary>
        /// Attempt to parse the specified token as a set of unique identifiers.
        /// </summary>
        /// <remarks>
        /// Attempts to parse the specified token as a set of unique identifiers.
        /// </remarks>
        /// <returns><c>true</c> if the set of unique identifiers were successfully parsed; otherwise, <c>false</c>.</returns>
        /// <param name="token">The token containing the set of unique identifiers.</param>
        /// <param name="validity">The UIDVALIDITY value.</param>
        /// <param name="uids">The set of unique identifiers.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="token"/> is <c>null</c>.
        /// </exception>
        public static bool TryParse(string token, uint validity, out UniqueIdSet uids)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            uids = new UniqueIdSet {
                sorted = false
            };

            UniqueId start, end;
            int      index = 0;

            do
            {
                if (!UniqueId.TryParse(token, ref index, validity, out start))
                {
                    return(false);
                }

                if (index >= token.Length)
                {
                    uids.ranges.Add(new UniqueIdRange(start, start));
                    uids.count++;
                    return(true);
                }

                if (token[index] == ':')
                {
                    index++;

                    if (!UniqueId.TryParse(token, ref index, validity, out end))
                    {
                        return(false);
                    }

                    var range = new UniqueIdRange(start, end);
                    uids.count += range.Count;
                    uids.ranges.Add(range);
                }
                else
                {
                    uids.ranges.Add(new UniqueIdRange(start, start));
                    uids.count++;
                }

                if (index >= token.Length)
                {
                    return(true);
                }

                if (token[index++] != ',')
                {
                    return(false);
                }
            } while (true);
        }
Example #2
0
 /// <summary>
 /// Attempt to parse the specified token as a set of unique identifiers.
 /// </summary>
 /// <remarks>
 /// Attempts to parse the specified token as a set of unique identifiers.
 /// </remarks>
 /// <returns><c>true</c> if the set of unique identifiers were successfully parsed; otherwise, <c>false</c>.</returns>
 /// <param name="token">The token containing the set of unique identifiers.</param>
 /// <param name="uids">The set of unique identifiers.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="token"/> is <c>null</c>.
 /// </exception>
 public static bool TryParse(string token, out UniqueIdSet uids)
 {
     return(TryParse(token, 0, out uids));
 }
Example #3
0
        /// <summary>
        /// Attempt to parse the specified token as a set of unique identifiers.
        /// </summary>
        /// <remarks>
        /// Attempts to parse the specified token as a set of unique identifiers.
        /// </remarks>
        /// <returns><c>true</c> if the set of unique identifiers were successfully parsed; otherwise, <c>false</c>.</returns>
        /// <param name="token">The token containing the set of unique identifiers.</param>
        /// <param name="validity">The UIDVALIDITY value.</param>
        /// <param name="uids">The set of unique identifiers.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="token"/> is <c>null</c>.
        /// </exception>
        public static bool TryParse(string token, uint validity, out UniqueIdSet uids)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            uids = new UniqueIdSet(validity);

            var  order = SortOrder.None;
            bool sorted = true;
            uint start, end;
            uint prev  = 0;
            int  index = 0;

            do
            {
                if (!UniqueId.TryParse(token, ref index, out start))
                {
                    return(false);
                }

                if (index < token.Length && token[index] == ':')
                {
                    index++;

                    if (!UniqueId.TryParse(token, ref index, out end))
                    {
                        return(false);
                    }

                    var range = new Range(start, end);
                    uids.count += range.Count;
                    uids.ranges.Add(range);

                    if (sorted)
                    {
                        switch (order)
                        {
                        default: sorted = true; order = start <= end ? SortOrder.Ascending : SortOrder.Descending; break;

                        case SortOrder.Descending: sorted = start >= end && start <= prev; break;

                        case SortOrder.Ascending: sorted = start <= end && start >= prev; break;
                        }
                    }

                    prev = end;
                }
                else
                {
                    uids.ranges.Add(new Range(start, start));
                    uids.count++;

                    if (sorted && uids.ranges.Count > 1)
                    {
                        switch (order)
                        {
                        default: sorted = true; order = start >= prev ? SortOrder.Ascending : SortOrder.Descending; break;

                        case SortOrder.Descending: sorted = start <= prev; break;

                        case SortOrder.Ascending: sorted = start >= prev; break;
                        }
                    }

                    prev = start;
                }

                if (index >= token.Length)
                {
                    break;
                }

                if (token[index++] != ',')
                {
                    return(false);
                }
            } while (true);

            uids.SortOrder = sorted ? order : SortOrder.None;

            return(true);
        }
Example #4
0
 /// <summary>
 /// Attempt to parse the specified token as a set of unique identifiers.
 /// </summary>
 /// <remarks>
 /// Attempts to parse the specified token as a set of unique identifiers.
 /// </remarks>
 /// <returns><c>true</c> if the set of unique identifiers were successfully parsed; otherwise, <c>false</c>.</returns>
 /// <param name="token">The token containing the set of unique identifiers.</param>
 /// <param name="validity">The UIDVALIDITY value.</param>
 /// <param name="uids">The set of unique identifiers.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="token"/> is <c>null</c>.
 /// </exception>
 public static bool TryParse(string token, uint validity, out UniqueIdSet uids)
 {
     return(TryParse(token, validity, out uids, out _, out _));
 }
Example #5
0
        /// <summary>
        /// Attempt to parse the specified token as a set of unique identifiers.
        /// </summary>
        /// <remarks>
        /// Attempts to parse the specified token as a set of unique identifiers.
        /// </remarks>
        /// <returns><c>true</c> if the set of unique identifiers were successfully parsed; otherwise, <c>false</c>.</returns>
        /// <param name="token">The token containing the set of unique identifiers.</param>
        /// <param name="validity">The UIDVALIDITY value.</param>
        /// <param name="uids">The set of unique identifiers.</param>
        /// <param name="minValue">The minimum unique identifier value parsed.</param>
        /// <param name="maxValue">The maximum unique identifier value parsed.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="token"/> is <c>null</c>.
        /// </exception>
        internal static bool TryParse(string token, uint validity, out UniqueIdSet uids, out UniqueId?minValue, out UniqueId?maxValue)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            uids     = new UniqueIdSet(validity);
            minValue = maxValue = null;

            var  order  = SortOrder.None;
            uint min    = uint.MaxValue;
            uint max    = 0;
            bool sorted = true;
            uint prev   = 0;
            int  index  = 0;

            do
            {
                if (!UniqueId.TryParse(token, ref index, out uint start))
                {
                    return(false);
                }

                min = Math.Min(min, start);
                max = Math.Max(max, start);

                if (index < token.Length && token[index] == ':')
                {
                    index++;

                    if (!UniqueId.TryParse(token, ref index, out uint end))
                    {
                        return(false);
                    }

                    min = Math.Min(min, end);
                    max = Math.Max(max, end);

                    var range = new Range(start, end);
                    uids.count += range.Count;
                    uids.ranges.Add(range);

                    if (sorted)
                    {
                        switch (order)
                        {
                        default: order = start <= end ? SortOrder.Ascending : SortOrder.Descending; break;

                        case SortOrder.Descending: sorted = start >= end && start <= prev; break;

                        case SortOrder.Ascending: sorted = start <= end && start >= prev; break;
                        }
                    }

                    prev = end;
                }
                else
                {
                    uids.ranges.Add(new Range(start, start));
                    uids.count++;

                    if (sorted && uids.ranges.Count > 1)
                    {
                        switch (order)
                        {
                        default: order = start >= prev ? SortOrder.Ascending : SortOrder.Descending; break;

                        case SortOrder.Descending: sorted = start <= prev; break;

                        case SortOrder.Ascending: sorted = start >= prev; break;
                        }
                    }

                    prev = start;
                }

                if (index >= token.Length)
                {
                    break;
                }

                if (token[index++] != ',')
                {
                    return(false);
                }
            } while (true);

            uids.SortOrder = sorted ? order : SortOrder.None;

            if (min <= max)
            {
                minValue = new UniqueId(validity, min);
                maxValue = new UniqueId(validity, max);
            }

            return(true);
        }