예제 #1
0
        public static DIndices GetSubstring(string s, ref int i, DelimitType dt)
        {
            DIndices di = new DIndices();

            di.Type = DelimitType.None;
            if (i < 0)
            {
                di.Start = -1;
                return(di);
            }

            // Find The First Character
            while (i < s.Length - 1)
            {
                if (IsOpener(s[i], dt))
                {
                    di.Type = GetDType(s[i]);
                    i++;
                    break;
                }
                i++;
            }

            // Could Not Find The First Character
            if (di.Type == DelimitType.None)
            {
                return(di);
            }

            // Find The Last Character
            di.Start = i;
            int open = 1;

            while (i < s.Length && open > 0)
            {
                if (IsOpener(s[i], di.Type))
                {
                    open++;
                }
                else if (IsCloser(s[i], di.Type))
                {
                    open--;
                    if (open == 0)
                    {
                        di.End = i - 1;
                        return(di);
                    }
                }
                i++;
            }

            // Could Not Find The Last Character
            di.Type = DelimitType.None;
            return(di);
        }
예제 #2
0
        public static List <DIndices> Delimit(string s, DelimitType dt)
        {
            var l = new List <DIndices>();
            int i = 0;

            while (i < s.Length)
            {
                DIndices di = GetSubstring(s, ref i, dt);
                if (di.Type == DelimitType.None)
                {
                    break;
                }
                l.Add(di);
            }
            return(l);
        }
예제 #3
0
        public static DIndices GetSubstring(string s, ref int i, DelimitType dt)
        {
            DIndices di = new DIndices();
            di.Type = DelimitType.None;
            if(i < 0) {
                di.Start = -1;
                return di;
            }

            // Find The First Character
            while(i < s.Length - 1) {
                if(IsOpener(s[i], dt)) {
                    di.Type = GetDType(s[i]);
                    i++;
                    break;
                }
                i++;
            }

            // Could Not Find The First Character
            if(di.Type == DelimitType.None)
                return di;

            // Find The Last Character
            di.Start = i;
            int open = 1;
            while(i < s.Length && open > 0) {
                if(IsOpener(s[i], di.Type)) {
                    open++;
                }
                else if(IsCloser(s[i], di.Type)) {
                    open--;
                    if(open == 0) {
                        di.End = i - 1;
                        return di;
                    }
                }
                i++;
            }

            // Could Not Find The Last Character
            di.Type = DelimitType.None;
            return di;
        }
예제 #4
0
        private static void ParseComplexData(object o, ZXPProxy zpp, string s, List <DIndices> ld, ref int li)
        {
            // Check For Data Availability
            if (li + 1 >= ld.Count || ld[li].Length < 1 || ld[li + 1].Type != DelimitType.Curly)
            {
                return;
            }

            // Check If A Key Is Available
            string key = GetKeyString(s, ld, li);

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

            // Get Substrings
            DIndices diType = ld[li], diData = ld[li + 1];

            li++;

            // Find The Field That Matches To This Key
            ZXPDatum datum = null;

            if (!zpp.DataDict.TryGetValue(key, out datum))
            {
                return;
            }

            // Check For A Possible Conversion
            if (datum.Converter != null)
            {
                // Try To Convert
                object val    = null;
                string sValue = s.Substring(ld[li].Start, ld[li].Length);
                if (ReadValue(sValue, datum.Converter, out val))
                {
                    datum.SetValue(o, val);
                }
                return;
            }
            else
            {
                // Get The Special Type
                string sType = s.Substring(diType.Start, diType.Length);
                if (string.IsNullOrWhiteSpace(sType))
                {
                    return;
                }
                Type cType = GetTypeFromString(sType);
                if (cType == null)
                {
                    return;
                }

                // Create And Set The Data
                object val    = null;
                string sValue = s.Substring(diData.Start, diData.Length);
                if (ReadValue(sValue, datum.Converter, cType, out val))
                {
                    datum.SetValue(o, val);
                }
            }
        }