コード例 #1
0
        public static bool TryParse(ref string error, string rangeString, out RangeSetSeries output)
        {
            List <RangeSet> rangeSets = new List <RangeSet>();

            output = null;
            var strLength = rangeString.Length;
            int endPos    = 0;
            int startPos;

            for (startPos = 0; startPos < strLength; startPos++)
            {
                if (rangeString[startPos] == '{')
                {
                    bool success = false;
                    for (endPos = startPos + 1; endPos < strLength; endPos++)
                    {
                        if (rangeString[endPos] == '}')
                        {
                            RangeSet temp;
                            if (!RangeSet.TryParse(ref error, rangeString.Substring(startPos + 1, endPos - startPos - 1), out temp))
                            {
                                return(false);
                            }
                            rangeSets.Add(temp);
                            startPos = endPos; // the increment will make sure we don't re explore this
                            success  = true;
                            break;
                        }
                    }
                    if (!success)
                    {
                        error = "There was an unmatched '{' at position " + startPos;
                        return(false);
                    }
                }
            }
            // in case it is a set of 1 element
            if (rangeSets.Count == 0)
            {
                RangeSet temp;
                if (RangeSet.TryParse(ref error, rangeString, out temp))
                {
                    return(false);
                }
                rangeSets.Add(temp);
            }
            output = new RangeSetSeries(rangeSets);
            return(true);
        }
コード例 #2
0
        public static bool TryParse(string rangeString, out RangeSetSeries output)
        {
            string error = null;

            return(TryParse(ref error, rangeString, out output));
        }