private static StrSpan GetContent中括号(char[] sql, StrSpan s) { char cLeft = sql[s.iLeft]; char cRight = sql[s.iRight]; if (s.iLeft == s.iRight) { throw new SelectDataTableException("无效的 中括号, 缺少 结束中括号 。 ", sql, s.iLeft); } if (cRight != ']') { throw new SelectDataTableException("无效的 中括号, 缺少 结束中括号 。 ", sql, s.iRight); } if (s.iRight == s.iLeft + 1) { s = new StrSpan(s.iLeft, s.iRight); s.isEmpty = true; return(s); } s = StrUtil.Trim(sql, s.iLeft + 1, s.iRight - 1, _whiteSpaces); return(new StrSpan(s.iLeft, s.iRight)); }
private static StrSpan GetContent单引号(char[] sql, StrSpan s) { char cLeft = sql[s.iLeft]; char cRight = sql[s.iRight]; if (s.iLeft == s.iRight) { throw new SelectDataTableException("无效的 字符串, 缺少 结束单引号 。 ", sql, s.iLeft); } if (cRight != '\'') { throw new SelectDataTableException("无效的 字符串, 缺少 结束单引号 。 ", sql, s.iRight); } if (s.iRight == s.iLeft + 1) { s = new StrSpan(s.iLeft, s.iRight); s.isEmpty = true; return(s); } return(new StrSpan(s.iLeft + 1, s.iRight - 1)); }
public static StrSpan Trim(char[] str, int beginIndex, int endIndex, char[] charList) { if (beginIndex > endIndex) { throw new Exception("StrUtil.Trim() : beginIndex 应小于等于 endIndex 。"); } StrSpan span; int i = FindForwardUntilNot(str, beginIndex, endIndex, charList); if (i == -1) { span = new StrSpan(endIndex, endIndex); span.isEmpty = true; return(span); } if (i == endIndex) { span = new StrSpan(i, i); return(span); } int j = FindBackwardUntilNot(str, endIndex, i, charList); return(new StrSpan(i, j)); }
public static List <StrSpan> Split(char[] str, int beginIndex, int endIndex, char c) { List <StrSpan> tokenList = new List <StrSpan>(); StrSpan span; int iLeft = beginIndex; //int iRight; for (int i = iLeft; i <= endIndex; i++) { if (str[i] == c) { if (i == iLeft) { span = new StrSpan(i, i); span.isEmpty = true; } else { span = new StrSpan(iLeft, i - 1); } tokenList.Add(span); iLeft = i + 1; } } if (iLeft > endIndex) { span = new StrSpan(endIndex, endIndex); span.isEmpty = true; } else { span = new StrSpan(iLeft, endIndex); } tokenList.Add(span); return(tokenList); }
private static StrSpan GetContent小括号(char[] sql, StrSpan s) { char cLeft = sql[s.iLeft]; char cRight = sql[s.iRight]; if (s.iLeft == s.iRight) { throw new SelectDataTableException("无效的 小括号, 缺少 结束小括号 。 ", sql, s.iLeft); } if (s.iRight == s.iLeft + 1) { if (cRight == ')') { s = new StrSpan(s.iLeft, s.iRight); s.isEmpty = true; return(s); } else { throw new SelectDataTableException("无效的 小括号, 缺少 结束小括号 。 ", sql, s.iRight); } } int i = FindWrapperEnd小括号(sql, s.iLeft, s.iRight); if (i == -1) { throw new SelectDataTableException("无效的 小括号, 缺少 结束小括号 。 ", sql, s.iRight); } if (i < s.iRight) { throw new SelectDataTableException("语法错误。存在无效的字符 。 ", sql, i + 1); } s = StrUtil.Trim(sql, s.iLeft + 1, s.iRight - 1, _whiteSpaces); // 去掉 小括号 并 对 内容 Trim return(s); //if ( s.isEmpty ) //{ // s = new StrSpan(s.iLeft, s.iRight); // s.isEmpty = true; // return s; //} //i = s.iLeft; //int j = s.iRight; //while (true) //{ // if (sql[i] == '(' && sql[j] == ')') // { // if (i + 1 == j) // { // s = new StrSpan(i, j); // s.isEmpty = true; // return s; // } // if (i + 1 <= j - 1) // { // i++; // j--; // } // } // else // { // break; // } // //return GetContent小括号(sql, s); // 去掉 重复 括号 //} //return new StrSpan(s.iLeft, s.iRight); }
public static Content GetContent(char[] sql, int beginIndex, int endIndex) { if (beginIndex > endIndex) { throw new SelectDataTableException("beginIndex 应 小于等于 endIndex 。 beginIndex : " + beginIndex + " endIndex : " + endIndex + " 。 ", sql, beginIndex); } StrSpan s = StrUtil.Trim(sql, beginIndex, endIndex, Parser._whiteSpaces); Content content; if (s.isEmpty) { content = new Content(s.iLeft, s.iRight, ContentType.None); content.isEmpty = true; return(content); } char cLeft = sql[s.iLeft]; char cRight = sql[s.iRight]; if (cLeft == '\'') { s = GetContent单引号(sql, s); content = new Content(s.iLeft, s.iRight, ContentType.String); if (s.isEmpty) { content.isEmpty = true; } return(content); } else if (cLeft == '[') { s = GetContent中括号(sql, s); } else if (cLeft == '(') { s = GetContent小括号(sql, s); content = new Content(s.iLeft, s.iRight, ContentType.Express); if (s.isEmpty) { content.isEmpty = true; } return(content); } if (StrUtil.IsNumber(sql[s.iLeft])) { return(new Content(s.iLeft, s.iRight, ContentType.Number)); } return(new Content(s.iLeft, s.iRight, ContentType.Column)); //throw new Exception("语法错误。 在 第 " + s.iLeft + " 个 字符 \"" + sql[s.iLeft] + "\" 。"); }