bool ParseString(string srcString, SwitchForm[] switchForms) { int len = srcString.Length; if (len == 0) { return(false); } int pos = 0; if (!IsItSwitchChar(srcString[pos])) { return(false); } while (pos < len) { if (IsItSwitchChar(srcString[pos])) { pos++; } const int kNoLen = -1; int matchedSwitchIndex = 0; int maxLen = kNoLen; for (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++) { int switchLen = switchForms[switchIndex].IDString.Length; if (switchLen <= maxLen || pos + switchLen > len) { continue; } if (String.Compare(switchForms[switchIndex].IDString, 0, srcString, pos, switchLen, true) == 0) { matchedSwitchIndex = switchIndex; maxLen = switchLen; } } if (maxLen == kNoLen) { throw new Exception("maxLen == kNoLen"); } SwitchResult matchedSwitch = _switches[matchedSwitchIndex]; SwitchForm switchForm = switchForms[matchedSwitchIndex]; if ((!switchForm.Multi) && matchedSwitch.ThereIs) { throw new Exception("switch must be single"); } matchedSwitch.ThereIs = true; pos += maxLen; int tailSize = len - pos; SwitchType type = switchForm.Type; switch (type) { case SwitchType.PostMinus: { if (tailSize == 0) { matchedSwitch.WithMinus = false; } else { matchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus); if (matchedSwitch.WithMinus) { pos++; } } break; } case SwitchType.PostChar: { if (tailSize < switchForm.MinLen) { throw new Exception("switch is not full"); } string charSet = switchForm.PostCharSet; const int kEmptyCharValue = -1; if (tailSize == 0) { matchedSwitch.PostCharIndex = kEmptyCharValue; } else { int index = charSet.IndexOf(srcString[pos]); if (index < 0) { matchedSwitch.PostCharIndex = kEmptyCharValue; } else { matchedSwitch.PostCharIndex = index; pos++; } } break; } case SwitchType.LimitedPostString: case SwitchType.UnLimitedPostString: { int minLen = switchForm.MinLen; if (tailSize < minLen) { throw new Exception("switch is not full"); } if (type == SwitchType.UnLimitedPostString) { matchedSwitch.PostStrings.Add(srcString.Substring(pos)); return(true); } String stringSwitch = srcString.Substring(pos, minLen); pos += minLen; for (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++) { char c = srcString[pos]; if (IsItSwitchChar(c)) { break; } stringSwitch += c; } matchedSwitch.PostStrings.Add(stringSwitch); break; } } } return(true); }
bool ParseString(string srcString, SwitchForm[] switchForms) { int len = srcString.Length; if (len == 0) return false; int pos = 0; if (!IsItSwitchChar(srcString[pos])) return false; while (pos < len) { if (IsItSwitchChar(srcString[pos])) pos++; const int kNoLen = -1; int matchedSwitchIndex = 0; int maxLen = kNoLen; for (int switchIndex = 0; switchIndex < _switches.Length; switchIndex++) { int switchLen = switchForms[switchIndex].IDString.Length; if (switchLen <= maxLen || pos + switchLen > len) continue; if (String.Compare(switchForms[switchIndex].IDString, 0, srcString, pos, switchLen, true) == 0) { matchedSwitchIndex = switchIndex; maxLen = switchLen; } } if (maxLen == kNoLen) throw new Exception("maxLen == kNoLen"); SwitchResult matchedSwitch = _switches[matchedSwitchIndex]; SwitchForm switchForm = switchForms[matchedSwitchIndex]; if ((!switchForm.Multi) && matchedSwitch.ThereIs) throw new Exception("switch must be single"); matchedSwitch.ThereIs = true; pos += maxLen; int tailSize = len - pos; SwitchType type = switchForm.Type; switch (type) { case SwitchType.PostMinus: { if (tailSize == 0) matchedSwitch.WithMinus = false; else { matchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus); if (matchedSwitch.WithMinus) pos++; } break; } case SwitchType.PostChar: { if (tailSize < switchForm.MinLen) throw new Exception("switch is not full"); string charSet = switchForm.PostCharSet; const int kEmptyCharValue = -1; if (tailSize == 0) matchedSwitch.PostCharIndex = kEmptyCharValue; else { int index = charSet.IndexOf(srcString[pos]); if (index < 0) matchedSwitch.PostCharIndex = kEmptyCharValue; else { matchedSwitch.PostCharIndex = index; pos++; } } break; } case SwitchType.LimitedPostString: case SwitchType.UnLimitedPostString: { int minLen = switchForm.MinLen; if (tailSize < minLen) throw new Exception("switch is not full"); if (type == SwitchType.UnLimitedPostString) { matchedSwitch.PostStrings.Add(srcString.Substring(pos)); return true; } String stringSwitch = srcString.Substring(pos, minLen); pos += minLen; for (int i = minLen; i < switchForm.MaxLen && pos < len; i++, pos++) { char c = srcString[pos]; if (IsItSwitchChar(c)) break; stringSwitch += c; } matchedSwitch.PostStrings.Add(stringSwitch); break; } } } return true; }
public void ParseStrings(SwitchForm[] switchForms, string[] commandStrings) { int numCommandStrings = commandStrings.Length; bool stopSwitch = false; for (int i = 0; i < numCommandStrings; i++) { string s = commandStrings[i]; if (stopSwitch) NonSwitchStrings.Add(s); else if (s == kStopSwitchParsing) stopSwitch = true; else if (!ParseString(s, switchForms)) NonSwitchStrings.Add(s); } }
private bool ParseString(string srcString, SwitchForm[] switchForms) { int length1 = srcString.Length; if (length1 == 0) { return(false); } int index1 = 0; if (!Parser.IsItSwitchChar(srcString[index1])) { return(false); } while (index1 < length1) { if (Parser.IsItSwitchChar(srcString[index1])) { ++index1; } int index2 = 0; int num1 = -1; for (int index3 = 0; index3 < this._switches.Length; ++index3) { int length2 = switchForms[index3].IDString.Length; if (length2 > num1 && index1 + length2 <= length1 && string.Compare(switchForms[index3].IDString, 0, srcString, index1, length2, true) == 0) { index2 = index3; num1 = length2; } } if (num1 == -1) { throw new Exception("maxLen == kNoLen"); } SwitchResult switchResult = this._switches[index2]; SwitchForm switchForm = switchForms[index2]; if (!switchForm.Multi && switchResult.ThereIs) { throw new Exception("switch must be single"); } switchResult.ThereIs = true; index1 += num1; int num2 = length1 - index1; SwitchType type = switchForm.Type; switch (type) { case SwitchType.PostMinus: if (num2 == 0) { switchResult.WithMinus = false; continue; } switchResult.WithMinus = srcString[index1] == '-'; if (switchResult.WithMinus) { ++index1; continue; } continue; case SwitchType.LimitedPostString: case SwitchType.UnLimitedPostString: int minLen = switchForm.MinLen; if (num2 < minLen) { throw new Exception("switch is not full"); } if (type == SwitchType.UnLimitedPostString) { switchResult.PostStrings.Add((object)srcString.Substring(index1)); return(true); } string str = srcString.Substring(index1, minLen); index1 += minLen; for (int index3 = minLen; index3 < switchForm.MaxLen && index1 < length1; ++index1) { char c = srcString[index1]; if (!Parser.IsItSwitchChar(c)) { str += c.ToString(); ++index3; } else { break; } } switchResult.PostStrings.Add((object)str); continue; case SwitchType.PostChar: if (num2 < switchForm.MinLen) { throw new Exception("switch is not full"); } string postCharSet = switchForm.PostCharSet; if (num2 == 0) { switchResult.PostCharIndex = -1; continue; } int num3 = postCharSet.IndexOf(srcString[index1]); if (num3 < 0) { switchResult.PostCharIndex = -1; continue; } switchResult.PostCharIndex = num3; ++index1; continue; default: continue; } } return(true); }
private bool ParseString(string srcString, SwitchForm[] switchForms) { int length = srcString.Length; if (length == 0) { return(false); } int num = 0; if (!IsItSwitchChar(srcString[num])) { return(false); } while (num < length) { if (IsItSwitchChar(srcString[num])) { num++; } int num2 = 0; int num3 = -1; for (int i = 0; i < _switches.Length; i++) { int length2 = switchForms[i].IDString.Length; if (length2 > num3 && num + length2 <= length && string.Compare(switchForms[i].IDString, 0, srcString, num, length2, ignoreCase: true) == 0) { num2 = i; num3 = length2; } } if (num3 == -1) { throw new Exception("maxLen == kNoLen"); } SwitchResult switchResult = _switches[num2]; SwitchForm switchForm = switchForms[num2]; if (!switchForm.Multi && switchResult.ThereIs) { throw new Exception("switch must be single"); } switchResult.ThereIs = true; num += num3; int num4 = length - num; SwitchType type = switchForm.Type; switch (type) { case SwitchType.PostMinus: if (num4 == 0) { switchResult.WithMinus = false; break; } switchResult.WithMinus = (srcString[num] == '-'); if (switchResult.WithMinus) { num++; } break; case SwitchType.PostChar: { if (num4 < switchForm.MinLen) { throw new Exception("switch is not full"); } string postCharSet = switchForm.PostCharSet; if (num4 == 0) { switchResult.PostCharIndex = -1; break; } int num6 = postCharSet.IndexOf(srcString[num]); if (num6 < 0) { switchResult.PostCharIndex = -1; break; } switchResult.PostCharIndex = num6; num++; break; } case SwitchType.LimitedPostString: case SwitchType.UnLimitedPostString: { int minLen = switchForm.MinLen; if (num4 < minLen) { throw new Exception("switch is not full"); } if (type == SwitchType.UnLimitedPostString) { switchResult.PostStrings.Add(srcString.Substring(num)); return(true); } string text = srcString.Substring(num, minLen); num += minLen; int num5 = minLen; while (num5 < switchForm.MaxLen && num < length) { char c = srcString[num]; if (IsItSwitchChar(c)) { break; } text += c; num5++; num++; } switchResult.PostStrings.Add(text); break; } } } return(true); }
private bool ParseString(string srcString, SwitchForm[] switchForms) { int length = srcString.Length; if (length == 0) { return(false); } int i = 0; if (!Parser.IsItSwitchChar(srcString[i])) { return(false); } while (i < length) { if (Parser.IsItSwitchChar(srcString[i])) { i++; } int num = 0; int num2 = -1; for (int j = 0; j < this._switches.Length; j++) { int length2 = switchForms[j].IDString.Length; if (length2 > num2 && i + length2 <= length) { if (string.Compare(switchForms[j].IDString, 0, srcString, i, length2, true) == 0) { num = j; num2 = length2; } } } if (num2 == -1) { throw new Exception("maxLen == kNoLen"); } SwitchResult switchResult = this._switches[num]; SwitchForm switchForm = switchForms[num]; if (!switchForm.Multi && switchResult.ThereIs) { throw new Exception("switch must be single"); } switchResult.ThereIs = true; i += num2; int num3 = length - i; SwitchType type = switchForm.Type; switch (type) { case SwitchType.PostMinus: if (num3 == 0) { switchResult.WithMinus = false; } else { switchResult.WithMinus = (srcString[i] == '-'); if (switchResult.WithMinus) { i++; } } break; case SwitchType.LimitedPostString: case SwitchType.UnLimitedPostString: { int minLen = switchForm.MinLen; if (num3 < minLen) { throw new Exception("switch is not full"); } if (type == SwitchType.UnLimitedPostString) { switchResult.PostStrings.Add(srcString.Substring(i)); return(true); } string text = srcString.Substring(i, minLen); i += minLen; int num4 = minLen; while (num4 < switchForm.MaxLen && i < length) { char c = srcString[i]; if (Parser.IsItSwitchChar(c)) { break; } text += c; num4++; i++; } switchResult.PostStrings.Add(text); break; } case SwitchType.PostChar: { if (num3 < switchForm.MinLen) { throw new Exception("switch is not full"); } string postCharSet = switchForm.PostCharSet; if (num3 == 0) { switchResult.PostCharIndex = -1; } else { int num5 = postCharSet.IndexOf(srcString[i]); if (num5 < 0) { switchResult.PostCharIndex = -1; } else { switchResult.PostCharIndex = num5; i++; } } break; } } } return(true); }