Example #1
0
        private Dictionary<string, string> Properties2Dictionary(string properties)
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            properties = properties.Replace("\r", "");
            foreach (var line in properties.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                if ((!string.IsNullOrEmpty(line)) && (!line.StartsWith(";")) && (!line.StartsWith("#")) && (!line.StartsWith("'")) && (line.Contains("=")))
                {
                    int index = line.IndexOf('=');
                    string key = line.Substring(0, index).Trim();
                    string value = line.Substring(index + 1).Trim();

                    if ((value.StartsWith("\"") && value.EndsWith("\"")) || (value.StartsWith("'") && value.EndsWith("'")))
                    {
                        value = value.Substring(1, value.Length - 2);
                    }
                    dictionary.Add(key, value);
                }
            }
            return dictionary;
        }
Example #2
0
        public string ConsultaFirst(int pkey)
        {
            string res = "";
            string pr = "";
            string elementos = "";
            int c = 1;
             //Obtener todas las producciones
            do {
                pr = ConsultaProd(Convert.ToString(pkey) + "." + Convert.ToString(c));
                elementos += pr + "|";
                c++;
            }
            while (pr != "");
            string [] or = elementos.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < or.Length; i++) {
                int apuntador = 0;
                bool terminado = false;
                string[] ntot = or[i].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                //Si es t se termina
                while (!terminado) {
                    if (apuntador >= ntot.Length) {
                        res += "$";
                        terminado = true;
                    }
                    else {
                        //Analiza lo que apunte
                        string o = ntot[apuntador];
                        //Si es NT
                        if (o.StartsWith("-")) {
                            int nt = Convert.ToInt32(o);
                            res += ConsultaFirst(nt);
                            string [] r = res.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            if (r.Length > 1 && r[r.Length - 1].StartsWith("0.")) {
                                res = "";
                                for (int j = 0; j < r.Length - 1; j++) {
                                    res += r[j] + ",";
                                }
                                apuntador++;
                            }
                            else {
                                terminado = true;
                            }
                        }
                        else {
                            //Si es T
                            if (o == "0") {
                                string epsilon = "0." + Convert.ToString(pkey).Substring(1);
                                res += epsilon+ ",";
                            }
                            else {
                                res += ntot[apuntador] + ",";
                            }
                            terminado = true;
                        }
                    }
                }
            }

            return res;
        }