Delimit() public static method

public static Delimit ( string s, DelimitType dt ) : List
s string
dt DelimitType
return List
Example #1
0
        public static void ParseInto(string s, object o, ZXPProxy zpp)
        {
            List <DIndices> delimiters = Delimiter.Delimit(s, DelimitType.Any);

            for (int i = 0; i < delimiters.Count;)
            {
                switch (delimiters[i].Type)
                {
                // Plain Data That Should Be Able To Be Parsed In
                case DelimitType.Bracket:
                    ParseSimpleData(o, zpp, s, delimiters, ref i);
                    break;

                // This Is A Special Type
                case DelimitType.Angled:
                    ParseComplexData(o, zpp, s, delimiters, ref i);
                    break;

                // This Is A Function
                case DelimitType.Paranthesis:
                    // Find The Key
                    ParseFunction(o, zpp, s, delimiters, ref i);
                    break;
                }
                i++;
            }
            return;
        }
Example #2
0
        private static bool ParseArray(Type eType, string sArray, out object val)
        {
            val = null;
            IZXPConverter etConv;

            ZXParser.GetConverter(eType, out etConv);

            var nl = Delimiter.Delimit(sArray, DelimitType.Angled | DelimitType.Curly);

            // Create Parameters
            object element;
            var    elements = new List <object>();

            for (int ai = 0; ai < nl.Count;)
            {
                if (nl[ai].Type == DelimitType.Angled)
                {
                    if (ai >= nl.Count - 1 || nl[ai + 1].Type != DelimitType.Curly)
                    {
                        ai++;
                        continue;
                    }

                    // Get The Argument Type
                    string atValue = sArray.Substring(nl[ai].Start, nl[ai].Length);
                    if (string.IsNullOrWhiteSpace(atValue))
                    {
                        break;
                    }
                    Type aType = GetTypeFromString(atValue);
                    if (aType == null)
                    {
                        ai += 2;
                        continue;
                    }

                    // Get The Argument
                    string        sValue = sArray.Substring(nl[ai + 1].Start, nl[ai + 1].Length);
                    IZXPConverter conv;
                    ZXParser.GetConverter(aType, out conv);
                    if (ReadValue(sValue, conv, aType, out element))
                    {
                        elements.Add(element);
                    }
                    ai += 2;
                }
                else
                {
                    // Simple Parse
                    string sValue = sArray.Substring(nl[ai].Start, nl[ai].Length);
                    if (ReadValue(sValue, etConv, eType, out element))
                    {
                        elements.Add(element);
                    }
                    ai++;
                }
            }

            if (elements.Count < 1)
            {
                return(true);
            }
            var valArr = Array.CreateInstance(eType, elements.Count);

            for (int i = 0; i < elements.Count; i++)
            {
                valArr.SetValue(elements[i], i);
            }
            val = valArr;
            return(true);
        }
Example #3
0
        private static void ParseFunction(object o, ZXPProxy zpp, string s, List <DIndices> ld, ref int li)
        {
            // Check If A Key Is Available
            string key = GetKeyString(s, ld, li);

            if (string.IsNullOrWhiteSpace(key))
            {
                return;
            }

            // Find The Method That Matches To This Key
            ZXPFunc    func;
            MethodInfo method = null;

            if (!zpp.FuncsDict.TryGetValue(key, out func))
            {
                return;
            }
            method = func.Method;

            // Check For Simple Invoke
            ParameterInfo[] paramInfo = method.GetParameters();
            if (paramInfo.Length < 1 || paramInfo == null)
            {
                method.Invoke(o, null);
                return;
            }

            // Parse Parameters
            string sArgs = s.Substring(ld[li].Start, ld[li].Length);

            object[] args = new object[paramInfo.Length];
            var      nl   = Delimiter.Delimit(sArgs, DelimitType.Angled | DelimitType.Curly);

            // Check Number Of Arguments
            int ca = 0;

            foreach (var ndi in nl)
            {
                if (ndi.Type == DelimitType.Curly)
                {
                    ca++;
                }
            }
            if (ca != args.Length)
            {
                return;
            }

            // Create Parameters
            int ai = 0, pi = 0;

            for (; pi < args.Length;)
            {
                if (nl[ai].Type == DelimitType.Angled)
                {
                    if (ai >= nl.Count - 1 || nl[ai + 1].Type != DelimitType.Curly)
                    {
                        ai++;
                        continue;
                    }

                    // Get The Argument Type
                    string atValue = sArgs.Substring(nl[ai].Start, nl[ai].Length);
                    if (string.IsNullOrWhiteSpace(atValue))
                    {
                        break;
                    }
                    Type aType = GetTypeFromString(atValue);
                    if (aType == null)
                    {
                        break;
                    }


                    // Get The Argument
                    string        sValue = sArgs.Substring(nl[ai + 1].Start, nl[ai + 1].Length);
                    IZXPConverter conv;
                    ZXParser.GetConverter(aType, out conv);
                    if (ReadValue(sValue, conv, aType, out args[pi]))
                    {
                        pi++;
                    }
                    ai += 2;
                }
                else
                {
                    // Simple Parse
                    Type          aType  = paramInfo[pi].ParameterType;
                    string        sValue = sArgs.Substring(nl[ai].Start, nl[ai].Length);
                    IZXPConverter conv;
                    ZXParser.GetConverter(aType, out conv);
                    if (ReadValue(sValue, conv, aType, out args[pi]))
                    {
                        pi++;
                    }
                    ai++;
                }
            }
            // Check That All Arguments Are OK
            if (pi == args.Length)
            {
                method.Invoke(o, args);
            }
        }