Exemplo n.º 1
0
        // once all the cardinalitytransform specific logic is extracted.
        public static List <IPathElement> Parse(string key)
        {
            var result = new List <IPathElement>();

            if (key.Contains(AT))
            {
                result.Add(new AtPathElement(key));
            }
            else if (STAR == key)
            {
                result.Add(new StarAllPathElement(key));
            }
            else if (key.Contains(STAR))
            {
                if (StringTools.CountMatches(key, STAR) == 1)
                {
                    result.Add(new StarSinglePathElement(key));
                }
                else
                {
                    result.Add(new StarRegexPathElement(key));
                }
            }
            else
            {
                result.Add(new LiteralPathElement(key));
            }

            return(result);
        }
Exemplo n.º 2
0
        public StarSinglePathElement(string key) :
            base(key)
        {
            if (StringTools.CountMatches(key, "*") != 1)
            {
                throw new ArgumentException(nameof(key), "StarSinglePathElement should only have one '*' in its key. Was: " + key);
            }
            else if ("*" == key)
            {
                throw new ArgumentException(nameof(key), "StarSinglePathElement should have a key that is just '*'. Was: " + key);
            }

            if (key.StartsWith("*"))
            {
                _prefix = "";
                _suffix = key.Substring(1);
            }
            else if (key.EndsWith("*"))
            {
                _prefix = key.Substring(0, key.Length - 1);
                _suffix = "";
            }
            else
            {
                string[] split = key.Split('*');
                _prefix = split[0];
                _suffix = split[1];
            }
        }
Exemplo n.º 3
0
        // Ex Keys :  *, cdv-*, *-$de
        public static IMatchablePathElement Parse(string key)
        {
            if ("*" == key)
            {
                return(new StarAllPathElement(key));
            }

            int numOfStars = StringTools.CountMatches(key, "*");

            if (numOfStars == 1)
            {
                return(new StarSinglePathElement(key));
            }
            else if (numOfStars == 2)
            {
                return(new StarDoublePathElement(key));
            }
            else if (numOfStars > 2)
            {
                return(new StarRegexPathElement(key));
            }
            else
            {
                return(new LiteralPathElement(key));
            }
        }
Exemplo n.º 4
0
        /**+
         *
         * @param key : should be a string with two "*" elements.
         */
        public StarDoublePathElement(string key) :
            base(key)
        {
            if (StringTools.CountMatches(key, "*") != 2)
            {
                throw new ArgumentException(nameof(key), "StarDoublePathElement should have two '*' in its key. Was: " + key);
            }

            string[] split          = key.Split('*');
            bool     startsWithStar = key.StartsWith("*");
            bool     endsWithStar   = key.EndsWith("*");

            if (startsWithStar && endsWithStar)
            {
                _prefix = "";
                _mid    = split[1];
                _suffix = "";
            }
            else if (endsWithStar)
            {
                _prefix = split[0];
                _mid    = split[1];
                _suffix = "";
            }
            else if (startsWithStar)
            {
                _prefix = "";
                _mid    = split[1];
                _suffix = split[2];
            }
            else
            {
                _prefix = split[0];
                _mid    = split[1];
                _suffix = split[2];
            }
        }
Exemplo n.º 5
0
        /**
         * Visible for Testing.
         *
         * Inspects the key in a particular order to determine the correct sublass of
         *  PathElement to create.
         *
         * @param origKey string that should represent a single PathElement
         * @return a concrete implementation of PathElement
         */
        public static IPathElement ParseSingleKeyLHS(string origKey)
        {
            string elementKey;   // the string to use to actually make Elements
            string keyToInspect; // the string to use to determine which kind of Element to create

            if (origKey.Contains("\\"))
            {
                // only do the extra work of processing for escaped chars, if there is one.
                keyToInspect = SpecStringParser.RemoveEscapedValues(origKey);
                elementKey   = SpecStringParser.RemoveEscapeChars(origKey);
            }
            else
            {
                keyToInspect = origKey;
                elementKey   = origKey;
            }

            //// LHS single values
            if ("@" == keyToInspect)
            {
                return(new AtPathElement(elementKey));
            }
            else if ("*" == keyToInspect)
            {
                return(new StarAllPathElement(elementKey));
            }
            else if (keyToInspect.StartsWith("["))
            {
                if (StringTools.CountMatches(keyToInspect, "[") != 1 || StringTools.CountMatches(keyToInspect, "]") != 1)
                {
                    throw new SpecException("Invalid key:" + origKey + " has too many [] references.");
                }

                return(new ArrayPathElement(elementKey));
            }
            //// LHS multiple values
            else if (keyToInspect.StartsWith("@") || keyToInspect.Contains("@("))
            {
                // The traspose path element gets the origKey so that it has it's escapes.
                return(TransposePathElement.Parse(origKey));
            }
            else if (keyToInspect.Contains("@"))
            {
                throw new SpecException("Invalid key:" + origKey + " can not have an @ other than at the front.");
            }
            else if (keyToInspect.Contains("$"))
            {
                return(new DollarPathElement(elementKey));
            }
            else if (keyToInspect.Contains("["))
            {
                if (StringTools.CountMatches(keyToInspect, "[") != 1 || StringTools.CountMatches(keyToInspect, "]") != 1)
                {
                    throw new SpecException("Invalid key:" + origKey + " has too many [] references.");
                }

                return(new ArrayPathElement(elementKey));
            }
            else if (keyToInspect.Contains("&"))
            {
                if (keyToInspect.Contains("*"))
                {
                    throw new SpecException("Invalid key:" + origKey + ", Can't mix * with & ) ");
                }
                return(new AmpPathElement(elementKey));
            }
            else if (keyToInspect.Contains("*"))
            {
                int numOfStars = StringTools.CountMatches(keyToInspect, "*");

                if (numOfStars == 1)
                {
                    return(new StarSinglePathElement(elementKey));
                }
                else if (numOfStars == 2)
                {
                    return(new StarDoublePathElement(elementKey));
                }
                else
                {
                    return(new StarRegexPathElement(elementKey));
                }
            }
            else if (keyToInspect.Contains("#"))
            {
                return(new HashPathElement(elementKey));
            }
            else
            {
                return(new LiteralPathElement(elementKey));
            }
        }