Esempio n. 1
0
        // Add a new rule to either msg or global
        private void AddOneRule(Src n)
        {
            ccSR attr = (ccSR)cbAttribute.SelectedIndex;

            // Make sure the user filled it in
            if (ruleSpecified(attr))
            {
                // Get the new rule
                SubstitutionRule sr = GetSubstitutionRule(attr);
                if (Subs[(int)n] == null)
                {
                    // Create a whole new substitution with one rule
                    Subs[(int)n]         = GetNewSubstitution();
                    Subs[(int)n].SubRule = new SubstitutionRule[] { sr };
                }
                else
                {
                    // Delete the rule if it exists
                    List <SubstitutionRule> r = new List <SubstitutionRule>();
                    foreach (SubstitutionRule t in Subs[(int)n].SubRule)
                    {
                        if (t.Type != attr.ToString())
                        {
                            r.Add(t);
                        }
                    }
                    // Add the new rule to the list and turn it back to an array
                    r.Add(sr);
                    Subs[(int)n].SubRule = r.ToArray();
                }
            }
        }
Esempio n. 2
0
 // get the substitutions for one type
 private SubstitutionRule GetSubstitutionRule(ccSR t)
 {
     TextBox[] tbs = subTexts[(int)t];
     string[]  s   = new string[tbs.Length];
     for (int i = 0; i < tbs.Length; i++)
     {
         s[i] = tbs[i].Text;
     }
     return(new SubstitutionRule()
     {
         Base = startWith[(int)t],
         Type = t.ToString(),
         Text = String.Join(txtDelimiter.Text, s)
     });
 }
        private void RetrieveSubstitution(List <SubstitutionRule> sr, ccSR rule)
        {
            AttrData attr = GetAttrData(rule);
            int      n    = (int)(attr.Get.Max - attr.Get.Min + 1);

            string[] subCode = new string[n];
            for (int i = 0; i < n; i++)
            {
                subCode[i] = GetAttribute(rule, i + (int)attr.Get.Min);
            }
            for (int i = 0; i < n; i += 10)
            {
                sr.Add(new SubstitutionRule()
                {
                    Type = rule.ToString().Replace("_", ""),
                    Base = (int)(i + attr.Get.Min),
                    Text = string.Join("/", subCode, i, Math.Min(10, n - i)),
                });
            }
        }