Esempio n. 1
0
 private ProjectItem CreateProjectItem(Match match)
 {
     var projectTitle = match.Result("${Title}");
     var projectPath = match.Result("${Location}");
     var projectItem = new ProjectItem {Name = projectTitle, Path = projectPath};
     return projectItem;
 }
Esempio n. 2
0
        /// <summary>
        /// Get the command args like /output:abc"
        /// </summary>
        /// <returns></returns>
        static Dictionary <string, string[]> GetNamedArgList()
        {
            Dictionary <string, string[]> namedArgs = new Dictionary <string, string[]>();

            string[] args = Environment.GetCommandLineArgs();

            foreach (string arg in args)
            {
                Regex regex = new Regex("[/{1}](?<key>[^:]+):(?<value>[^\"]*)");
                System.Text.RegularExpressions.Match match = regex.Match(arg);
                if (match.Success)
                {
                    string strKey   = match.Result("${key}").ToLower();
                    string strValue = match.Result("${value}");
                    strKey = strKey.Trim('"');  //Remove ?
                    string[] values;
                    if (!namedArgs.TryGetValue(strKey, out values))
                    {
                        values = new string[0];
                        namedArgs.Add(strKey, values);
                    }
                    string[] newValues = new string[values.Length + 1];
                    values.CopyTo(newValues, 0);
                    newValues[values.Length] = strValue;
                    namedArgs[strKey]        = newValues;
                }
            }
            return(namedArgs);
        }
Esempio n. 3
0
 internal override String Evaluate(Match match) {
   this.lastMatch = match;
   Object[] args = new Object[this.cArgs];
   if (this.cArgs > 0) {
     args[0] = match.ToString();
     if (this.cArgs > 1) {
       int i = 1;
       if (this.groupNumbers != null)
         for (; i <= this.groupNumbers.Length; i++) {
           Group group = match.Groups[this.groupNumbers[i-1]];
           args[i] = group.Success ? group.ToString() : null;
         }
       if (i < this.cArgs) {
         args[i++] = match.Index;
         if (i < this.cArgs) {
           args[i++] = this.source;
           for (; i < this.cArgs; i++)
             args[i] = null;
         }
       }
     }
   }
   Object result = this.function.Call(args, null);
   return match.Result(result is Empty ? "" : Convert.ToString(result));
 }
Esempio n. 4
0
        public static int SheifTopicDataInt(ref string errText, ref TCG.ResourcesService.Resources topic, Match match, string datarole)
        {
            if (string.IsNullOrEmpty(datarole))
            {
                return -1;
            }

            string splitstr = datarole.IndexOf("\r\n")>-1 ? "\r\n" : "\n";
            string[] datas = datarole.Split(new string[] { splitstr }, StringSplitOptions.None);
            if (datas.Length == 0)
            {
                return -2;
            }

            PropertyInfo[] tproperty = topic.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            for (int i = 0; i < datas.Length; i++)
            {
                if (!string.IsNullOrEmpty(datas[i]))
                {
                    string[] keyvalue = datas[i].Split(',');
                    int rtn = SheifTopicSheValue(ref errText, ref topic, tproperty, match.Result(keyvalue[0]), keyvalue[1]);
                }
            }
            return 1;
        }
Esempio n. 5
0
            private static string Evaluate(Match match)
            {
                var prop = match.Groups[1].Value;
                if (!themeColors.ContainsKey(prop))
                    themeColors[prop] = themeColors["background-color"].Replace("background-color", prop);

                return match.Result(".theme-color-$1(");
            }
 /// <summary>
 /// Replace the URL placeholder {p:PropertyName} with the value of the corresponding
 /// property of the parent data object.
 /// </summary>
 /// <param name="m">The regex match that contains property name.</param>
 /// <returns>The property value to use.</returns>
 protected string GetPropertyValue(Match m)
 {
     string prop = m.Result("$1");
     DataObject parent = this.property.GetParent();
     if (parent != null && parent.HasProperty(prop))
         return parent[prop].EditStringValue;
     return m.Value;
 }
