/// <summary> /// If compSwitch is the compSwitchInfo compiler switch, then extract the switch args /// Return /// - true: if this is the switch (even if the switch args have error) /// - false: this is not the switch /// </summary> private bool ExtractSwitchInfo(CompSwitchInfo compSwitchInfo, string compSwitch) { string matchedID = null; // First see if we have a match... for (int i = 0; i < compSwitchInfo.SwitchIDs.Length; i++) { if (compSwitch.StartsWith(compSwitchInfo.SwitchIDs[i], StringComparison.Ordinal)) { matchedID = compSwitchInfo.SwitchIDs[i]; break; } } // No no... we arent dealing with the correct switchInfo if (null == matchedID) { return(false); } // Now we can get to extracting the switch arguments object switchVal = null; switch (compSwitchInfo.SwitchValueType) { case SwitchValueType.SVT_Boolean: if (matchedID.Length == compSwitch.Length) { switchVal = true; } else if ((matchedID.Length + 1) == compSwitch.Length) { if ('+' == compSwitch[matchedID.Length]) { switchVal = true; } else if ('-' == compSwitch[matchedID.Length]) { switchVal = false; } } if (null != switchVal) { compSwitchInfo.SwitchValue = switchVal; } else { Debug.Assert(false, "Cannot parse boolean switch: " + compSwitch); } break; case SwitchValueType.SVT_String: if (matchedID.Length < compSwitch.Length) { switchVal = compSwitch.Substring(matchedID.Length); } if (null != switchVal) { compSwitchInfo.SwitchValue = switchVal; } else { Debug.Assert(false, "Cannot parse string switch: " + compSwitch); } break; case SwitchValueType.SVT_MultiString: Debug.Assert( null != compSwitchInfo.SwitchValue, "Non null switch value expected for a multistring switch: " + matchedID ); if (matchedID.Length < compSwitch.Length) { switchVal = compSwitch.Substring(matchedID.Length); } if (null != switchVal) { ((StringBuilder)(compSwitchInfo.SwitchValue)).Append(switchVal); ((StringBuilder)(compSwitchInfo.SwitchValue)).Append(";"); } else { Debug.Assert(false, "Cannot parse multistring switch: " + compSwitch); } break; default: Debug.Assert(false, "Unknown switch value type"); break; } return(true); }
/// <summary> /// If compSwitch is the compSwitchInfo compiler switch, then extract the switch args /// Return /// - true: if this is the switch (even if the switch args have error) /// - false: this is not the switch /// </summary> private bool ExtractSwitchInfo(CompSwitchInfo compSwitchInfo, string compSwitch) { string matchedID = null; // First see if we have a match... for (int i=0; i<compSwitchInfo.SwitchIDs.Length; i++) { if (compSwitch.StartsWith(compSwitchInfo.SwitchIDs[i], StringComparison.Ordinal)) { matchedID = compSwitchInfo.SwitchIDs[i]; break; } } // No no... we arent dealing with the correct switchInfo if (null == matchedID) { return false; } // Now we can get to extracting the switch arguments object switchVal = null; switch (compSwitchInfo.SwitchValueType) { case SwitchValueType.SVT_Boolean: if (matchedID.Length == compSwitch.Length) { switchVal = true; } else if ((matchedID.Length + 1) == compSwitch.Length) { if ('+' == compSwitch[matchedID.Length]) { switchVal = true; } else if ('-' == compSwitch[matchedID.Length]) { switchVal = false; } } if (null != switchVal) { compSwitchInfo.SwitchValue = switchVal; } else { Debug.Assert(false, "Cannot parse boolean switch: " + compSwitch); } break; case SwitchValueType.SVT_String: if (matchedID.Length < compSwitch.Length) { switchVal = compSwitch.Substring(matchedID.Length); } if (null != switchVal) { compSwitchInfo.SwitchValue = switchVal; } else { Debug.Assert(false, "Cannot parse string switch: " + compSwitch); } break; case SwitchValueType.SVT_MultiString: Debug.Assert( null != compSwitchInfo.SwitchValue, "Non null switch value expected for a multistring switch: " + matchedID ); if (matchedID.Length < compSwitch.Length) { switchVal = compSwitch.Substring(matchedID.Length); } if (null != switchVal) { ((StringBuilder)(compSwitchInfo.SwitchValue)).Append(switchVal); ((StringBuilder)(compSwitchInfo.SwitchValue)).Append(";"); } else { Debug.Assert(false, "Cannot parse multistring switch: " + compSwitch); } break; default: Debug.Assert(false, "Unknown switch value type"); break; } return true; }