private string[] GetTerms(string allterms) { int splitIndex = allterms.IndexOf(','); if (splitIndex < 0) { return new string[] { allterms } } ; char[] startChars = new char[] { '(', '[', ',' }; int start = 0; int len; List <string> result = new List <string>(); while (start < allterms.Length) { int ss = allterms.IndexOfAny(startChars, start); if (ss < 0) { string s = allterms.Substring(start).Trim(); if (s.Length > 0) { result.Add(s); } break; } if (allterms[ss] == ',') { // copy from start len = ss - start; string s = allterms.Substring(start, len).Trim(); if (s.Length > 0) { result.Add(s); } start = ss + 1; continue; } int termend = Term.FindMatchingEnd(allterms[ss], allterms, ss); len = termend - start + 1; string su = allterms.Substring(start, len).Trim(); if (su.Length > 0) { result.Add(su); } start = termend + 1; ss = allterms.IndexOfAny(startChars, start); if (ss > 0) { start = ss + 1; } } return(result.ToArray()); }
public Function(string src, int start, EquationElement root) { m_startIndex = start; m_func = Term.ExtractName(src, start).ToLower(); start += m_func.Length; // space는 무시, 다음문자는 무조건 괄호가 와야함. while (src[start] == ' ') { start++; } if (src[start] != '(') { throw new ParseException(src, m_startIndex, "함수는 무조건 () 로 실행해야 합니다.'"); } int termstart = start; int end = Term.FindMatchingEnd('(', src, termstart); if (end < termstart) { throw new ParseException(src, m_startIndex, "함수 매칭 실패"); } m_endindex = end; string allterms = src.Substring(termstart + 1, end - termstart - 1); //string[] terms = allterms.Split(','); string[] terms = GetTerms(allterms); m_terms = new List <Term>(); foreach (string term in terms) { Term newterm = new Term(); newterm.Parse(term, root); newterm.Parent = this; m_terms.Add(newterm); } }