Esempio n. 7
0
 protected virtual string GetMatch(Match m, ViewDataDictionary viewDataDictionary)
 {
     if (m.Success) {
         string key = m.Result("$1");
         if (viewDataDictionary.ContainsKey(key)) {
             return viewDataDictionary[key].ToString();
         }
     }
     return string.Empty;
 }
Esempio n. 8
0
 protected MatchViewModel(Match model)
 {
     Model = model;
     var groups = model.Groups;
     var capture = model.Captures;// Capture has Index, Length, Value
     var index = model.Index;
     var length = model.Length;
     var next = model.NextMatch();
     var result = model.Result(stringg);
     var x = model.Success;
     var y = model.Value;
     groups[0].
Esempio n. 9
0
 protected virtual string GetMatch(Match m, ViewDataDictionary viewData)
 {
     if (m.Success)
     {
         // 获取匹配后的结果,即 ViewData 中的 key 值,并根据这个 key 值返回 ViewData 中对应的 value
         string key = m.Result("$1");
         if (viewData.ContainsKey(key))
         {
             return viewData[key].ToString();
         }
     }
     return string.Empty;
 }
 static public int Result(IntPtr l)
 {
     try {
         System.Text.RegularExpressions.Match self = (System.Text.RegularExpressions.Match)checkSelf(l);
         System.String a1;
         checkType(l, 2, out a1);
         var ret = self.Result(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 11
0
        public void Compile()
        {
            _compiledDoc = null;

            if (_pureScriptController.Apply())
            {
                _tempDoc.ScriptText = _pureScriptController.Model.ScriptText;

                if (null != _view)
                {
                    _view.ClearCompilerErrors();
                }

                IScriptText compiledDoc = _tempDoc.CloneForModification();
                bool        result      = compiledDoc.Compile();

                string[] errors = compiledDoc.Errors;
                if (result == false)
                {
                    _compiledDoc = null;

                    foreach (string s in errors)
                    {
                        System.Text.RegularExpressions.Match match = _compilerErrorRegex.Match(s);
                        if (match.Success)
                        {
                            string news = match.Result("(${line},${column}) : ${msg}");

                            _view.AddCompilerError(news);
                        }
                        else
                        {
                            _view.AddCompilerError(s);
                        }
                    }


                    Current.Gui.ErrorMessageBox("There were compilation errors");
                    return;
                }
                else
                {
                    _compiledDoc = compiledDoc;

                    _view.AddCompilerError(DateTime.Now.ToLongTimeString() + " : Compilation successful.");
                }
            }
        }
Esempio n. 12
0
 public void UpdateOutput()
 {
     try {
         RE.Match match = RE.Regex.Match(input.Text, expression.Text);
         if (match.Success)
         {
             output.Text = match.Result(result.Text);
         }
         else
         {
             output.Text = "No match";
         }
     } catch (Exception e) {
         output.Text = e.Message;
     }
 }
Esempio n. 13
0
        public void EhView_Compile()
        {
            if (m_TableScript.ScriptText != View.ScriptText)
            {
                m_TableScript = m_TableScript.CloneForModification();
            }
            m_TableScript.ScriptText = View.ScriptText;


            View.ClearCompilerErrors();

            bool bSucceeded = m_TableScript.Compile();

            if (!bSucceeded)
            {
                foreach (string s in m_TableScript.Errors)
                {
                    System.Text.RegularExpressions.Match match = compilerErrorRegex.Match(s);
                    if (match.Success)
                    {
                        string news = match.Result("(${line},${column}) : ${msg}");

                        View.AddCompilerError(news);
                    }
                    else
                    {
                        View.AddCompilerError(s);
                    }
                }


                System.Windows.Forms.MessageBox.Show(View.Form, "There were compilation errors", "No success");
                return;
            }
            else
            {
                View.AddCompilerError(DateTime.Now.ToLongTimeString() + " : Compilation successful.");
            }
        }
 internal override string Evaluate(Match match)
 {
     base.lastMatch = match;
     object[] args = new object[this.cArgs];
     if (this.cArgs > 0)
     {
         args[0] = match.ToString();
         if (this.cArgs > 1)
         {
             int index = 1;
             if (this.groupNumbers != null)
             {
                 while (index <= this.groupNumbers.Length)
                 {
                     Group group = match.Groups[this.groupNumbers[index - 1]];
                     args[index] = group.Success ? group.ToString() : null;
                     index++;
                 }
             }
             if (index < this.cArgs)
             {
                 args[index++] = match.Index;
                 if (index < this.cArgs)
                 {
                     args[index++] = this.source;
                     while (index < this.cArgs)
                     {
                         args[index] = null;
                         index++;
                     }
                 }
             }
         }
     }
     object obj2 = this.function.Call(args, null);
     return match.Result((obj2 is Microsoft.JScript.Empty) ? "" : Microsoft.JScript.Convert.ToString(obj2));
 }
Esempio n. 15
0
 static string Replace(Match m)
 {
     return m.Result("$2").ToString().ToUpper();
 }
Esempio n. 16
0
        private static string ToUpperChar(Match context, string options, Func<char, char> processingFunction)
        {
            string result = string.Empty;
            Match match = charConversionOptionsParser.Match(context.Result(options));
            if (match.Success)
            {
                // Convert to char array:
                char[] charArray = context.Groups[match.Groups["GroupName"].Value].Value.ToCharArray();

                // Check for specified indices:
                Group indexGroup = match.Groups["Index"];
                if (indexGroup.Success)
                {
                    // Process indices:
                    foreach (Capture capture in indexGroup.Captures)
                    {
                        if (capture.Length > 0)
                        {
                            // Split options into range:
                            string[] range = capture.Value.Split('-');

                            // Parse "from" index:
                            int from;
                            if (!Int32.TryParse(range[0], out from))
                                from = 0;
                            int to = from;

                            // Parse "to" index:
                            if (range.Length > 1)
                            {
                                if (!Int32.TryParse(range[1], out to))
                                    to = charArray.Length - 1;
                            }

                            // Ensure valid range:
                            if (from < 0)
                                from = 0;
                            if (to >= charArray.Length)
                                to = charArray.Length - 1;

                            // Apply processing:
                            for (int i = from; i <= to; i++)
                                charArray[i] = processingFunction(charArray[i]);
                        }
                    }
                }
                // No indices specified. Fallback to default - process the first char (if possible):
                else if (charArray.Length > 0)
                {
                    charArray[0] = processingFunction(charArray[0]);
                }

                result = new string(charArray);
            }
            return result;
        }
Esempio n. 17
0
 private string Evaluator(Match match)
 {
     string id = match.Result("$1");
     return _resolvings[id];
 }
Esempio n. 18
0
        private string _ParseANSI(Match m)
        {
            string[] ansicode = m.Result( "$1" ).Split( new char[] { ';' } ); //取出所需結果,並切割成字串陣列
            StringBuilder ret = new StringBuilder(); //要回傳的字串

            foreach ( string s in ansicode )
            {
                if ( s == "" | s == "0" )
                {
                    //重置所有控制碼
                    brightness = "f0";
                    forecolor = "7";
                    backcolor = "b0";
                    blink = false;
                    underline = false;
                }
                else if ( s == "1" )
                {
                    //明暗
                    brightness = "f1";
                }
                else if ( s == "4" )
                {
                    //底線
                    underline = true;
                }
                else if ( s == "5" )
                {
                    //閃爍
                    blink = true;
                }
                else if ( s == "7" )
                {
                    //交換顏色
                    string tmp = forecolor;
                    forecolor = backcolor[1].ToString();
                    backcolor = "b" + tmp;
                }
                else if ( s[0].ToString() == "3" )
                {
                    //前景色
                    forecolor = s[1].ToString();
                }
                else if ( s[0].ToString() == "4" )
                {
                    //背景色
                    backcolor = "b" + s[1].ToString();
                }
            }

            ret.Append( opened == true ? "</span>" : "" ); //如果前面有未關閉的標籤,先關閉之

            if ( brightness == "f0" && forecolor == "7" && backcolor == "b0" && blink == false && underline == false )
            {
                /* TODO: 如果標籤跟上一個完全一樣,也不要寫入 */
                //目前控制碼完全跟預設值一樣,所以不寫入新的標籤
                opened = false; //沒有寫新的標籤,所以目前狀態為已關閉
            }
            else
            {
                //寫入新的標籤
                ret.Append( "<span class=\"" + brightness + forecolor + " " + backcolor ); //亮度及前景色、背景色
                ret.Append( blink == true ? " db" : "" ); //閃爍
                ret.Append( underline == true ? " du" : "" ); //底線
                ret.Append( "\">" );
                opened = true; //寫入了新的標籤,所以目前狀態為未關閉
            }

            return ret.ToString();
        }
 private void PrintCanvas(Match match)
 {
     //this ugliness is just to visualize the solution.
     Console.WriteLine("Visualized:");
     Console.WriteLine();
     var solutionChars = match.Groups["SolutionChar"].GetCaptures();
     var canvas = Regex.Match(match.Result("$_"), @"~[~\s]+\Z").Value;
     var ordered = match.Groups["Filled"].GetCaptures()
         .Zip(solutionChars, (filled, c) => new {Char = c.Value, Order = filled.Length})
         .OrderBy(c => c.Order).Select(c => c.Char).ToArray();
     int index = 0;
     var solution = Regex.Replace(canvas, @"~", m => ordered[index++]);
     Console.WriteLine(solution);
 }
Esempio n. 20
0
 private static string ArgMatchReplace(Match match)
 {
     return match.Result("${arg}");
 }
Esempio n. 21
0
        public static OpsParsedStatement ParseStatement(Match statementMatch)
        {

            string command = statementMatch.Result("${command}").Trim();
            string invalid = statementMatch.Result("${invalid}");

            if (command.Length == 0)
            {
                if(invalid.Length == 0)
                    return null; // no statement
                else
                    throw new OpsException( "Could not pattern match statement.\nCheck that command and argument identifier match " + IdentifierExp + "\nand argument value with spaces are surrounded by single quotes.");
            }

            OpsParsedStatement result = new OpsParsedStatement();

            result.Command = command;

            string args = statementMatch.Result("${args}");
            ParseArguments(result, args);

            return result;
        }
Esempio n. 22
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <param name="match">The match.</param>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        internal string ToString(Match match)
        {
            if (match == null || !match.Success)
            {
                return string.Empty;
            }

            Dictionary<string, string> data = new Dictionary<string, string>();

            foreach (var one in this.dynamicShards)
            {
                data.Add(one, match.Result(string.Format(placeHolderFormat, one)));
            }

            return ToString(data);
        }
Esempio n. 23
0
 internal override String Evaluate(Match match) {
   this.lastMatch = match;
   return match.Result(replaceString);
 }
			private string Evaluator(Match m)
			{
				string ctlID = m.Groups[2].Value;
				Control trueCtl = ctl.Parent.FindControl(ctlID);
				string newID = (trueCtl != null ? trueCtl.ClientID : ctlID);
				return m.Result("$1" + newID + "$3");
			}
 internal override string Evaluate(Match match)
 {
     base.lastMatch = match;
     return match.Result(this.replaceString);
 }
Esempio n. 26
0
 /// <summary>
 /// Evaluates a regular expression match for the string formatting.
 /// Substitutes the constants <c>FieldId</c>, <c>FieldText</c> and <c>AttrPattern</c>
 /// with the corresponding value of ID, Text or the named attribute of the header respectively.
 /// </summary>
 /// <param name="m">The match to evaluate.</param>
 /// <returns>The result of the evaluation.</returns>
 private string EvaluateMatch(Match m)
 {
     string field = m.Result("$1");
     string attrName = m.Result("$2");
     if (string.IsNullOrEmpty(attrName))
     {
         if (field == "i") return Id;
         if (field == "t") return Text;
     }
     else if (field == "a:")
     {
         string res = "";
         object attr = this[attrName];
         IList lst = attr as IList;
         if (lst == null) res = Convert.ToString(attr);
         else foreach(string s in lst) res += (res == "" ? "" : ", ") + s;
         return res;
     }
     return m.Value;
 }
Esempio n. 27
0
        private string ParseLayoutViewContent(ControllerContext viewContext, Match layoutMatch, string html)
        {
            string layoutFileType = layoutMatch.Result("$1").Trim().ToUpperInvariant(),
                   layoutValue = layoutMatch.Result("$2"),
                   layoutFilePath;

            switch (layoutFileType)
            {
                case UrlValueType:
                    layoutFilePath = MapPath(viewContext, layoutValue);
                    break;
                case FileValueType:
                    layoutFilePath = layoutValue.Trim();
                    break;
                case NameValueType:
                    layoutFilePath = MapPath(viewContext, Format(CultureInfo.InvariantCulture, LayoutViewLocation, layoutValue.Trim()));
                    break;
                default:
                    return html;
            }

            html = RegularExpressions.LayoutServerTag.Replace(html, Empty);

            if (!File.Exists(layoutFilePath))
            {
                throw new FileNotFoundException(Format(Resources.LayoutViewNotFound, layoutFilePath));
            }

            if (viewContext.HttpContext.IsDebuggingEnabled)
            {
                GetReferencedFilePaths(viewContext).Add(layoutFilePath);
            }

            string layoutHtml = ReadViewHtml(layoutFilePath, ViewType.Layout);

            MatchCollection sectionMatches = RegularExpressions.SectionServerTag.Matches(layoutHtml);

            foreach (Match sectionMatch in sectionMatches)
            {
                var sectionTagRegex = new Regex(Format(CultureInfo.InvariantCulture, RegularExpressions.CustomSectionTagTemplate, sectionMatch.Groups[1].Value),
                                                RegexOptions.IgnoreCase | RegexOptions.Singleline);

                Match sectionTagMatch = sectionTagRegex.Match(html);
                
                layoutHtml = layoutHtml.Replace(sectionMatch.Value, sectionTagMatch.Success ? sectionTagMatch.Groups[1].Value.TrimLine() : Empty);
                html = sectionTagRegex.Replace(html, Empty);
            }

            layoutHtml = RegularExpressions.BodyServerTag.Replace(layoutHtml, html.TrimLine());

            return layoutHtml;
        }
Esempio n. 28
0
 static string Replace(Match m)
 {
     return m.Result("$1[URL=$2]$3[/URL]$4").ToString();
 }
Esempio n. 29
0
        private string ParsePartialViewContent(ViewContext viewContext, Match match)
        {
            if (!match.Success)
            {
                return Empty;
            }

            string partialViewFileType = match.Result("$1").Trim().ToUpperInvariant(),
                   partialViewValue = match.Result("$2").Trim(),
                   partialViewFilePath;

            switch (partialViewFileType)
            {
                case UrlValueType:
                    partialViewFilePath = MapPath(viewContext, partialViewValue);
                    break;
                case FileValueType:
                    partialViewFilePath = partialViewValue;
                    break;
                case NameValueType:
                    return GeneratePartialView(viewContext, partialViewValue);
                default:
                    return match.Result("$0");
            }

            if (partialViewFilePath == null || !File.Exists(partialViewFilePath))
            {
                throw new FileNotFoundException(Format(Resources.PartialViewNotFound, partialViewFilePath));
            }

            Stack<string> partialViewStack = GetRenderedPartialFilePaths(viewContext);

            if (partialViewStack.Contains(partialViewFilePath.ToUpperInvariant()))
            {
                throw new RecursiveViewReferenceException(Format(Resources.RecursivePartialViewReference, partialViewFilePath));
            }

            if (viewContext.HttpContext.IsDebuggingEnabled)
            {
                GetReferencedFilePaths(viewContext).Add(partialViewFilePath);
            }

            partialViewStack.Push(partialViewFilePath.ToUpperInvariant());

            string html = ReadViewHtml(partialViewFilePath, ViewType.PartialView);
            html = ParseViewContent(viewContext, html);

            partialViewStack.Pop();

            return html;
        }
Esempio n. 30
0
 private static string replaceKeyword(System.Text.RegularExpressions.Match m)
 {
     return("<span style='color:red'>" + m.Result("$0") + "</span>");
 }
Esempio n. 31
0
 private void GetCuptionsResult(Match m, Hashtable groups, StringCollection resultValues) {
     string captionResultPattern = _regexControl.CurrentPattern.Result;
     bool hasCaptionResultPattern = captionResultPattern != null && captionResultPattern.Length > 0;
     _groupTitlesList = new StringCollection();
     while (m.Success) {
         if (hasCaptionResultPattern)
             resultValues.Add(m.Result(captionResultPattern));
         int i = 0;
         foreach (Group group in m.Groups) {
             if (i == 0) {
                 i++;
                 continue;
             }
             string groupTitle = string.Format(MsgsBase.Res.Group_No, i++);
             if (!groups.Contains(groupTitle))
                 groups.Add(groupTitle, new ArrayList());
             if (!_groupTitlesList.Contains(groupTitle))
                 _groupTitlesList.Add(groupTitle);
             IList captures = new StringCollection();
             ((IList) groups[groupTitle]).Add(captures);
             foreach (Capture c1 in group.Captures)
                 captures.Add(c1.Value);
         }
         m = m.NextMatch();
     }
 }
Esempio n. 32
0
		private string replaceAllEvaluator(Match m)
		{
			//	So this method is called for every match

			//	We make a replacement in the range based upon
			//	the match range.
			string replacement = m.Result(_lastReplaceAllReplaceString);
			int start = _lastReplaceAllRangeToSearch.Start + m.Index + _lastReplaceAllOffset;
			int end = start + m.Length;

			Range r = new Range(start, end, Scintilla);
			_lastReplaceAllMatches.Add(r);
			r.Text = replacement;

			//	But because we've modified the document, the RegEx
			//	match ranges are going to be different from the
			//	document ranges. We need to compensate
			_lastReplaceAllOffset += replacement.Length - m.Value.Length;
			return replacement;
		}
Esempio n. 33
0
        private string VersionChanger(Match match)
        {
            // assembly version would be in the format yyyy.dd.mm and assembly file version would be in the format yyyy.dd.mm.revsion
            // first find the type of assembly version
            string versionType = match.Groups[1].Value;

            // get the yyyy.mm.dd
            int yyyy = int.Parse(match.Groups[2].Value);
            int mm = int.Parse(match.Groups[3].Value);
            int dd = int.Parse(match.Groups[4].Value);

            var currentDate = DateTime.UtcNow;

            bool hasRevision = false; // we have the revision number only when change the assembly file version
            int revisionNumber = 1;

            if (!string.IsNullOrEmpty(match.Groups[5].Value))
            {
                hasRevision = true;
                revisionNumber = int.Parse(match.Groups[5].Value.Replace(".", string.Empty));

                // increment revision if same date
                if (yyyy == currentDate.Year && mm == currentDate.Month && dd == currentDate.Day)
                    ++revisionNumber;
                else
                    revisionNumber = 1;
            }

            var dateVersion = currentDate.ToString("yyyy.MM.dd");

            return string.Format(match.Result("[assembly: Assembly{0}Version(\"{1}{2}\")]"),
                versionType, dateVersion, ( hasRevision ? string.Format(".{0}",revisionNumber) : string.Empty));
        }
			string GetValue (Match match, string var)
		{
			string str = match.Result (var);
			if (str != var && !String.IsNullOrEmpty (str))
				return str;
			else
				return null;
		}
Esempio n. 35
0
        private static string ReplaceAssemblyAttributeValue(Match match, Func<string, string, string> attributeValueGetter)
        {
            string attrName = match.Result("$1");
            string oldAttrValue = match.Result("$2");

            string newAttrValue = attributeValueGetter(attrName, oldAttrValue);
            if (newAttrValue == null)
            {
                newAttrValue = oldAttrValue;
            }

            string fragment = match.Result("$0");

            string res;

            res = Regex.Replace(fragment, @"\((.*?)\)", "({0})".FormatWith(newAttrValue));

            return res;
        }