Example #1
0
        /// <summary>
        /// Creates new enviromental object element.
        /// </summary>
        /// <param name="name">Environmental object name.</param>
        /// <param name="errorMessage">
        /// Output parameter, which holds error message catched during serialization.
        /// </param>
        /// <returns>
        /// True if serialization was succesfull otherwise returns false.
        /// </returns>
        public bool EnvironmentalObjects(string name, out string errorMessage)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentException(ExceptionsMessage("name", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(name, Regexp.Check.String))
                {
                    throw new ArgumentException(ExceptionsMessage("name", (int)ErrorMessages.IncorectCharacters));
                }

                // <environmentalObject name="a"/>
                XmlElement environmentalObjectElement = v_InventoryXmlDocument.CreateElement("environmentalObject");
                environmentalObjectElement.SetAttribute("name", name);

                XmlNode environmentalObject = v_InventoryXmlDocument.SelectSingleNode("inventory/mSystemDeclaration/environmentalObjects");
                environmentalObject?.AppendChild(environmentalObjectElement);

                errorMessage = null;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
Example #2
0
        // dump prints a string representation of the regexp showing
        // the structure explicitly.
        private static String dump(Regexp re)
        {
            StringBuilder b = new StringBuilder();

            dumpRegexp(b, re);
            return(b.ToString());
        }
Example #3
0
        public void testToStringEquivalentParse()
        {
            foreach (String[] tt in PARSE_TESTS)
            {
                Regexp re = Parser.parse(tt[0], TEST_FLAGS);
                String d  = dump(re);
                Assert.AreEqual(d, tt[1]); // (already ensured by testParseSimple)

                String s = re.ToString();
                if (!s.Equals(tt[0]))
                {
                    // If toString didn't return the original regexp,
                    // it must have found one with fewer parens.
                    // Unfortunately we can't check the length here, because
                    // toString produces "\\{" for a literal brace,
                    // but "{" is a shorter equivalent in some contexts.
                    Regexp nre = Parser.parse(s, TEST_FLAGS);
                    String nd  = dump(nre);
                    Assert.AreEqual(d, nd, false, String.Format("parse({0}) -> {1}", tt[0], s));

                    String ns = nre.ToString();
                    Assert.AreEqual(s, ns, false, String.Format("parse({0}) -> {1}", tt[0], s));
                }
            }
        }
Example #4
0
        /// <summary>
        /// Creates new radius element.
        /// </summary>
        /// <param name="value">Radius value.</param>
        /// <param name="errorMessage">
        /// Output parameter, which holds error message catched during serialization.
        /// </param>
        /// <returns>
        /// True if serialization was succesfull otherwise returns false.
        /// </returns>
        public bool Radius(string value, out string errorMessage)
        {
            try
            {
                if (string.IsNullOrEmpty(value))
                {
                    throw new ArgumentException(ExceptionsMessage("value", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(value, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("value", (int)ErrorMessages.IncorectFloatingNumber));
                }

                //<radius value="0.1"/>
                XmlElement radiuseElement = v_InventoryXmlDocument.CreateElement("radius");
                radiuseElement.SetAttribute("name", value);

                XmlNode radius = v_InventoryXmlDocument.SelectSingleNode("inventory/mSystemDeclaration");
                radius?.AppendChild(radiuseElement);

                errorMessage = null;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
Example #5
0
        /// <summary>
        /// Creates new protein element.
        /// </summary>
        /// <param name="name">Protein name.</param>
        /// <param name="errorMessage">
        /// Output parameter, which holds error message catched during serialization.
        /// </param>
        /// <returns>
        /// True if serialization was succesfull otherwise returns false.
        /// </returns>
        public bool Proteins(string name, out string errorMessage)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentException(ExceptionsMessage("name", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(name, Regexp.Check.StringWithApostroph))
                {
                    throw new ArgumentException(ExceptionsMessage("name", (int)ErrorMessages.IncorectCharactersWithApostroph));
                }

                // < protein name = "p0" />
                XmlElement protein = v_InventoryXmlDocument.CreateElement("protein");
                protein.SetAttribute("name", name);

                XmlNode proteins = v_InventoryXmlDocument.SelectSingleNode("inventory/mSystemDeclaration/proteins");
                proteins?.AppendChild(protein);

                errorMessage = null;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
        public bool DoCommand(FileInfo file)
        {
            var match =
                Regexp.Match(IncludeExtension
                                        ? file.ChangedFilename
                                        : Path.GetFileNameWithoutExtension(file.ChangedFilename));

            try
            {
                var ext = !IncludeExtension?Path.GetExtension(file.ChangedFilename) : "";

                var group    = match.Groups;
                var groupArr = new object[group.Count];
                for (var i = 0; i < groupArr.Length; i++)
                {
                    groupArr[i] = group[i].Value.Trim();
                }
                file.ChangedFilename = $"{string.Format(FormatString, groupArr)}{ext}";
            }
            catch
            {
                return(false);
            }

            return(true);
        }
        static void Main(string[] args)
        {
            ArrayList arr;;

            arr = (ArrayList)Regexp.Run("(FL_S2_3_M1_Q_r_k < 5) & (FL_S2_3_M2_Q_r_k < 5) ? 0 : FL_S2_M1_2.Q_sd * OF_KC_sd * 600 / (FL_S2_3_M1_Q_r_k + FL_S2_3_M2_Q_r_k)", "[A-z][A-z0-9.]*");
            Console.ReadKey();
        }
        /// <summary>
        /// Creates new evoRule element within evoRulesWithPriority block.
        /// </summary>
        /// <remarks>
        /// Catches all exceptions and returned as errorMessage.
        /// </remarks>
        /// <param name="type">EvoRule type can be metabolic, divide, center or destroy.</param>
        /// <param name="priority">EvoRule priority.</param>
        /// <param name="leftSideList">Container leftSide object.</param>
        /// <param name="rightSideList">Container rightSide object.</param>
        /// <param name="errorMessage">
        /// Output parameter, which holds error message catched during serialization.
        /// </param>
        /// <returns>
        /// True if serialization was succesfull otherwise returns false.
        /// </returns>
        public bool EvoRule(string type, int priority, List <string> leftSideList, List <string> rightSideList, out string errorMessage)
        {
            try
            {
                if (string.IsNullOrEmpty(type))
                {
                    throw new ArgumentException(ExceptionsMessage("type", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(type, Regexp.Check.String))
                {
                    throw new ArgumentException(ExceptionsMessage("type", (int)ErrorMessages.IncorectCharacters));
                }
                if (leftSideList == null || leftSideList.Count == 0)
                {
                    throw new ArgumentException(ExceptionsMessage("leftSideList", (int)ErrorMessages.EmptyList));
                }
                if (rightSideList == null || rightSideList.Count == 0)
                {
                    throw new ArgumentException(ExceptionsMessage("rightSideList", (int)ErrorMessages.EmptyList));
                }

                /*<evoRule type="2res" priority="0">
                 *  <leftside >
                 *      <object name="a"/>
                 *  </leftside>
                 *  <rightside>
                 *      <object name="p1"/>
                 *  </rightside>
                 * </evoRule>*/
                XmlElement evoRule = v_EvolutionXmlDocument.CreateElement("evoRule");
                evoRule.SetAttribute("priority", priority.ToString());
                evoRule.SetAttribute("type", type);

                XmlElement leftsideElement = (XmlElement)evoRule.AppendChild(v_EvolutionXmlDocument.CreateElement("leftside"));
                foreach (string leftSide in leftSideList)
                {
                    XmlElement leftobject = (XmlElement)leftsideElement.AppendChild(v_EvolutionXmlDocument.CreateElement("object"));
                    leftobject.SetAttribute("name", leftSide);
                }

                XmlElement rightsideElement = (XmlElement)evoRule.AppendChild(v_EvolutionXmlDocument.CreateElement("rightside"));
                foreach (string rightSide in rightSideList)
                {
                    XmlElement rightobject = (XmlElement)rightsideElement.AppendChild(v_EvolutionXmlDocument.CreateElement("object"));
                    rightobject.SetAttribute("name", rightSide);
                }

                XmlNode evoRulesWithPriority = v_EvolutionXmlDocument.SelectSingleNode("evolution/evoRulesWithPriority");
                evoRulesWithPriority?.AppendChild(evoRule);

                errorMessage = null;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
Example #9
0
 /// <summary> Construct a new <code>Regsub</code> that can be used to step
 /// through the given string, finding each substring that matches
 /// the given regular expression.
 /// <p>
 /// <code>Regexp</code> contains two substitution methods,
 /// <code>sub</code> and <code>subAll</code>, that can be used instead
 /// of <code>Regsub</code> if just simple substitutions are being done.
 ///
 /// </summary>
 /// <param name="">r
 /// The compiled regular expression.
 ///
 /// </param>
 /// <param name="">str
 /// The string to search.
 ///
 /// </param>
 /// <seealso cref="Regexp#sub">
 /// </seealso>
 /// <seealso cref="Regexp#subAll">
 /// </seealso>
 public Regsub(Regexp r, string str)
 {
     this.r      = r;
     this.str    = str;
     this.ustart = 0;
     this.mstart = -1;
     this.end    = 0;
 }
Example #10
0
 /// <summary>
 /// Construct a new <code>Regsub</code> that can be used to step
 /// through the given string, finding each substring that matches
 /// the given regular expression.
 /// <code>Regexp</code> contains two substitution methods,
 /// <code>sub</code> and <code>subAll</code>, that can be used instead
 /// of <code>Regsub</code> if just simple substitutions are being done.
 /// </summary>
 /// <param name="r">
 /// The compiled regular expression.
 /// </param>
 /// <param name="str">
 /// The string to search.
 /// </param>
 /// <seealso cref="Regexp#sub" />
 /// <seealso cref="Regexp#subAll" />
 public Regsub(Regexp r, string str)
 {
     _r      = r;
     _str    = str;
     _ustart = 0;
     _mstart = -1;
     _end    = 0;
 }
Example #11
0
        public void Scanner_MatchTest()
        {
            byte[] data = new byte[] {
                0x30, 0x34, 0x32, 0x12, 0x55, 0xC3, 0xB8, 0x34, 0x00
            };

            Regexp re = Regexp.Compile(".*55C3");

            Assert.IsTrue(re.Match(data, 0), "Should have matched");
        }
Example #12
0
        /// <summary>
        /// Creates new floating object.
        /// </summary>
        /// <param name="name">Floating object name.</param>
        /// <param name="valueOfSides">Sides value.</param>
        /// <param name="valueOfRadius">Radius value.</param>
        /// <param name="errorMessage">
        /// Output parameter, which holds error message catched during serialization.
        /// </param>
        /// <returns>
        /// True if serialization was succesfull otherwise returns false.
        /// </returns>
        public bool FloatingObjects(string name, string valueOfSides, string valueOfRadius, out string errorMessage)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentException(ExceptionsMessage("floating object", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(name, Regexp.Check.String))
                {
                    throw new ArgumentException(ExceptionsMessage("floating object", (int)ErrorMessages.IncorectCharacters));
                }
                if (string.IsNullOrEmpty(valueOfSides))
                {
                    throw new ArgumentException(ExceptionsMessage("sides", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(valueOfSides, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("sides", (int)ErrorMessages.IncorectFloatingNumber));
                }
                if (string.IsNullOrEmpty(valueOfRadius))
                {
                    throw new ArgumentException(ExceptionsMessage("radius", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(valueOfRadius, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("radius", (int)ErrorMessages.IncorectFloatingNumber));
                }

                /* <floatingObject name="a">
                 *      <sides value="5"/>
                 *      <radius value="0.05"/>
                 * </floatingObject> */
                XmlElement floatingObject = v_InventoryXmlDocument.CreateElement("floatingObject");
                floatingObject.SetAttribute("name", name);

                XmlElement sides = (XmlElement)floatingObject.AppendChild(v_InventoryXmlDocument.CreateElement("sides"));
                sides.SetAttribute("value", valueOfSides);

                XmlElement radius = (XmlElement)floatingObject.AppendChild(v_InventoryXmlDocument.CreateElement("radius"));
                radius.SetAttribute("value", valueOfRadius);

                XmlNode floatingObjects = v_InventoryXmlDocument.SelectSingleNode("inventory/mSystemDeclaration/floatingObjects");
                floatingObjects?.AppendChild(floatingObject);

                errorMessage = null;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
Example #13
0
        public void testParseInvalidRegexps()
        {
            foreach (String regexp in INVALID_REGEXPS)
            {
                try
                {
                    Regexp re = Parser.parse(regexp, RE2.PERL);
                    Assert.Fail("Parsing (PERL) " + regexp + " should have failed, instead got " + dump(re));
                }
                catch (PatternSyntaxException e)
                {
                    /* ok */
                }

                try
                {
                    Regexp re = Parser.parse(regexp, RE2.POSIX);
                    Assert.Fail("parsing (POSIX) " + regexp + " should have failed, instead got " + dump(re));
                }
                catch (PatternSyntaxException e)
                {
                    /* ok */
                }
            }

            foreach (String regexp in ONLY_PERL)
            {
                Parser.parse(regexp, RE2.PERL);
                try
                {
                    Regexp re = Parser.parse(regexp, RE2.POSIX);
                    Assert.Fail("parsing (POSIX) " + regexp + " should have failed, instead got " + dump(re));
                }
                catch (PatternSyntaxException e)
                {
                    /* ok */
                }
            }

            foreach (String regexp in ONLY_POSIX)
            {
                try
                {
                    Regexp re = Parser.parse(regexp, RE2.PERL);
                    Assert.Fail("parsing (PERL) " + regexp + " should have failed, instead got " + dump(re));
                }
                catch (PatternSyntaxException e)
                {
                    /* ok */
                }

                Parser.parse(regexp, RE2.POSIX);
            }
        }
Example #14
0
        public void RegexpTestsForDifferentInputs()
        {
            Assert.IsTrue(Regexp.CheckInputText(string.Empty, Regexp.Check.NumberOrEmptyString));
            Assert.IsTrue(Regexp.CheckInputText("123", Regexp.Check.NumberOrEmptyString));
            Assert.IsFalse(Regexp.CheckInputText("1 23", Regexp.Check.NumberOrEmptyString));

            Assert.IsTrue(Regexp.CheckInputText(string.Empty, Regexp.Check.FloatingNumberOrEmptyString));
            Assert.IsTrue(Regexp.CheckInputText("123.5", Regexp.Check.FloatingNumberOrEmptyString));
            Assert.IsFalse(Regexp.CheckInputText("1 23.5", Regexp.Check.FloatingNumberOrEmptyString));

            Assert.IsTrue(Regexp.CheckInputText(string.Empty, Regexp.Check.StringOrEmptyString));
            Assert.IsTrue(Regexp.CheckInputText("test", Regexp.Check.StringOrEmptyString));
            Assert.IsFalse(Regexp.CheckInputText("test test", Regexp.Check.StringOrEmptyString));
        }
Example #15
0
        public void Scanner_BuildExpr()
        {
            Regexp re;

            re = Regexp.Compile("11.22");
            Debug.WriteLine(re);
            re = Regexp.Compile("34+32+33");
            Debug.WriteLine(re);
            re = Regexp.Compile(".*11221122");
            Debug.WriteLine(re);
            re = Regexp.Compile("11(22|23)*44");
            Assert.IsTrue(re.Match(new Byte[] { 0x11, 0x22, 0x22, 0x23, 0x44 }, 0));
            re = Regexp.Compile("(B8|B9)*0204");
            Assert.IsTrue(re.Match(new Byte[] { 0xB8, 0x02, 0x04 }, 0));
            re = Regexp.Compile("C390*");
            Assert.IsTrue(re.Match(new Byte[] { 0xC3, 0x90, 0x90, 0x90, 0xB8 }, 0));
        }
        /// <summary>
        /// Creates new glueTuple element.
        /// </summary>
        /// <param name="protein1">Name of the protein1.</param>
        /// <param name="protein2">Name of the protein2.</param>
        /// <param name="signalM">Signal M set string.</param>
        /// <param name="errorMessage">
        /// Used as error output if exception is caught.
        /// </param>
        /// <returns>
        /// True if serialization was succesfull otherwise returns false.
        /// </returns>
        public bool GlueRelation(string protein1, string protein2, string signalM, out string errorMessage)
        {
            try
            {
                if (string.IsNullOrEmpty(protein1))
                {
                    throw new ArgumentException(ExceptionsMessage("protein1", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(protein1, Regexp.Check.StringWithApostroph))
                {
                    throw new ArgumentException(ExceptionsMessage("protein1", (int)ErrorMessages.IncorectCharactersWithApostroph));
                }
                if (string.IsNullOrEmpty(protein2))
                {
                    throw new ArgumentException(ExceptionsMessage("protein2", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(protein2, Regexp.Check.StringWithApostroph))
                {
                    throw new ArgumentException(ExceptionsMessage("protein2", (int)ErrorMessages.IncorectCharactersWithApostroph));
                }
                if (!Regexp.CheckInputText(signalM, Regexp.Check.String))
                {
                    throw new ArgumentException(ExceptionsMessage("protein1", (int)ErrorMessages.IncorectCharacters));
                }

                // <glueTuple protein1="p0" protein2="p2" signalMset=""/>
                XmlElement glueTuple = v_EvolutionXmlDocument.CreateElement("glueTuple");
                glueTuple.SetAttribute("signalMset", signalM);
                glueTuple.SetAttribute("protein2", protein2);
                glueTuple.SetAttribute("protein1", protein1);

                XmlNode glueRelations = v_EvolutionXmlDocument.SelectSingleNode("evolution/glueRelations");
                glueRelations?.AppendChild(glueTuple);

                errorMessage = null;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
Example #17
0
 // Test Parse -> Dump.
 private void testParseDump(String[][] tests, int flags)
 {
     foreach (String[] test in tests)
     {
         try
         {
             Regexp re = Parser.parse(test[0], flags);
             String d  = dump(re);
             if (!test[1].Equals(d))
             {
                 Assert.Fail("parse/dump of " + test[0] + " expected " + test[1] + ", got " + d);
             }
         }
         catch (PatternSyntaxException e)
         {
             throw new Exception("Parsing failed: " + test[0], e);
         }
     }
 }
Example #18
0
        private static String mkCharClass(RunePredicate f)
        {
            Regexp     re    = new Regexp(Regexp.Op.CHAR_CLASS);
            List <int> runes = new List <int>();
            int        lo    = -1;

            for (int i = 0; i <= Unicode.MAX_RUNE; i++)
            {
                if (f(i))
                {
                    if (lo < 0)
                    {
                        lo = i;
                    }
                }
                else
                {
                    if (lo >= 0)
                    {
                        runes.Add(lo);
                        runes.Add(i - 1);
                        lo = -1;
                    }
                }
            }

            if (lo >= 0)
            {
                runes.Add(lo);
                runes.Add(Unicode.MAX_RUNE);
            }

            re.runes = new int[runes.Count];
            int j = 0;

            foreach (int i in runes)
            {
                re.runes[j++] = i;
            }

            return(dump(re));
        }
Example #19
0
        // ---- parse & validate ------------------------

        /// <summary>
        /// Creates a new URI from a string, e.g. `http://www.msft.com/some/path`,
        /// `file:///usr/home`, or `scheme:with/path`.
        ///
        /// @param value A string which represents an URI (see `URI#toString`).
        /// </summary>
        public static DocumentUri Parse(string value, bool strict = false)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new UriFormatException("Given uri is null or empty");
            }
            var match = Regexp.Match(value);

            if (!match.Success)
            {
                return(new DocumentUri(Empty, Empty, Empty, Empty, Empty));
            }

            return(new DocumentUri(
                       match.Groups[2].Value ?? Empty,
                       PercentDecode(match.Groups[4].Value ?? Empty),
                       PercentDecode(match.Groups[5].Value ?? Empty),
                       PercentDecode(match.Groups[7].Value ?? Empty),
                       PercentDecode(match.Groups[9].Value ?? Empty),
                       strict
                       ));
        }
Example #20
0
        //[TestMethod]
        //public void Test29()
        //{
        //    runTest("Test29");
        //}

        private void runTest(string testName)
        {
            CharSetSolver solver = new CharSetSolver(BitWidth.BV64);
            var           dfa_al = ReadDFA(testName, solver);

            Regexp        regexp = null;
            StringBuilder sb     = new StringBuilder();

            sb.AppendLine("*------------------------------------");
            sb.AppendLine("| " + testName);
            sb.AppendLine("|------------------------------------");

            foreach (var r in RegexpSynthesis.SynthesizeRegexp(dfa_al.First, dfa_al.Second, solver, sb, timeout))
            {
                regexp = r;
                break;
            }

            sb.AppendLine("*------------------------------------");
            sb.AppendLine();

            System.Console.WriteLine(sb);
        }
Example #21
0
        public bool Equals(CustomField other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Id == other.Id &&
                   IsFilter == other.IsFilter &&
                   IsRequired == other.IsRequired &&
                   Multiple == other.Multiple &&
                   Searchable == other.Searchable &&
                   Visible == other.Visible &&
                   CustomizedType.Equals(other.CustomizedType) &&
                   DefaultValue.Equals(other.DefaultValue) &&
                   FieldFormat.Equals(other.FieldFormat) &&
                   MaxLength == other.MaxLength &&
                   MinLength == other.MinLength &&
                   Name.Equals(other.Name) &&
                   Regexp.Equals(other.Regexp) &&
                   PossibleValues.Equals(other.PossibleValues) &&
                   Roles.Equals(other.Roles) &&
                   Trackers.Equals(other.Trackers));
        }
 private static bool CorrectOnPosSet(Regexp regexp, IEnumerable<string> testSet)
 {
     foreach (var test in testSet)
         if (!regexp.HasModel(test))
         {
             return false;
         }
     return true;
 }
 public static void SetRegexp(DependencyObject d, Regexp value)
 {
     d.SetValue(RegexpProperty, value);
 }
Example #24
0
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            bool nocase  = false;
            bool indices = false;

            try
            {
                int i = 1;

                while (argv[i].ToString().StartsWith("-"))
                {
                    int index = TclIndex.Get(interp, argv[i], validOpts, "switch", 0);
                    i++;
                    switch (index)
                    {
                    case OPT_INDICES:
                    {
                        indices = true;
                        break;
                    }

                    case OPT_NOCASE:
                    {
                        nocase = true;
                        break;
                    }

                    case OPT_LAST:
                    {
                        goto opts_brk;
                    }
                    }
                }

opts_brk:
                ;


                TclObject exp = TclString.NewInstance(argv[i++].ToString().Replace("\\d", "[0-9]"));

                string inString = argv[i++].ToString();

                int matches = argv.Length - i;

                Regexp r = TclRegexp.compile(interp, exp, nocase);

                int[] args    = new int[matches * 2];
                bool  matched = r.match(inString, args);
                if (matched)
                {
                    for (int match = 0; i < argv.Length; i++)
                    {
                        TclObject obj;

                        int start = args[match++];
                        int end   = args[match++];
                        if (indices)
                        {
                            if (end >= 0)
                            {
                                end--;
                            }
                            obj = TclList.NewInstance();
                            TclList.Append(interp, obj, TclInteger.NewInstance(start));
                            TclList.Append(interp, obj, TclInteger.NewInstance(end));
                        }
                        else
                        {
                            string range = (start >= 0) ? inString.Substring(start, (end) - (start)) : "";
                            obj = TclString.NewInstance(range);
                        }
                        try
                        {
                            interp.SetVar(argv[i].ToString(), obj, 0);
                        }
                        catch (TclException e)
                        {
                            throw new TclException(interp, "couldn't set variable \"" + argv[i] + "\"");
                        }
                    }
                }
                interp.SetResult(matched);
            }
            catch (System.IndexOutOfRangeException e)
            {
                throw new TclNumArgsException(interp, 1, argv, "?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?");
            }
            return(TCL.CompletionCode.RETURN);
        }
        public bool Equals(ContentTypeProperty input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     Name == input.Name ||
                     (Name != null && Name.Equals(input.Name))
                     ) &&
                 (
                     RootPropertyName == input.RootPropertyName ||
                     (RootPropertyName != null && RootPropertyName.Equals(input.RootPropertyName))
                 ) &&
                 (
                     ReadableName == input.ReadableName ||
                     (ReadableName != null && ReadableName.Equals(input.ReadableName))
                 ) &&
                 (
                     Value == input.Value ||
                     (Value != null && Value.Equals(input.Value))
                 ) &&
                 (
                     PropertyDescription == input.PropertyDescription ||
                     (PropertyDescription != null && PropertyDescription.Equals(input.PropertyDescription))
                 ) &&
                 (
                     Localizable == input.Localizable ||
                     (Localizable != null && Localizable.Equals(input.Localizable))
                 ) &&
                 (
                     Fallback == input.Fallback ||
                     (Fallback != null && Fallback.Equals(input.Fallback))
                 ) &&
                 (
                     Enabled == input.Enabled ||
                     (Enabled != null && Enabled.Equals(input.Enabled))
                 ) &&
                 (
                     Order == input.Order ||
                     (Order.Equals(input.Order))
                 ) &&
                 (
                     Visible == input.Visible ||
                     (Visible != null && Visible.Equals(input.Visible))
                 ) &&
                 (
                     IsTitle == input.IsTitle ||
                     (IsTitle != null && IsTitle.Equals(input.IsTitle))
                 ) &&
                 (
                     Required == input.Required ||
                     (Required != null && Required.Equals(input.Required))
                 ) &&
                 (
                     MaxLength == input.MaxLength ||
                     (MaxLength.Equals(input.MaxLength))
                 ) &&
                 (
                     MaxByteLength == input.MaxByteLength ||
                     (MaxByteLength.Equals(input.MaxByteLength))
                 ) &&
                 (
                     MaxFileSize == input.MaxFileSize ||
                     (MaxFileSize.Equals(input.MaxFileSize))
                 ) &&
                 (
                     Regexp == input.Regexp ||
                     (Regexp != null && Regexp.Equals(input.Regexp))
                 ) &&
                 (
                     ValidateAs == input.ValidateAs ||
                     (ValidateAs != null && ValidateAs.Equals(input.ValidateAs))
                 ) &&
                 (
                     RssAttribute == input.RssAttribute ||
                     (RssAttribute != null && RssAttribute.Equals(input.RssAttribute))
                 ) &&
                 (
                     VisibleDependency == input.VisibleDependency ||
                     (VisibleDependency != null && VisibleDependency.Equals(input.VisibleDependency))
                 ) &&
                 (
                     VisibleOn == input.VisibleOn ||
                     (VisibleOn != null && VisibleOn.Equals(input.VisibleOn))
                 ) &&
                 (
                     Datatype == input.Datatype ||
                     (Datatype != null && Datatype.Equals(input.Datatype))
                 ) &&
                 (
                     Attributes == input.Attributes ||
                     (Attributes != null && Attributes.SequenceEqual(input.Attributes))
                 ) &&
                 (
                     ChildProperties == input.ChildProperties ||
                     (ChildProperties != null && ChildProperties.SequenceEqual(input.ChildProperties))
                 ) &&
                 (
                     ContentTypeAllowed == input.ContentTypeAllowed ||
                     (ContentTypeAllowed != null && ContentTypeAllowed.Equals(input.ContentTypeAllowed))
                 ) &&
                 (
                     BindToProperty == input.BindToProperty ||
                     (BindToProperty != null && BindToProperty.Equals(input.BindToProperty))
                 ) &&
                 (
                     BoundRegex == input.BoundRegex ||
                     (BoundRegex != null && BoundRegex.Equals(input.BoundRegex))
                 ) &&
                 (
                     RepresentationSelection == input.RepresentationSelection ||
                     (RepresentationSelection != null && RepresentationSelection.SequenceEqual(input.RepresentationSelection))
                 ) &&
                 (
                     DefaultValues == input.DefaultValues ||
                     (DefaultValues != null && DefaultValues.SequenceEqual(input.DefaultValues))
                 ) &&
                 (
                     IsExternalAllowed == input.IsExternalAllowed ||
                     (IsExternalAllowed != null && IsExternalAllowed.Equals(input.IsExternalAllowed))
                 ) &&
                 (
                     PropertySection == input.PropertySection ||
                     (PropertySection != null && PropertySection.Equals(input.PropertySection))
                 ) &&
                 (
                     Weight == input.Weight ||
                     (Weight.Equals(input.Weight))
                 ) &&
                 (
                     Entitytype == input.Entitytype ||
                     (Entitytype != null && Entitytype.Equals(input.Entitytype))
                 ) &&
                 (
                     IsCombo == input.IsCombo ||
                     (IsCombo != null && IsCombo.Equals(input.IsCombo))
                 ) &&
                 (
                     SuppressProperty == input.SuppressProperty ||
                     (SuppressProperty != null && SuppressProperty.Equals(input.SuppressProperty))
                 ) &&
                 (
                     LegalContentTypes == input.LegalContentTypes ||
                     (LegalContentTypes != null && LegalContentTypes.SequenceEqual(input.LegalContentTypes))
                 ) &&
                 (
                     RepresentationValidationString == input.RepresentationValidationString ||
                     (RepresentationValidationString != null && RepresentationValidationString.Equals(input.RepresentationValidationString))
                 ) &&
                 (
                     MinWidth == input.MinWidth ||
                     (MinWidth.Equals(input.MinWidth))
                 ) &&
                 (
                     MaxWidth == input.MaxWidth ||
                     (MaxWidth.Equals(input.MaxWidth))
                 ) &&
                 (
                     MinHeight == input.MinHeight ||
                     (MinHeight.Equals(input.MinHeight))
                 ) &&
                 (
                     MaxHeight == input.MaxHeight ||
                     (MaxHeight.Equals(input.MaxHeight))
                 ) &&
                 (
                     IsVideo == input.IsVideo ||
                     (IsVideo != null && IsVideo.Equals(input.IsVideo))
                 ) &&
                 (
                     IsImage == input.IsImage ||
                     (IsImage != null && IsImage.Equals(input.IsImage))
                 ));
        }
Example #26
0
        /// <summary>
        /// Creates new initial object element.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="posX">Parameter posX.</param>
        /// <param name="posY">Parameter posY.</param>
        /// <param name="posZ">Parameter posZ.</param>
        /// <param name="angleX">Parameter angleX.</param>
        /// <param name="angleY">Parameter angleY.</param>
        /// <param name="angleZ">Parameter angleZ.</param>
        /// <param name="errorMessage">
        /// Output parameter, which holds error message catched during serialization.
        /// </param>
        /// <returns>
        /// True if serialization was succesfull otherwise returns false.
        /// </returns>
        public bool SeedTiles(string name, string posX, string posY, string posZ, string angleX, string angleY, string angleZ, out string errorMessage)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentException(ExceptionsMessage("name", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(name, Regexp.Check.String))
                {
                    throw new ArgumentException(ExceptionsMessage("name", (int)ErrorMessages.IncorectCharacters));
                }
                if (string.IsNullOrEmpty(posX))
                {
                    throw new ArgumentException(ExceptionsMessage("posX", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(posX, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("posX", (int)ErrorMessages.IncorectFloatingNumber));
                }
                if (string.IsNullOrEmpty(posY))
                {
                    throw new ArgumentException(ExceptionsMessage("posY", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(posY, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("posY", (int)ErrorMessages.IncorectFloatingNumber));
                }
                if (string.IsNullOrEmpty(posZ))
                {
                    throw new ArgumentException(ExceptionsMessage("posZ", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(posZ, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("posZ", (int)ErrorMessages.IncorectFloatingNumber));
                }
                if (string.IsNullOrEmpty(angleX))
                {
                    throw new ArgumentException(ExceptionsMessage("angleX", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(angleX, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("angleX", (int)ErrorMessages.IncorectFloatingNumber));
                }
                if (string.IsNullOrEmpty(angleY))
                {
                    throw new ArgumentException(ExceptionsMessage("angleY", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(angleY, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("angleY", (int)ErrorMessages.IncorectFloatingNumber));
                }
                if (string.IsNullOrEmpty(angleZ))
                {
                    throw new ArgumentException(ExceptionsMessage("angleZ", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(angleZ, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("angleZ", (int)ErrorMessages.IncorectFloatingNumber));
                }

                /* <initialObject name="q2">
                 *      <posX value="0"/>
                 *      <posY value="0"/>
                 *      <posZ value="-16.18"/>
                 *      <angleX value="0"/>
                 *      <angleY value="0"/>
                 *      <angleZ value="0"/>
                 * </initialObject> */
                XmlElement seedTile = v_InventoryXmlDocument.CreateElement("initialObject");
                seedTile.SetAttribute("name", name);

                XmlElement posXElement = (XmlElement)seedTile.AppendChild(v_InventoryXmlDocument.CreateElement("posX"));
                posXElement.SetAttribute("value", posX);
                XmlElement posYElement = (XmlElement)seedTile.AppendChild(v_InventoryXmlDocument.CreateElement("posY"));
                posYElement.SetAttribute("value", posY);
                XmlElement posZElement = (XmlElement)seedTile.AppendChild(v_InventoryXmlDocument.CreateElement("posZ"));
                posZElement.SetAttribute("value", posZ);
                XmlElement angleXElement = (XmlElement)seedTile.AppendChild(v_InventoryXmlDocument.CreateElement("angleX"));
                angleXElement.SetAttribute("value", angleX);
                XmlElement angleYElement = (XmlElement)seedTile.AppendChild(v_InventoryXmlDocument.CreateElement("angleY"));
                angleYElement.SetAttribute("value", angleY);
                XmlElement angleZElement = (XmlElement)seedTile.AppendChild(v_InventoryXmlDocument.CreateElement("angleZ"));
                angleZElement.SetAttribute("value", angleZ);

                XmlNode seedTiles = v_InventoryXmlDocument.SelectSingleNode("inventory/mSystemDeclaration/initialObjects");
                seedTiles?.AppendChild(seedTile);

                errorMessage = null;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
        public static IEnumerable<Regexp> SynthesizeRegexp(HashSet<char> alphabet, Automaton<BDD> dfa, CharSetSolver s, StringBuilder sb, long timeout)
        {
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"..\..\..\regexpenum.txt"))
            {
                solver = s;
                numStates = dfa.StateCount;
                alph = alphabet;

                #region test variables
                StringBuilder sb1 = new StringBuilder();
                int lim = 0;
                Stopwatch membershipTimer = new Stopwatch();
                Stopwatch equivTimer = new Stopwatch();
                timer = new Stopwatch();
                timer.Start();
                #endregion


                #region TestSets for equiv
                var mytests = DFAUtilities.MyHillTestGeneration(alphabet, dfa, solver);
                var posMN = mytests.First;
                var negMN = mytests.Second;
                var tests = DFAUtilities.GetTestSets(dfa, alphabet, solver);
                var positive = tests.First;
                var negative = tests.Second;
                foreach (var t in posMN)
                    positive.Remove(t);
                foreach (var t in negMN)
                    negative.Remove(t);
                #endregion

                #region Sigma Star
                bool fst = true;
                foreach (var c in alph)
                    if (fst)
                    {
                        fst = false;
                        sigmaStar = new RELabel(c);
                    }
                    else
                        sigmaStar = new REUnion(sigmaStar, new RELabel(c));
                
                sigmaPlus = new REPlus(sigmaStar);
                sigmaStar = new REStar(sigmaStar); 
                #endregion                

                #region Accessories vars
                maxWidthC = 0;
                maxSigmaStarC = 0;
                var isSubset = true;
                HashSet<string> visited = new HashSet<string>();
                HashSet<string> newReg = new HashSet<string>();
                currUnionEls = new Dictionary<string,Automaton<BDD>>();
                memoDfa = new Dictionary<string, Automaton<BDD>>(); 
                List<Regexp> subsetReg = new List<Regexp>();
                #endregion

                for (maxWidth = 1; true; maxWidth++)
                {
                    newReg = new HashSet<string>();
                    maxSigmaStar = 2;

                    foreach (var regexp in EnumerateRegexp())
                    {
                        #region run for at most timeout
                        if (timer.ElapsedMilliseconds > timeout)
                        {
                            sb.AppendLine("| Timeout");
                            timer.Stop();
                            yield break;
                        }
                        #endregion

                        var re = regexp.Normalize();

                        if (!(visited.Contains(re.ToString())))
                        {
                            visited.Add(re.ToString());

                            sb1 = new StringBuilder();
                            sb1.Append(re.ToString());
                            file.WriteLine(sb1);
                            lim++;

                            #region Membership test
                            membershipTimer.Start();
                            isSubset = CorrectOnNegSet(regexp, negMN);
                            membershipTimer.Stop();
                            #endregion

                            #region equivalence check
                            if (isSubset)
                            {
                                membershipTimer.Start();
                                if (CorrectOnNegSet(regexp, negative))
                                {
                                    if (CorrectOnPosSet(regexp, posMN) && CorrectOnPosSet(regexp, positive))
                                    {
                                        membershipTimer.Stop();
                                        equivTimer.Start();
                                        var rDfa = getDfa(regexp);
                                        memoDfa[regexp.ToString()] = rDfa;

                                        if (rDfa.IsEquivalentWith(dfa, solver))
                                        {
                                            isSubset = false;
                                            equivTimer.Stop();
                                            timer.Stop();

                                            sb.Append("| ");
                                            regexp.ToString(sb);
                                            sb.AppendLine("|");
                                            sb.AppendLine(string.Format("| elapsed time:    \t {0} ms", timer.ElapsedMilliseconds));
                                            sb.AppendLine(string.Format("| equivalence cost:\t {0} ms", equivTimer.ElapsedMilliseconds));
                                            sb.AppendLine(string.Format("| membership cost: \t {0} ms", membershipTimer.ElapsedMilliseconds));
                                            sb.AppendLine(string.Format("| attempts:        \t {0}", lim));
                                            yield return regexp;
                                        }
                                        else
                                        {
                                            Console.WriteLine("used dfa");
                                            equivTimer.Stop();
                                        }
                                    }
                                    else
                                    {
                                        membershipTimer.Stop();
                                    }
                                }
                                else
                                {
                                    membershipTimer.Stop();
                                    isSubset = false;
                                }
                            }
                            #endregion

                            //#region Subsets
                            //if (isSubset)
                            //{
                            //    foreach (var reg1 in subsetReg)
                            //    {
                            //        var union = (reg1.CompareTo(regexp) > 0) ? (new REUnion(reg1, regexp)) : (new REUnion(regexp, reg1));
                            //        visited.Add(union.ToString());
                            //        sb1 = new StringBuilder();
                            //        sb1.Append(union + " From union");
                            //        file.WriteLine(sb1);
                            //        lim++;

                            //        membershipTimer.Start();
                            //        if (CorrectOnPosSet(union, posMN) && CorrectOnPosSet(union, positive))
                            //        {
                            //            membershipTimer.Stop();

                            //            equivTimer.Start();
                            //            var rDfa = getDfa(union);
                            //            memoDfa[union.ToString()] = rDfa;

                            //            if (rDfa.IsEquivalentWith(dfa, solver))
                            //            {
                            //                equivTimer.Stop();
                            //                timer.Stop();

                            //                sb.Append("| ");
                            //                union.ToString(sb);
                            //                sb.AppendLine("|");
                            //                sb.AppendLine(string.Format("| elapsed time:    \t {0} ms", timer.ElapsedMilliseconds));
                            //                sb.AppendLine(string.Format("| equivalence cost:\t {0} ms", equivTimer.ElapsedMilliseconds));
                            //                sb.AppendLine(string.Format("| membership cost: \t {0} ms", membershipTimer.ElapsedMilliseconds));
                            //                sb.AppendLine(string.Format("| attempts:        \t {0}", lim));
                            //                yield return union;
                            //            }
                            //            else
                            //            {
                            //                Console.WriteLine("used dfa");
                            //                equivTimer.Stop();
                            //            }
                            //        }
                            //        else
                            //        {
                            //            membershipTimer.Stop();
                            //        }
                            //    }
                            //    subsetReg.Add(regexp);
                            //}
                            //#endregion
                        }
                    }

                    visited = new HashSet<string>(visited.Union(newReg));
                }
            }
        }
Example #28
0
        internal static bool regExpMatch(Interp interp, string inString, TclObject pattern)
        {
            Regexp r = TclRegexp.compile(interp, pattern, false);

            return(r.match(inString, (string[])null));
        }
Example #29
0
        // dumpRegexp writes an encoding of the syntax tree for the regexp |re|
        // to |b|.  It is used during testing to distinguish between parses that
        // might print the same using re's toString() method.
        private static void dumpRegexp(StringBuilder b, Regexp re)
        {
            OP_NAMES.TryGetValue(re.op, out string name);
            if (name == null)
            {
                b.Append("op").Append(re.op);
            }
            else
            {
                switch (re.op)
                {
                case Regexp.Op.STAR:
                case Regexp.Op.PLUS:
                case Regexp.Op.QUEST:
                case Regexp.Op.REPEAT:
                    if ((re.flags & RE2.NON_GREEDY) != 0)
                    {
                        b.Append('n');
                    }

                    b.Append(name);
                    break;

                case Regexp.Op.LITERAL:
                    if (re.runes.Length > 1)
                    {
                        b.Append("str");
                    }
                    else
                    {
                        b.Append("lit");
                    }

                    if ((re.flags & RE2.FOLD_CASE) != 0)
                    {
                        foreach (int r in re.runes)
                        {
                            if (Unicode.simpleFold(r) != r)
                            {
                                b.Append("fold");
                                break;
                            }
                        }
                    }

                    break;

                default:
                    b.Append(name);
                    break;
                }
            }

            b.Append('{');
            switch (re.op)
            {
            case Regexp.Op.END_TEXT:
                if ((re.flags & RE2.WAS_DOLLAR) == 0)
                {
                    b.Append("\\z");
                }

                break;

            case Regexp.Op.LITERAL:
                foreach (int r in re.runes)
                {
                    // Extremely painful Dot NET!
                    // Convert UTF-32 character to a UTF-16 String.
                    var strC = Char.ConvertFromUtf32(r);
                    b.Append(strC);
                }

                break;

            case Regexp.Op.CONCAT:
            case Regexp.Op.ALTERNATE:
                foreach (Regexp sub in re.subs)
                {
                    dumpRegexp(b, sub);
                }

                break;

            case Regexp.Op.STAR:
            case Regexp.Op.PLUS:
            case Regexp.Op.QUEST:
                dumpRegexp(b, re.subs[0]);
                break;

            case Regexp.Op.REPEAT:
                b.Append(re.min).Append(',').Append(re.max).Append(' ');
                dumpRegexp(b, re.subs[0]);
                break;

            case Regexp.Op.CAPTURE:
                if (re.name != null && re.name.Length != 0)
                {
                    b.Append(re.name);
                    b.Append(':');
                }

                dumpRegexp(b, re.subs[0]);
                break;

            case Regexp.Op.CHAR_CLASS:
            {
                String sep = "";
                for (int i = 0; i < re.runes.Length; i += 2)
                {
                    b.Append(sep);
                    sep = " ";
                    int lo = re.runes[i], hi = re.runes[i + 1];
                    if (lo == hi)
                    {
                        b.Append(String.Format("0x{0:x}", lo));
                    }
                    else
                    {
                        b.Append(String.Format("0x{0:x}-0x{1:x}", lo, hi));
                    }
                }

                break;
            }
            }

            b.Append('}');
        }
Example #30
0
        /// <summary>
        /// Creates new tile element.
        /// </summary>
        /// <param name="tileName">Tile name.</param>
        /// <param name="polygonSides">Polygon sides value.</param>
        /// <param name="polygonVertexDistance">Polygon vertex distance value.</param>
        /// <param name="polygonAngle">Polygon angle value.</param>
        /// <param name="positionsList">List of positions.</param>
        /// <param name="connectorList">List of connectors.</param>
        /// <param name="surfaceGluen">Surface glue value.</param>
        /// <param name="proteinsList">List of proteins.</param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public bool Tiles(string tileName, string polygonSides, string polygonVertexDistance, string polygonAngle, List <Positions> positionsList, List <Connect> connectorList, string surfaceGluen, List <string> proteinsList, out string errorMessage)
        {
            try
            {
                if (string.IsNullOrEmpty(tileName))
                {
                    throw new ArgumentException(ExceptionsMessage("tileName", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(tileName, Regexp.Check.String))
                {
                    throw new ArgumentException(ExceptionsMessage("tileName", (int)ErrorMessages.IncorectCharacters));
                }
                if (string.IsNullOrEmpty(polygonSides))
                {
                    throw new ArgumentException(ExceptionsMessage("polygonSides", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(polygonSides, Regexp.Check.Number))
                {
                    throw new ArgumentException(ExceptionsMessage("polygonSides", (int)ErrorMessages.IncorectNumber));
                }
                if (string.IsNullOrEmpty(polygonVertexDistance))
                {
                    throw new ArgumentException(ExceptionsMessage("polygonVertexDistance", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(polygonVertexDistance, Regexp.Check.Number))
                {
                    throw new ArgumentException(ExceptionsMessage("polygonVertexDistance", (int)ErrorMessages.IncorectNumber));
                }
                if (string.IsNullOrEmpty(polygonAngle))
                {
                    throw new ArgumentException(ExceptionsMessage("polygonAngle", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(polygonAngle, Regexp.Check.FloatingNumber))
                {
                    throw new ArgumentException(ExceptionsMessage("polygonAngle", (int)ErrorMessages.IncorectFloatingNumber));
                }
                if (string.IsNullOrEmpty(surfaceGluen))
                {
                    throw new ArgumentException(ExceptionsMessage("surfaceGlue", (int)ErrorMessages.IsNullOrEmpty));
                }
                if (!Regexp.CheckInputText(surfaceGluen, Regexp.Check.String))
                {
                    throw new ArgumentException(ExceptionsMessage("surfaceGlue", (int)ErrorMessages.IncorectCharacters));
                }
                if (connectorList.Count == 0)
                {
                    throw new ArgumentException(ExceptionsMessage("connectorList", (int)ErrorMessages.EmptyList));
                }

                XmlElement xmlTiles = v_InventoryXmlDocument.CreateElement("tile");
                xmlTiles.SetAttribute("name", tileName);

                XmlElement polygon = (XmlElement)xmlTiles.AppendChild(v_InventoryXmlDocument.CreateElement("polygon"));
                XmlElement sides   = (XmlElement)polygon.AppendChild(v_InventoryXmlDocument.CreateElement("sides"));
                sides.SetAttribute("value", polygonSides);
                XmlElement vertexDistance = (XmlElement)polygon.AppendChild(v_InventoryXmlDocument.CreateElement("vertexDistance"));
                vertexDistance.SetAttribute("value", polygonVertexDistance);
                XmlElement angleElement = (XmlElement)polygon.AppendChild(v_InventoryXmlDocument.CreateElement("angleElement"));
                angleElement.SetAttribute("value", polygonAngle);

                if (positionsList.Count != 0)
                {
                    XmlElement positions = (XmlElement)xmlTiles.AppendChild(v_InventoryXmlDocument.CreateElement("positions"));
                    foreach (Positions posit in positionsList)
                    {
                        XmlElement position = (XmlElement)positions.AppendChild(v_InventoryXmlDocument.CreateElement("position"));
                        position.SetAttribute("name", posit.PositionName);
                        XmlElement positionPosX = (XmlElement)position.AppendChild(v_InventoryXmlDocument.CreateElement("posX"));
                        positionPosX.SetAttribute("value", posit.PositionPosX.ToString(CultureInfo.InvariantCulture));
                        XmlElement positionPosY = (XmlElement)position.AppendChild(v_InventoryXmlDocument.CreateElement("posY"));
                        positionPosY.SetAttribute("value", posit.PositionPosY.ToString(CultureInfo.InvariantCulture));
                        XmlElement positionPosZ = (XmlElement)position.AppendChild(v_InventoryXmlDocument.CreateElement("posZ"));
                        positionPosZ.SetAttribute("value", posit.PositionPosZ.ToString(CultureInfo.InvariantCulture));
                    }
                }

                XmlElement connectors = (XmlElement)xmlTiles.AppendChild(v_InventoryXmlDocument.CreateElement("connectors"));
                foreach (Connect connect in connectorList)
                {
                    XmlElement connector = (XmlElement)connectors.AppendChild(v_InventoryXmlDocument.CreateElement("connector"));
                    connector.SetAttribute("name", connect.ConnectorAngle);

                    XmlElement connectorPositions = (XmlElement)connector.AppendChild(v_InventoryXmlDocument.CreateElement("positions"));

                    foreach (string position in connect.ConnectorPosition)
                    {
                        XmlElement connectorPosition = (XmlElement)connectorPositions.AppendChild(v_InventoryXmlDocument.CreateElement("position"));
                        connectorPosition.SetAttribute("name", position);
                    }

                    XmlElement protein = (XmlElement)connector.AppendChild(v_InventoryXmlDocument.CreateElement("protein"));
                    protein.SetAttribute("name", connect.ConnectorProtein);

                    if (connect.ConnectorAngle != string.Empty)
                    {
                        XmlElement angle = (XmlElement)connector.AppendChild(v_InventoryXmlDocument.CreateElement("angle"));
                        angle.SetAttribute("value", connect.ConnectorAngle.ToString(CultureInfo.InvariantCulture));
                    }
                }

                XmlElement surfaceGlue = (XmlElement)xmlTiles.AppendChild(v_InventoryXmlDocument.CreateElement("surfaceGlue"));
                surfaceGlue.SetAttribute("name", surfaceGluen);

                XmlElement proteins = (XmlElement)xmlTiles.AppendChild(v_InventoryXmlDocument.CreateElement("proteins"));
                if (proteinsList.Count != 0)
                {
                    foreach (string protein in proteinsList)
                    {
                        XmlElement proteinsProtein = (XmlElement)proteins.AppendChild(v_InventoryXmlDocument.CreateElement("protein"));
                        proteinsProtein.SetAttribute("name", protein);
                    }
                }

                XmlNode tiles = v_InventoryXmlDocument.SelectSingleNode("inventory/mSystemDeclaration/fixedObjects");
                tiles?.AppendChild(xmlTiles);
                errorMessage = null;
                return(true);
            }
            catch (Exception exception)
            {
                errorMessage = exception.Message;
                return(false);
            }
        }
Example #31
0
        public TCL.CompletionCode CmdProc(Interp interp, TclObject[] argv)
        {
            bool all    = false;
            bool nocase = false;

            try
            {
                int i = 1;

                while (argv[i].ToString().StartsWith("-"))
                {
                    int index = TclIndex.Get(interp, argv[i], validOpts, "switch", 0);
                    i++;
                    switch (index)
                    {
                    case OPT_ALL:
                    {
                        all = true;
                        break;
                    }

                    case OPT_NOCASE:
                    {
                        nocase = true;
                        break;
                    }

                    case OPT_LAST:
                    {
                        goto opts_brk;
                    }
                    }
                }

opts_brk:
                ;


                TclObject exp = argv[i++];

                string inString = argv[i++].ToString();

                string subSpec = argv[i++].ToString();

                string varName = null;
                if (i != argv.Length)
                {
                    varName = argv[i++].ToString();
                }
                if (i != argv.Length)
                {
                    throw new System.IndexOutOfRangeException();
                }

                Regexp r = TclRegexp.compile(interp, exp, nocase);

                int    count = 0;
                string result;

                if (all == false)
                {
                    result = r.sub(inString, subSpec);
                    if ((System.Object)result == null)
                    {
                        result = inString;
                    }
                    else
                    {
                        count++;
                    }
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    Regsub        s  = new Regsub(r, inString);
                    while (s.nextMatch())
                    {
                        count++;
                        sb.Append(s.skipped());
                        Regexp.applySubspec(s, subSpec, sb);
                    }
                    sb.Append(s.rest());
                    result = sb.ToString();
                }

                TclObject obj = TclString.NewInstance(result);
                if (varName == null)
                {
                    interp.SetResult(result);
                }
                else
                {
                    try
                    {
                        interp.SetVar(varName, obj, 0);
                    }
                    catch (TclException e)
                    {
                        throw new TclException(interp, "couldn't set variable \"" + varName + "\"");
                    }
                    interp.SetResult(count);
                }
            }
            catch (System.IndexOutOfRangeException e)
            {
                throw new TclNumArgsException(interp, 1, argv, "?switches? exp string subSpec ?varName?");
            }
            return(TCL.CompletionCode.RETURN);
        }
 private static Automaton<BDD> getDfa(Regexp regexp)
 {
     var re = regexp.Normalize();
     if (!memoDfa.Keys.Contains(re.ToString()))             
         memoDfa[re.ToString()] = re.getDFA(alph,solver);
      
     return memoDfa[re.ToString()];
 }