public static bool IsValidStateName(string name) { if (string.IsNullOrEmpty(name)) { return(false); } return(RegexUtil.Get1stMatch(@"[_a-zA-Z]+_[_a-zA-Z0-9]*", name) == name); }
public static List <string> SplitComma(string i) //カンマ区切りで分割 ダブルクォート対応 \"対応 { if (string.IsNullOrEmpty(i)) { return(null); } var s = i.Trim(); if (string.IsNullOrEmpty(s)) { return(null); } var dw = @"\x22((\x5c\x22)|([^\x22]))*?\x22"; // DQに囲まれた文字列 ¥”対応 var p1 = @"[^\x22]+?\x2c"; // "以外が続き 最後が , (カンマ) var p2 = @"[^\x22]+?$"; // "以外が続き 最後が 行末 var p3 = dw + @"\s*\x2c"; // 文字列で最後が, var p4 = dw + @"\s*$"; // 文字列で最後が 行末 var regex = string.Format("^(({0})|({1})|({2})|({3}))", p1, p2, p3, p4); var tb = s; var list = new List <string>(); for (var loop = 0; loop <= 100; loop++) { if (loop == 100) { throw new SystemException("Unexpected! {11529044-AA98-47BC-9B8B-A7D2B5322265}"); } var f = RegexUtil.Get1stMatch(regex, tb); if (!string.IsNullOrEmpty(f)) { var f2 = f.Trim(',').Trim(); list.Add(f2); tb = tb.Substring(f.Length); } else { break; } } if (list.Count > 0) { return(list); } return(null); }
public static Item Read(string branch, string brcond, string branch_cmt) { var item = new Item(); if (string.IsNullOrEmpty(branch)) { return(null); } item.br_raw_list = StringUtil.SplitTrim(branch, StringUtil._0a[0]); item.br_api_list = new List <string>(); item.br_state_list = new List <string>(); for (var n = 0; n < item.br_raw_list.Count; n++) { var s = item.br_raw_list[n]; //var api = RegexUtil.Get1stMatch(@"^.+\(", s).TrimEnd('('); var api = RegexUtil.Get1stMatch(@"^.+\(", s);//.TrimEnd('('); api = StringUtil.TrimEnd(api, '('); item.br_api_list.Add(api); //var bst = RegexUtil.Get1stMatch(@"\(.+\)", s).TrimStart('(').TrimEnd(')'); var bst = RegexUtil.Get1stMatch(@"\(.+\)", s).TrimStart('('); bst = StringUtil.TrimEnd(bst, ')'); item.br_state_list.Add(bst); } if (!string.IsNullOrEmpty(brcond)) { item.br_cond_list = StringUtil.SplitTrim(brcond, StringUtil._0a[0]); } if (!string.IsNullOrEmpty(branch_cmt)) { item.br_cmt_list = StringUtil.SplitTrim(branch_cmt, StringUtil._0a[0]); for (var n = 0; n < item.br_cmt_list.Count; n++) { var a = item.br_cmt_list[n].Trim(); item.br_cmt_list[n] = a == "?" ? "" : a; } } return(item); }
/// <summary> /// 文字列中の対象文字を代替文字に入れ替える /// ※代替文字に改行が含まれていた場合、見栄えを調整する。この場合に複数行になる /// </summary> public static List <string> ReplaceWordsInLine(string line, string target, string replace, bool bTrimEnd = true) { if (string.IsNullOrEmpty(line)) { throw new SystemException("Unexpected! {8F041B67-5F7C-4159-83BC-A0A20858C242}"); } if (string.IsNullOrEmpty(target)) { throw new SystemException("Unexpected! {475F3A7E-03A0-4AE0-94AD-8668BDA5B217}"); } if (target.Trim() != target) { throw new SystemException("Unexpected! {BC4E8F0B-5DAA-4ED5-9E75-98134929CF0B}"); } if (!line.Contains(target)) { throw new SystemException("Unexpected! {D5C8183F-D166-4C6E-AB6B-2E7FD7155696}"); } var replace2 = string.Empty; if (!string.IsNullOrEmpty(replace)) { replace2 = replace.Trim(); } var newline = StringUtil.FindNewLineChar(replace2); if (newline == null) //1行 { var tmp = line.Replace(target, replace2); // return new List<string>() { tmp }; var p = new List <string>(); p.Add(tmp); return(p); } /* * 複数行 * if ([[hoge]]){ return; } * v * v * if ( * hoge1 * hoge2 * : * ){ return; } * * */ List <string> replines = bTrimEnd ? StringUtil.SplitTrimEnd(replace2, '\x0a') : StringUtil.SplitTrim(replace2, '\x0a'); var firstspace = RegexUtil.Get1stMatch(@"^\s", line); var targetindex = line.IndexOf(target); var result = new List <string>(); //1. 第一行:ターゲット手前まで { var buf = line.Substring(0, targetindex); result.Add(buf); } //2. 代替文字列 先頭に "firstspace" と (targetindex - firstspace.length)分のスペース foreach (var r in replines) { var buf = string.Empty; if (firstspace != null) { buf += firstspace + new string(' ', targetindex - firstspace.Length); } else { buf += new string(' ', targetindex); } buf += r; result.Add(buf); } //3. 最終行:代替文字列と同様の空白、その後にlineのターゲット文字以降を挿入 { var buf = string.Empty; if (firstspace != null) { buf += firstspace + new string(' ', targetindex + target.Length - firstspace.Length); } else { buf += new string(' ', targetindex + target.Length); } buf += line.Substring(targetindex + target.Length); result.Add(buf); } return(result); }