Example #1
0
 /// <summary>
 /// 将二进制转成字符串
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public static string Decode(string s)
 {
     System.Text.RegularExpressions.CaptureCollection cs =
         System.Text.RegularExpressions.Regex.Match(s, @"([01]{8})+").Groups[1].Captures;
     byte[] data = new byte[cs.Count];
     for (int i = 0; i < cs.Count; i++)
     {
         data[i] = Convert.ToByte(cs[i].Value, 2);
     }
     return(Encoding.Unicode.GetString(data, 0, data.Length));
 }
Example #2
0
 private Dictionary<int, String> ProcessTemplateCodeParts(CaptureCollection codeParts)
 {
     var processingResult = new Dictionary<int, String>();
     foreach (Capture codePart in codeParts)
     {
         String code = CheckForCodeBrackets(codePart.ToString());
         String formattedCode = language.FormatCode(code);
         processingResult[codePart.Index] = formattedCode;
     }
     return processingResult;
 }
 static public int GetEnumerator(IntPtr l)
 {
     try {
         System.Text.RegularExpressions.CaptureCollection self = (System.Text.RegularExpressions.CaptureCollection)checkSelf(l);
         var ret = self.GetEnumerator();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 private void EvaluateCaptureAndInformObserver(CaptureCollection captureCollection, int captureIndex)
 {
     var capture = captureCollection[captureIndex];
     var index = captureCollection[captureIndex].Index;
     var length = captureCollection[captureIndex].Length;
     if (index == 0)
     {
         this.syntaxParserObserver.AddGherkinSyntaxSpanAt(index, length);
     }
     else
     {
         this.EvaluateCaptureAfterFirstGroup(capture, index, length);
     }
 }
Example #5
0
        //=================================================
        //		Preprocess Directives
        //=================================================
        private string PreprocessDirectives(string text)
        {
            Gen::Dictionary <int, string> errors = new Gen::Dictionary <int, string>();
            Gen::List <DefineMacro>       defs   = new Gen::List <DefineMacro>();

            DefineMacro def;
            string      text2 = reg_directive.Replace(text, delegate(System.Text.RegularExpressions.Match m){
                if (m.Groups["nspace"].Success)
                {
                    if (this.@namespace != null)
                    {
                        errors.Add(m.Index, "名前空間を複数指定する事は出来ません。");
                    }
                    this.@namespace = m.Groups["nspace"].Value;
                }
                else if (m.Groups["class"].Success)
                {
                    if (this.classname != null)
                    {
                        errors.Add(m.Index, "クラス名を複数指定する事は出来ません。");
                    }
                    this.classname = m.Groups["class"].Value;
                }
                else if (m.Groups["defname"].Success)
                {
                    def         = new DefineMacro();
                    def.name    = m.Groups["defname"].Value;
                    def.Content = m.Groups["defcontent"].Value;

                    // 引数リスト
                    System.Text.RegularExpressions.CaptureCollection capts = m.Groups["defarg"].Captures;
                    int iM   = capts.Count;
                    def.args = new string[capts.Count];
                    for (int i = 0; i < iM; i++)
                    {
                        def.args[i] = capts[i].Value;
                    }

                    defs.Add(def);
                }
                return(reg_remove.Replace(m.Value, ""));
            });

            foreach (DefineMacro define in defs)
            {
                define.Apply(ref text2);
            }

            return(text2);
        }
Example #6
0
 private Dictionary<int, String> ProcessTemplateTextParts(CaptureCollection textParts)
 {
     var processingResult = new Dictionary<int, String>();
     foreach (Capture textPart in textParts)
     {
         String text = CheckForCodeBrackets(textPart.ToString());
         if (text == "")
         {
             continue;
         }
         String formattedText = language.FormatText(text);
         processingResult[textPart.Index] = formattedText;
     }
     return processingResult;
 }
 static public int getItem(IntPtr l)
 {
     try {
         System.Text.RegularExpressions.CaptureCollection self = (System.Text.RegularExpressions.CaptureCollection)checkSelf(l);
         int v;
         checkType(l, 2, out v);
         var ret = self[v];
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 private TreeViewItem GetCaptures(CaptureCollection captures)
 {
     TreeViewItem parent = new TreeViewItem() { Header = "Captures" };
     int i = 0;
     foreach (Capture cap in captures) {
         var node = new TreeViewItem() {
             Header = string.Format("Capture {0}: '{1}'", i++, cap.ToString()),
             IsExpanded = true
         };
         node.Items.Add("Index: " + cap.Index);
         node.Items.Add("Length: " + cap.Length);
         node.Items.Add("Value: " + cap.Value);
         parent.Items.Add(node);
     }
     return parent;
 }
 static public int CopyTo(IntPtr l)
 {
     try {
         System.Text.RegularExpressions.CaptureCollection self = (System.Text.RegularExpressions.CaptureCollection)checkSelf(l);
         System.Array a1;
         checkType(l, 2, out a1);
         System.Int32 a2;
         checkType(l, 3, out a2);
         self.CopyTo(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #10
0
    //Elected Services: (easy)
    //3. bidirection_string_convert_binary
    //for example,
    //input "abc" --> output is "string to binary: 011000010000000001100010000000000110001100000000"
    //input "011000010000000001100010000000000110001100000000" --> output is "binary to string: abc"

    public string bidirection_string_Convert_binary(string str)
    {
        int i;

        for (i = 0; i < str.Length; i++)
        {
            if (str[i].Equals('0') || str[i].Equals('1'))
            {
                continue;
            }
            else
            {
                break;
            }
        }
        if (i == str.Length)
        {
            System.Text.RegularExpressions.CaptureCollection cs = System.Text.RegularExpressions.Regex.Match(str, @"([01]{8})+").Groups[1].Captures;
            byte[] data = new byte[cs.Count];
            for (int j = 0; j < cs.Count; j++)
            {
                data[j] = Convert.ToByte(cs[j].Value, 2);
            }
            return("binary to string: " + Encoding.Unicode.GetString(data, 0, data.Length).ToString());
        }
        else
        {
            byte[]        data = Encoding.Unicode.GetBytes(str);
            StringBuilder sb   = new StringBuilder(data.Length * 8);
            foreach (byte b in data)
            {
                sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
            }
            return("string to binary: " + sb.ToString());
        }
    }
Example #11
0
        private string TokenizeValue(XmlAttribute targetAttribute,
                                     XmlAttribute transformAttribute,
                                     bool fTokenizeParameter,
                                     List <Dictionary <string, string> > parameters)
        {
            Debug.Assert(!fTokenizeParameter || parameters != null);

            tokenizeValueCurrentXmlAttribute = transformAttribute;
            string transformValue = transformAttribute.Value;
            string xpath          = GetXPathToAttribute(targetAttribute);

            //subsitute the know value first in the transformAttribute
            transformValue = SubstituteKownValue(transformValue, ParentAttributeRegex, "$(", delegate(string key) { return(EscapeDirRegexSpecialCharacter(GetAttributeValue(key), true)); });

            // then use the directive to parse the value. --- if TokenizeParameterize is enable
            if (fTokenizeParameter && parameters != null)
            {
                int position = 0;
                System.Text.StringBuilder strbuilder = new StringBuilder(transformValue.Length);
                position = 0;
                List <RegularExpressions.Match> matchs = new List <RegularExpressions.Match>();

                do
                {
                    position = transformValue.IndexOf("{%", position, StringComparison.OrdinalIgnoreCase);
                    if (position > -1)
                    {
                        RegularExpressions.Match match = DirRegex.Match(transformValue, position);
                        // Add the successful match to collection
                        if (match.Success)
                        {
                            matchs.Add(match);
                            position = match.Index + match.Length;
                        }
                        else
                        {
                            position++;
                        }
                    }
                } while (position > -1);

                if (matchs.Count > 0)
                {
                    strbuilder.Remove(0, strbuilder.Length);
                    position = 0;
                    int index = 0;

                    foreach (RegularExpressions.Match match in matchs)
                    {
                        strbuilder.Append(transformValue.Substring(position, match.Index - position));
                        RegularExpressions.CaptureCollection attrnames = match.Groups["attrname"].Captures;
                        if (attrnames != null && attrnames.Count > 0)
                        {
                            RegularExpressions.CaptureCollection attrvalues      = match.Groups["attrval"].Captures;
                            Dictionary <string, string>          paramDictionary = new Dictionary <string, string>(4, StringComparer.OrdinalIgnoreCase);

                            paramDictionary[XPathWithIndex] = xpath;
                            paramDictionary[TokenNumber]    = index.ToString(System.Globalization.CultureInfo.InvariantCulture);

                            // Get the key-value pare of the in the tranform form
                            for (int i = 0; i < attrnames.Count; i++)
                            {
                                string name = attrnames[i].Value;
                                string val  = null;
                                if (attrvalues != null && i < attrvalues.Count)
                                {
                                    val = EscapeDirRegexSpecialCharacter(attrvalues[i].Value, false);
                                }
                                paramDictionary[name] = val;
                            }

                            //Identify the Token format
                            string strTokenFormat = null;
                            if (!paramDictionary.TryGetValue(Token, out strTokenFormat))
                            {
                                strTokenFormat = storageDictionary.TokenFormat;
                            }
                            if (!string.IsNullOrEmpty(strTokenFormat))
                            {
                                paramDictionary[Token] = strTokenFormat;
                            }

                            // Second translation of #() -- replace with the existing Parameters
                            int      count = paramDictionary.Count;
                            string[] keys  = new string[count];
                            paramDictionary.Keys.CopyTo(keys, 0);
                            for (int i = 0; i < count; i++)
                            {
                                // if token format contain the #(),we replace with the known value such that it is unique identify
                                // for example, intokenizeTransformXml.cs, default token format is
                                // string.Concat("$(ReplacableToken_#(", SetTokenizedAttributes.ParameterAttribute, ")_#(", SetTokenizedAttributes.TokenNumber, "))");
                                // which ParameterAttribute will be translate to parameterDictionary["parameter"} and TokenNumber will be translate to parameter
                                // parameterDictionary["TokenNumber"]
                                string keyindex = keys[i];
                                string val      = paramDictionary[keyindex];
                                string newVal   = SubstituteKownValue(val, TokenFormatRegex, "#(",
                                                                      delegate(string key) { return(paramDictionary.ContainsKey(key) ? paramDictionary[key] : null); });

                                paramDictionary[keyindex] = newVal;
                            }

                            if (paramDictionary.TryGetValue(Token, out strTokenFormat))
                            {
                                // Replace with token
                                strbuilder.Append(strTokenFormat);
                            }
                            string attributeLocator;
                            if (paramDictionary.TryGetValue(XpathLocator, out attributeLocator) && !string.IsNullOrEmpty(attributeLocator))
                            {
                                IList <string> locators         = XmlArgumentUtility.SplitArguments(attributeLocator);
                                string         xpathwithlocator = GetXPathToAttribute(targetAttribute, locators);
                                if (!string.IsNullOrEmpty(xpathwithlocator))
                                {
                                    paramDictionary[XPathWithLocator] = xpathwithlocator;
                                }
                            }
                            parameters.Add(paramDictionary);
                        }

                        position = match.Index + match.Length;
                        index++;
                    }
                    strbuilder.Append(transformValue.Substring(position));
                    transformValue = strbuilder.ToString();
                }
            }
            return(transformValue);
        }
Example #12
0
            internal Enumerator(CaptureCollection collection)
            {
                Debug.Assert(collection != null, "collection cannot be null.");

                _collection = collection;
                _index = -1;
            }
 private void RenderCaptures(CaptureCollection captures, XmlNode node)
 {
   foreach (Capture capture in captures)
   {
     var elem = node.Elem("Capture");
     elem.Elem("Index").InnerText = capture.Index.ToString();
     elem.Elem("Length").InnerText = capture.Length.ToString();
     elem.Elem("Value").InnerText = capture.Value;
   }
 }
 /*
  * Nonpublic constructor
  */
 internal CaptureEnumerator(CaptureCollection rcc) {
     _curindex = -1;
     _rcc = rcc;
 }
Example #15
0
 // internal
 internal Group(string text, int index, int length, int n_caps) : base(text, index, length)
 {
     success  = true;
     captures = new CaptureCollection(n_caps);
     captures.SetValue(this, n_caps - 1);
 }
Example #16
0
        private static object GetFieldValue(TemplateFieldAccessor root, CaptureCollection parts)
        {
            object value;
            TemplateFieldAccessor accessor = root;
            for (int i = 0; i < parts.Count - 1; i++)
            {
                Capture part = parts[i];
                value = accessor(part.Value);

                // if the accessor didnt return an accessor then
                // wrap the value in an object accessor
                if (!(value is TemplateFieldAccessor))
                    value = TemplateFieldAccessors.PropertyAccessor(value);

                accessor = (TemplateFieldAccessor)value;
            }

            value = accessor(parts[parts.Count - 1].Value);

            return value;
        }
Example #17
0
		internal Group () : base ("")
		{
			success = false;
			captures = new CaptureCollection (0);
		}
Example #18
0
 public KecaknoahRegexCaptures(CaptureCollection col)
 {
     cc = col;
     captures = new List<KecaknoahReference>();
     for (int i = 0; i < cc.Count; i++) captures.Add(KecaknoahReference.Right(new KecaknoahRegexCapture(cc[i])));
 }
Example #19
0
		// KLUDGE WARNING
		//
		// The kludge to determine the base type of the to-be-generated ASP.NET class is
		// very unfortunate but with our current parser it is, unfortunately, necessary. The
		// reason for reading the entire file into memory and parsing it with a regexp is
		// that we need to read the main directive (i.e. <%@Page %>, <%@Control %> etc),
		// pass it to the page parser filter if it exists, and finally read the inherits
		// attribute of the directive to get access to the base type of the class to be
		// generated. On that type we check whether it is decorated with the
		// FileLevelControlBuilder attribute and, if yes, use the indicated type as the
		// RootBuilder. This is necessary for the ASP.NET MVC views using the "generic"
		// inherits declaration to work properly. Our current parser is not able to parse
		// the input file out of sequence (i.e. directives first, then the rest) so we need
		// to do what we do below, alas.
		IDictionary GetDirectiveAttributesDictionary (string skipKeyName, CaptureCollection names, CaptureCollection values)
		{
			var ret = new Dictionary <string, object> (StringComparer.OrdinalIgnoreCase);

			int index = 0;
			string keyName;
			foreach (Capture c in names) {
				keyName = c.Value;
				if (String.Compare (skipKeyName, keyName, StringComparison.OrdinalIgnoreCase) == 0) {
					index++;
					continue;
				}
				
				ret.Add (c.Value, values [index++].Value);
			}

			return ret;
		}
Example #20
0
        private static bool UnitIncludeTime(CaptureCollection units)
        {
            foreach (Capture unit in units)
            {
                if (UnitIncludesTime(unit.Value))
                {
                    return true;
                }
            }

            return false;
        }
Example #21
0
        public ktRE_CaptureCollection(CaptureCollection GC)
            : this()
        {
            m_List = new ktList();

            foreach (Capture G in GC)
            {
                m_List.Add(G);
            }
        }
Example #22
0
 internal Group() : base("")
 {
     success  = false;
     captures = new CaptureCollection(0);
 }
Example #23
0
 /// <summary>
 /// Creates a delegate that writes the value of a template field to a TextWriter
 /// </summary>
 /// <param name="parts">The parsed parts of the field name.</param>
 /// <param name="format">The format to be used when converting the field value to a string.</param>
 /// <returns>A new writer delegate.</returns>
 private static TemplateWriter FieldWriter(CaptureCollection parts, string format)
 {
     return delegate(TextWriter writer, TemplateFieldAccessor root)
     {
         writer.Write(string.Format(format, GetFieldValue(root, parts)));
     };
 }
Example #24
0
        /// <summary>
        /// Decodes the commands and if necessary (re)starts the Attack.
        /// Works with the Captures from RegEx.
        /// </summary>
        /// <param name="cmds">the CaptureCollection containing a collection of commands</param>
        /// <param name="vals">the CaptureCollection containing a collection of values corresponding to the commands.</param>
        /// <returns>True if the commands were successfully loaded. False in case of any error.</returns>
        private bool parseOLUrlCmd(CaptureCollection cmds, CaptureCollection vals)
        {
            bool ret = false;
            if ((cmds.Count == vals.Count) && (cmds.Count > 0))
            {
                StringCollection defaults = new StringCollection();
                defaults.Add("targetip"); defaults.Add("targethost"); defaults.Add("timeout");
                defaults.Add("subsite"); defaults.Add("message"); defaults.Add("port");
                defaults.Add("method"); defaults.Add("threads"); defaults.Add("wait");
                defaults.Add("random"); defaults.Add("speed"); defaults.Add("sockspthread");
                defaults.Add("useget"); defaults.Add("usegzip");

                int num = 0;
                bool isnum = false;
                bool restart = false;
                bool ctdwndn = false;
                string tval = "";
                string tcmd = "";

                for (int i = 0; i < cmds.Count; i++)
                {
                    tval = vals[i].Value.Trim();
                    tcmd = cmds[i].Value.Trim();
                    defaults.Remove(tcmd);
                    switch (tcmd.ToLowerInvariant())
                    {
                        case "targetip":
                            if (txtTargetIP.Text != tval)
                            {
                                txtTargetIP.Text = tval;
                                LockOnIP(true);
                                restart = true;
                            }
                            ret = true;
                            break;
                        case "targethost":
                            if (txtTargetURL.Text != tval)
                            {
                                txtTargetURL.Text = tval;
                                LockOnURL(true);
                                restart = true;
                            }
                            ret = true;
                            break;
                        case "timeout":
                            isnum = int.TryParse(tval, out num);
                            if (isnum)
                            {
                                if (txtTimeout.Text != num.ToString())
                                {
                                    txtTimeout.Text = num.ToString();
                                    restart = true;
                                }
                            }
                            break;
                        case "subsite":
                            tval = Uri.UnescapeDataString(tval);
                            if (txtSubsite.Text != tval)
                            {
                                txtSubsite.Text = tval;
                                restart = true;
                            }
                            break;
                        case "message":
                            if (txtData.Text != tval)
                            {
                                txtData.Text = tval;
                                restart = true;
                            }
                            break;
                        case "port":
                            if (txtPort.Text != tval)
                            {
                                txtPort.Text = tval;
                                restart = true;
                            }
                            break;
                        case "method":
                            int index = cbMethod.FindString(tval);
                            if (index != -1)
                            {
                                if (cbMethod.SelectedIndex != index)
                                {
                                    cbMethod.SelectedIndex = index;
                                    restart = true;
                                }
                            }
                            break;
                        case "threads":
                            if (Functions.ParseInt(tval, 1, 99, out num))
                            {
                                if (txtThreads.Text != num.ToString())
                                {
                                    txtThreads.Text = num.ToString();
                                    if(cbMethod.SelectedIndex >= 3)
                                        restart = true;
                                }
                            }
                            break;
                        case "wait":
                            if (tval.ToLowerInvariant() == "true")
                            {
                                if (!chkWaitReply.Checked)
                                    restart = true;
                                chkWaitReply.Checked = true;
                            }
                            else if (tval.ToLowerInvariant() == "false")
                            {
                                if (chkWaitReply.Checked)
                                    restart = true;
                                chkWaitReply.Checked = false;
                            }
                            break;
                        case "random":
                            if (tval.ToLowerInvariant() == "true")
                            {
                                if (!chkRandom.Checked || !chkMsgRandom.Checked)
                                    restart = true;
                                chkRandom.Checked = true; //HTTP
                                chkMsgRandom.Checked = true; //TCP_UDP
                            }
                            else if (tval.ToLowerInvariant() == "false")
                            {
                                if (chkRandom.Checked || chkMsgRandom.Checked)
                                    restart = true;
                                chkRandom.Checked = false; //HTTP
                                chkMsgRandom.Checked = false; //TCP_UDP
                            }
                            break;
                        case "speed":
                            if (Functions.ParseInt(tval, tbSpeed.Minimum, tbSpeed.Maximum, out num))
                            {
                                if (tbSpeed.Value != num)
                                {
                                    tbSpeed.Value = num;
                                    restart = true;
                                }
                            }
                            break;
                        case "hivemind":
                            string[] sp = tval.Split(':');
                            if (sp.Length > 1)
                            {
                                txtIRCserver.Text = sp[0];
                                string[] spt = sp[1].Split('#');
                                if (spt.Length > 1)
                                {
                                    txtIRCport.Text = spt[0];
                                    txtIRCchannel.Text = '#' + spt[1];
                                    enableHive.Checked = true;
                                    return true;
                                }
                            }
                            //ret = true;
                            break;
                        case "time": // might be not a bad idea to include a NTP-lookup before this?
                            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
                            DateTime dtGo = DateTime.Parse(tval, ci.DateTimeFormat, System.Globalization.DateTimeStyles.AssumeUniversal);
                            DateTime dtNow = DateTime.UtcNow;
                            long tdiff = dtGo.Ticks - dtNow.Ticks;
                            tdiff /= TimeSpan.TicksPerMillisecond;
                            ret = true;
                            tZergRush.Stop();
                            if (tdiff > 0)
                            {
                                tZergRush.Interval = (int)tdiff;
                                tZergRush.Start();
                                this.Text = String.Format("{0} | U dun goofed | v. {1} | Next Raid: {2}", Application.ProductName, Application.ProductVersion, dtGo.ToString("MM-dd HH:mm"));
                                restart = true;
                            }
                            else
                            {
                                ctdwndn = true;
                                this.Text = String.Format("{0} | U dun goofed | v. {1}", Application.ProductName, Application.ProductVersion);
                            }
                            ret = true;
                            break;
                        case "useget":
                            if (tval.ToLowerInvariant() == "true")
                                chkUseGet.Checked = true;
                            else if (tval.ToLowerInvariant() == "false")
                                chkUseGet.Checked = false;
                            break;
                        case "usegzip":
                            if (tval.ToLowerInvariant() == "true")
                                chkAllowGzip.Checked = true;
                            else if (tval.ToLowerInvariant() == "false")
                                chkAllowGzip.Checked = false;
                            break;
                        case "sockspthread":
                            if (Functions.ParseInt(tval, 1, 99, out num))
                                txtSLSpT.Text = num.ToString();
                            break;
                    }
                }
                // let's reset the other values -.-
                for (int i = 0; i < defaults.Count; i++)
                {
                    switch (defaults[i])
                    {
                        case "targetip":
                            txtTargetIP.Text = "";
                            break;
                        case "targethost":
                            txtTargetURL.Text = "";
                            break;
                        case "timeout":
                            txtTimeout.Text = "30";
                            break;
                        case "subsite":
                            txtSubsite.Text = "/";
                            break;
                        case "message":
                            txtData.Text = "U dun goofed";
                            break;
                        case "port":
                            txtPort.Text = "80";
                            break;
                        case "method":
                            int index = cbMethod.FindString("TCP");
                            if (index != -1) { cbMethod.SelectedIndex = index; }
                            break;
                        case "threads":
                            txtThreads.Text = "10";
                            break;
                        case "wait":
                            chkWaitReply.Checked = true;
                            break;
                        case "random":
                            chkRandom.Checked = false;
                            chkMsgRandom.Checked = false;
                            break;
                        case "speed":
                            tbSpeed.Value = 0;
                            break;
                        case "sockspthread":
                            txtSLSpT.Text = "25";
                            break;
                        case "useget":
                            chkUseGet.Checked = false;
                            break;
                        case "usegzip":
                            chkAllowGzip.Checked = false;
                            break;
                    }
                }
                if (restart)
                {
                    Attack(false, false, true);
                    if(!tZergRush.Enabled)
                        Attack(false, true, true);
                }
                else if (ctdwndn && (cmdAttack.Text == AttackText))
                {
                    Attack(false, true, true);
                }
                if(!tZergRush.Enabled)
                    this.Text = String.Format("{0} | U dun goofed | v. {1}", Application.ProductName, Application.ProductVersion);
            }
            return ret;
        }
Example #25
0
 private static TemplateWriter FieldWriter(CaptureCollection parts)
 {
     return delegate(TextWriter writer, TemplateFieldAccessor root)
     {
         object fieldValue = GetFieldValue(root, parts);
         if (fieldValue != null)
             writer.Write(fieldValue.ToString());
     };
 }
Example #26
0
 /*
  * Nonpublic constructor
  */
 internal CaptureEnumerator(CaptureCollection rcc)
 {
     _curindex = -1;
     _rcc      = rcc;
 }
Example #27
0
 /// <summary>
 ///zwraca zaczytane rozwiazania z trzeciej sekcji pliku
 ///result jest sparsowana trzecia czescia pliku, tworzy z niej rozwiazania i zwraca je
 ///badFormat odpowiada czy dane maja byc czytane zgodnie czy tez nie z formatem pliku
 /// </summary>
 private List<Solution> ReadResult(CaptureCollection result, bool badFormat)
 {
     List<Solution> solutions = new List<Solution>();
     string wzorzec = "(?<tag>.{0,4}?)\r\n((?<x1>([0-9]*)?),(?<y1>([0-9]*)?),(?<x2>([0-9]*)?),(?<y2>([0-9]*)?)(\r\n)?)*";
     Regex wyr = new Regex(wzorzec, RegexOptions.IgnoreCase);
     for (int k = 0; k < result.Count; ++k)
     {
         string r = result[k].Value;
         Match elem = wyr.Match(r);
         if (elem.Success)
         {
             string tag = "";
             try
             {
                 tag = elem.Groups["tag"].Value;
                 CaptureCollection x1 = elem.Groups["x1"].Captures;
                 CaptureCollection x2 = elem.Groups["x2"].Captures;
                 CaptureCollection y1 = elem.Groups["y1"].Captures;
                 CaptureCollection y2 = elem.Groups["y2"].Captures;
                 List<Rectangle> rects = new List<Rectangle>();
                 for (int i = 0; i < x1.Count; ++i)
                 {
                     int l = Int32.Parse(x1[i].Value) <= Int32.Parse(x2[i].Value)?
                         Int32.Parse(x1[i].Value) : Int32.Parse(x2[i].Value);
                     int rt = Int32.Parse(x1[i].Value) <= Int32.Parse(x2[i].Value) ?
                         Int32.Parse(x2[i].Value) : Int32.Parse(x1[i].Value);
                     int d = Int32.Parse(y1[i].Value) <= Int32.Parse(y2[i].Value) ?
                         Int32.Parse(y1[i].Value) : Int32.Parse(y2[i].Value);
                     int g = Int32.Parse(y1[i].Value) <= Int32.Parse(y2[i].Value) ?
                         Int32.Parse(y2[i].Value) : Int32.Parse(y1[i].Value);
                     if (badFormat)
                     {
                         g += d;
                         rt += l;
                     }
                     Rectangle rect = new Rectangle(new Point(l, d), new Point(rt, g));
                     if (rects.Count == 0 ||
                             rect.LeftTop.X <= rects[0].LeftTop.X && rect.LeftTop.Y <= rects[0].LeftTop.Y)
                         rects.Insert(0, rect);
                     else
                         rects.Add(rect);
                 }
                 if (rects.Count > 0 && (rects[0].LeftTop.X != 0 || rects[0].LeftTop.Y != 0))
                     for (int i = rects.Count - 1; i >= 0; --i)
                         rects[i] = rects[i].Move(new Point(rects[i].LeftTop.X - rects[0].LeftTop.X,
                                                         rects[i].LeftTop.Y - rects[0].LeftTop.Y));
                 RectangleContainer rc = new RectangleContainer();
                 rc.InsertRectangles(rects);
                 if (!rc.IsCorrectRectangle)
                 {
                     this.log.AppendLine("Powsta³ nie prostok¹t dla tagu: " + tag);
                     Debug.WriteLine("Powsta³ nie prostok¹t dla tagu: {0}", tag);
                 }
                 else
                     solutions.Add(new Solution(tag, rc.MaxCorrectRect));
             }
             catch (Exception ex)
             {
                 this.log.AppendLine("B³¹d w tagu " + tag);
                 Debug.WriteLine("B³¹d w tagu " + tag + " : " + ex.Message + "\n\n" + ex.StackTrace);
             }
         }
     }
     return solutions;
 }
Example #28
0
 internal CaptureEnumerator(CaptureCollection rcc)
 {
     this._rcc = rcc;
 }
Example #29
0
		string GetDirectiveName (CaptureCollection names)
		{
			string val;
			foreach (Capture c in names) {
				val = c.Value;
				if (Directive.IsDirective (val))
					return val;
			}

			return tparser.DefaultDirectiveName;
		}
Example #30
0
		public void FixtureSetUp ()
		{
			coll = Match.Empty.Captures;
		}
 internal CaptureEnumerator(CaptureCollection rcc)
 {
     this._rcc = rcc;
 }
Example #32
0
		// internal
		internal Group (string text, int index, int length, int n_caps) : base (text, index, length)
		{
			success = true;
			captures = new CaptureCollection (n_caps);
			captures.SetValue (this, n_caps - 1);
		}