public static string RegExp(string data, string strMatch, bool fullValue = false) { string ret = ""; System.Text.RegularExpressions.Regex oRegex = new System.Text.RegularExpressions.Regex(strMatch); System.Text.RegularExpressions.Match oMath = oRegex.Match(data); if (fullValue) { return(oMath.Value); } while (oMath.Success) { for (int i = 1; i <= 2; i++) { System.Text.RegularExpressions.Group g = oMath.Groups[i]; if (g.ToString() != "") { ret = g.ToString(); return(ret); } } oMath = oMath.NextMatch(); } return(ret); }
/// <summary> /// Returns value from Group parsed as integer. Exception if fails. /// </summary> /// <param name="grp"></param> /// <returns></returns> public static int GetIntValue(this System.Text.RegularExpressions.Group grp) { int ret = int.Parse(grp.Value); return(ret); }
private static string FromPS(System.Text.RegularExpressions.Group g, string delimeter = ";") { if (g.Success) { return(string.Join(delimeter, FromPS(g.Value))); } return(null); }
public static T?GetOptionalEnumValue <T>(this System.Text.RegularExpressions.Group grp) where T : struct { if (!grp.Success) { return(null); } return(Enum.TryParse(grp.Value, out T value) ? value : (T?)null); }
/** OnMouseEvent */ private void OnMouseEvent(UnityEngine.UIElements.MouseEventBase <UnityEngine.UIElements.MouseDownEvent> a_event) { switch (a_event.clickCount) { case 2: { //コードジャンプ。 { System.Text.RegularExpressions.Regex t_regex = new System.Text.RegularExpressions.Regex("^(?<path>.*)\\((?<line>[0-9]*)\\)(\\:)?(?<comment>.*)$"); System.Text.RegularExpressions.Match t_match = t_regex.Match(this.item.text); if (t_match.Success == true) { string[] t_group_list = new string[] { "0", "path", "line", "comment" }; string t_path = ""; int t_line = 0; string t_comment = ""; for (int jj = 0; jj < t_group_list.Length; jj++) { string t_group_name = t_group_list[jj]; System.Text.RegularExpressions.Group t_group = t_match.Groups[t_group_name]; if (t_group.Success == true) { switch (t_group_name) { case "path": { t_path = t_group.Value; } break; case "line": { if (int.TryParse(t_group.Value, out t_line) == false) { t_line = 0; } } break; case "comment": { t_comment = t_group.Value; } break; } } } #if (UNITY_EDITOR) Unity.CodeEditor.CodeEditor.CurrentEditor.OpenProject(t_path, t_line, -1); #endif } } } break; } }
public BGroup(Group group) { var config = new MapperConfiguration(cfg => cfg.CreateMap <Group, BGroup>()); Mapper mapper = new Mapper(config); BGroup tmpBGroup = mapper.Map <BGroup>(group); this.Name = tmpBGroup.Name; this.CourseId = tmpBGroup.CourseId; this.StartDate = tmpBGroup.StartDate; this.EndDate = tmpBGroup.EndDate; }
/// <summary> /// Get a specified field value. /// </summary> /// <param name="fieldName"></param> /// <returns></returns> public object GetValue(string fieldName) { if (mRegExMatch == null) { throw new ArgumentNullException("mRegExMatch"); } System.Text.RegularExpressions.Group group = mRegExMatch.Groups[fieldName]; if (group.Success == false) { throw new RegExException(fieldName); } return(mFields[fieldName].StringToValue(group.Value)); }
private static decimal ParseDecimalFromGroupValue ( System.Text.RegularExpressions.Group group ) { if (null == group) { return(0); } if (false == group.Success) { return(0); } return(Decimal.Parse((group.Value ?? String.Empty).Replace(",", "."))); }
static StackObject *get_Success_2(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Text.RegularExpressions.Group instance_of_this_method = (System.Text.RegularExpressions.Group) typeof(System.Text.RegularExpressions.Group).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.Success; __ret->ObjectType = ObjectTypes.Integer; __ret->Value = result_of_this_method ? 1 : 0; return(__ret + 1); }
static StackObject *get_Captures_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Text.RegularExpressions.Group instance_of_this_method = (System.Text.RegularExpressions.Group) typeof(System.Text.RegularExpressions.Group).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.Captures; object obj_result_of_this_method = result_of_this_method; if (obj_result_of_this_method is CrossBindingAdaptorType) { return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance)); } return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method)); }
public static bool _Synchronized_System_Text_RegularExpressions_Group( ) { //Parameters System.Text.RegularExpressions.Group inner = null; //ReturnType/Value System.Text.RegularExpressions.Group returnVal_Real = null; System.Text.RegularExpressions.Group returnVal_Intercepted = null; //Exception Exception exception_Real = null; Exception exception_Intercepted = null; InterceptionMaintenance.disableInterception( ); try { returnValue_Real = System.Text.RegularExpressions.Group.Synchronized(inner); } catch (Exception e) { exception_Real = e; } InterceptionMaintenance.enableInterception( ); try { returnValue_Intercepted = System.Text.RegularExpressions.Group.Synchronized(inner); } catch (Exception e) { exception_Intercepted = e; } Return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted)); }
private void BuildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action) { if (vsBuildAction.vsBuildActionBuild == Action || vsBuildAction.vsBuildActionRebuildAll == Action) { if (vsBuildScope.vsBuildScopeProject == Scope) { //Project StreamReader sr = new StreamReader(projectName, System.Text.Encoding.UTF8); string projectFileContent = sr.ReadToEnd(); sr.Dispose(); System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("<OutputPath>(\\S+)</OutputPath>"); string outPutPath = reg.Match(projectFileContent).Groups[1].Value; if (outPutPath == string.Empty) { outPutPath = "bin\\Debug\\"; } string FullOutPutPath = Path.Combine(Path.GetDirectoryName(projectName), outPutPath); System.Text.RegularExpressions.Regex regframework = new System.Text.RegularExpressions.Regex("<TargetFramework>(\\S+)</TargetFramework>"); System.Text.RegularExpressions.Group groupframework = regframework.Match(projectFileContent).Groups[1]; string repairFullOutPutPath = null; if (groupframework.Success) { repairFullOutPutPath = Path.Combine(FullOutPutPath, groupframework.Value); if (Directory.Exists(repairFullOutPutPath)) { FullOutPutPath = repairFullOutPutPath; } } string FullCopyPath = Path.Combine(Path.GetDirectoryName(projectName), "bin\\"); //复制文件添加Razor自动提示功能 CopyRazorLibrary(projectName, projectFileContent); if (FullOutPutPath != FullCopyPath) { CopyDirectory(FullOutPutPath, FullCopyPath); OutPutString("从目录:\"" + FullOutPutPath + "\"复制到:\"" + FullCopyPath + "\"", true); } } } }
protected override void ProcessRecord() { if (InputObject == null) { return; } PSObject newInputObject; if (NoClone.IsPresent) { newInputObject = Helpers.EnsureHasProperties(InputObject, Property); } else { newInputObject = Helpers.CloneObject(InputObject, Property); } bool setValue = true; PSVariable matchVar = new PSVariable("Matches"); if (whereIsScriptBlock) { var varList = new List <PSVariable>(); varList.Add(new PSVariable("_", InputObject)); varList.Add(matchVar); var whereResult = whereAsScriptBlock.InvokeWithContext(null, varList, null); setValue = LanguagePrimitives.IsTrue(whereResult); } else if (whereIsString) { setValue = false; var whereProperty = newInputObject.Properties[whereAsString]; if (Match != null && whereProperty != null && whereProperty.Value != null) { var matchResult = matchRegex.Match(whereProperty.Value.ToString()); setValue = matchResult.Success; Hashtable matches = new Hashtable(StringComparer.CurrentCultureIgnoreCase); foreach (string groupName in matchGroupNames) { System.Text.RegularExpressions.Group g = matchResult.Groups[groupName]; if (g.Success) { int keyInt; if (Int32.TryParse(groupName, out keyInt)) { matches.Add(keyInt, g.ToString()); } else { matches.Add(groupName, g.ToString()); } } } matchVar.Value = matches; } else { setValue = whereProperty != null && LanguagePrimitives.IsTrue(whereProperty.Value); } } if (!setValue) { WriteObject(newInputObject); return; } object newValue = Value; if (valueIsScriptBlock) { var varList = new List <PSVariable>(); varList.Add(new PSVariable("_", InputObject)); varList.Add(matchVar); var scriptResult = valueAsScriptBlock.InvokeWithContext(null, varList, null); if (scriptResult.Count == 1) { newValue = scriptResult[0]; } else { newValue = scriptResult; } } foreach (string property in Property) { if (!IfUnset.IsPresent || Helpers.IsPropertyNullOrWhiteSpace(newInputObject, property)) { if (JoinWith != null) { var enumValue = LanguagePrimitives.ConvertTo <string[]>(newValue); newValue = string.Join(JoinWith, enumValue); } newInputObject.Properties.Add(new PSNoteProperty(property, newValue)); } } WriteObject(newInputObject); }
/** FileMain */ private static void FileMain(Fee.File.Path a_assets_path) { string t_full_path = Fee.File.Path.CreateAssetsPath(a_assets_path, Fee.File.Path.SEPARATOR).GetPath(); string t_text = Fee.EditorTool.AssetTool.ReadTextFile(a_assets_path); if (t_text != null) { string[] t_list_text = t_text.Split(new char[] { '\n' }); for (int ii = 0; ii < t_list_text.Length; ii++) { string t_temp = t_list_text[ii]; //最後についている「\r」を削除。 { if (t_temp.Length > 0) { t_temp = System.Text.RegularExpressions.Regex.Replace(t_temp, "^(.*)\r$", "$1"); } } //「//」タイプのコメントを削除。 { if (t_temp.Length > 0) { System.Text.RegularExpressions.Regex t_regex = new System.Text.RegularExpressions.Regex("^(?<capture>.*)\\/\\/.*$"); System.Text.RegularExpressions.Match t_match = t_regex.Match(t_temp); if (t_match.Success == true) { string[] t_group_list = new string[] { "0", "capture" }; for (int jj = 0; jj < t_group_list.Length; jj++) { string t_group_name = t_group_list[jj]; System.Text.RegularExpressions.Group t_group = t_match.Groups[t_group_name]; if (t_group.Success == true) { switch (t_group_name) { case "0": { } break; case "capture": { if (t_temp != t_group.Value) { t_temp = t_group.Value; } } break; default: { #if (UNITY_EDITOR) Tool.EditorLogError(a_assets_path.GetPath() + ":" + ii.ToString() + ":" + t_group_name + ":" + t_group.Value + ":" + t_list_text[ii]); #endif } break; } } } } } } //「#if」「#elif」使用箇所検索。 { System.Text.RegularExpressions.Regex t_regex = new System.Text.RegularExpressions.Regex("^\\s*\\#\\s*(?<deftype>if|elif)\\s*(?<capture>.*)\\s*$"); System.Text.RegularExpressions.Match t_match = t_regex.Match(t_temp); if (t_match.Success == true) { string[] t_group_list = new string[] { "0", "deftype", "capture" }; for (int jj = 0; jj < t_group_list.Length; jj++) { string t_group_name = t_group_list[jj]; System.Text.RegularExpressions.Group t_group = t_match.Groups[t_group_name]; if (t_group.Success == true) { switch (t_group_name) { case "0": { } break; case "deftype": { } break; case "capture": { string[] t_list_define = t_group.Value.Split(new char[] { '(', ')', '|', '&', '!', ' ' }); for (int kk = 0; kk < t_list_define.Length; kk++) { if (t_list_define[kk].Length > 0) { DefineMain(t_temp, t_list_define[kk]); } } } break; default: { #if (UNITY_EDITOR) Tool.EditorLogError(a_assets_path.GetPath() + ":" + ii.ToString() + ":" + t_group_name + ":" + t_group.Value + ":" + t_list_text[ii]); #endif } break; } } } } } } } }
public static System.Text.RegularExpressions.Group Synchronized(System.Text.RegularExpressions.Group inner) { return(default(System.Text.RegularExpressions.Group)); }
public static System.Text.RegularExpressions.Group Synchronized(System.Text.RegularExpressions.Group inner) { throw null; }
private async Task <ExecValue> executeNativeRegexFunctionAsync(ExecutionContext ctx, FunctionDefinition func, ObjectData thisValue) { if (func == ctx.Env.RegexContainsFunction) { ObjectData arg = ctx.FunctionArguments.Single(); ObjectData arg_val = arg.DereferencedOnce(); string arg_str = arg_val.NativeString; ObjectData pattern_obj = thisValue.GetField(ctx.Env.RegexPatternField); ObjectData pattern_val = pattern_obj.DereferencedOnce(); string pattern = pattern_val.NativeString; bool val = new System.Text.RegularExpressions.Regex(pattern).IsMatch(arg_str); ExecValue result = ExecValue.CreateReturn(await ObjectData.CreateInstanceAsync(ctx, func.ResultTypeName.Evaluation.Components, val).ConfigureAwait(false)); return(result); } else if (func == ctx.Env.RegexMatchFunction) { ObjectData arg = ctx.FunctionArguments.Single(); ObjectData arg_val = arg.DereferencedOnce(); string arg_str = arg_val.NativeString; ObjectData pattern_obj = thisValue.GetField(ctx.Env.RegexPatternField); ObjectData pattern_val = pattern_obj.DereferencedOnce(); string pattern = pattern_val.NativeString; System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(pattern); System.Text.RegularExpressions.MatchCollection matches = regex.Matches(arg_str); var elements = new List <ObjectData>(); for (int match_idx = 0; match_idx < matches.Count; ++match_idx) { System.Text.RegularExpressions.Match match = matches[match_idx]; ObjectData match_start_val = await createNat64Async(ctx, (UInt64)match.Index).ConfigureAwait(false); ObjectData match_end_val = await createNat64Async(ctx, (UInt64)(match.Index + match.Length)).ConfigureAwait(false); ObjectData array_captures_ptr; { if (!ctx.Env.DereferencedOnce(ctx.Env.MatchCapturesProperty.TypeName.Evaluation.Components, out IEntityInstance array_captures_type, out bool dummy)) { throw new Exception($"Internal error {ExceptionCode.SourceInfo()}"); } ExecValue ret = await createObject(ctx, true, array_captures_type, ctx.Env.ArrayDefaultConstructor, null) .ConfigureAwait(false); if (ret.IsThrow) { return(ret); } array_captures_ptr = ret.ExprValue; ctx.Heap.TryInc(ctx, array_captures_ptr, RefCountIncReason.StoringLocalPointer, ""); // skipping implicit "everything" group for (int grp_idx = 1; grp_idx < match.Groups.Count; ++grp_idx) { System.Text.RegularExpressions.Group group = match.Groups[grp_idx]; string group_name = regex.GroupNameFromNumber(grp_idx); if (group_name == $"{grp_idx}") // hack for anonymous captures { group_name = null; } for (int cap_idx = 0; cap_idx < group.Captures.Count; ++cap_idx) { System.Text.RegularExpressions.Capture cap = group.Captures[cap_idx]; ObjectData cap_start_val = await createNat64Async(ctx, (UInt64)cap.Index).ConfigureAwait(false); ObjectData cap_end_val = await createNat64Async(ctx, (UInt64)(cap.Index + cap.Length)).ConfigureAwait(false); ObjectData cap_opt_name_val; { Option <ObjectData> opt_group_name_obj; if (group_name != null) { ObjectData str_ptr = await createStringAsync(ctx, group_name).ConfigureAwait(false); opt_group_name_obj = new Option <ObjectData>(str_ptr); } else { opt_group_name_obj = new Option <ObjectData>(); } IEntityInstance opt_cap_type = ctx.Env.CaptureConstructor.Parameters.Last().TypeName.Evaluation.Components; ExecValue opt_exec = await createOption(ctx, opt_cap_type, opt_group_name_obj).ConfigureAwait(false); if (opt_exec.IsThrow) { return(opt_exec); } cap_opt_name_val = opt_exec.ExprValue; } ExecValue capture_obj_exec = await createObject(ctx, false, ctx.Env.CaptureType.InstanceOf, ctx.Env.CaptureConstructor, null, cap_start_val, cap_end_val, cap_opt_name_val).ConfigureAwait(false); if (capture_obj_exec.IsThrow) { return(capture_obj_exec); } ObjectData capture_ref = await capture_obj_exec.ExprValue.ReferenceAsync(ctx).ConfigureAwait(false); ExecValue append_exec = await callNonVariadicFunctionDirectly(ctx, ctx.Env.ArrayAppendFunction, null, array_captures_ptr, capture_ref).ConfigureAwait(false); if (append_exec.IsThrow) { return(append_exec); } } } } ObjectData match_val; { ExecValue ret = await createObject(ctx, false, ctx.Env.MatchType.InstanceOf, ctx.Env.MatchConstructor, null, match_start_val, match_end_val, array_captures_ptr).ConfigureAwait(false); ctx.Heap.TryRelease(ctx, array_captures_ptr, null, false, RefCountDecReason.DroppingLocalPointer, ""); if (ret.IsThrow) { return(ret); } match_val = ret.ExprValue; } elements.Add(match_val); } ObjectData heap_chunk = await createChunkOnHeap(ctx, ctx.Env.MatchType.InstanceOf, elements).ConfigureAwait(false); ExecValue result = ExecValue.CreateReturn(heap_chunk); return(result); } else { throw new NotImplementedException($"{ExceptionCode.SourceInfo()}"); } }