private static bool HasConditional(string content, string[] conditionals, string sign, out ConditionalResult result) { result = new ConditionalResult(); foreach (var _keyword in conditionals) { string keyword = $" {_keyword} "; if (content.IndexOf(keyword) == -1) { continue; } var index = content.IndexOf(keyword); while (index != -1) { if (!FiMHelper.IsIndexInsideString(content, index)) { result.Keyword = keyword; result.Sign = sign; result.Index = index; return(true); } var newIndex = content.IndexOf(keyword, index); if (newIndex == index) { break; } index = newIndex; } } return(false); }
private static FiMHelper.ArrayIndex GetArrayIndex(string content) { // Explicit index if (Regex.IsMatch(content, @"^(.+) of (.+)$")) { var match = Regex.Match(content, @"^(.+) (of) (.+)$"); if (!FiMHelper.IsIndexInsideString(content, match.Groups[2].Index)) { string strIndex = match.Groups[1].Value; string strVar = match.Groups[3].Value; // (somewhat) stricter check if (KirinValue.ValidateName(strVar)) { return(new FiMHelper.ArrayIndex() { RawIndex = strIndex, RawVariable = strVar }); } } } // Implicit index if (Regex.IsMatch(content, @"^(.+) (\d+)$")) { var match = Regex.Match(content, @"^(.+) (\d+)$"); string varName = match.Groups[1].Value; string varIndex = match.Groups[2].Value; // (somewhat) stricter check if (KirinValue.ValidateName(varName)) { return(new FiMHelper.ArrayIndex() { RawIndex = varIndex, RawVariable = varName, }); } } return(null); }