public static void ParseParameters(String parametersString, List <String> parameterList) { if (parametersString == null) { return; } if (parametersString.Length <= 0) { return; } Int32 offset = 0; while (true) { while (true) { Char c = parametersString[offset]; if (Sos.IsValidStartOfSosString(c)) { break; } if (!Char.IsWhiteSpace(c)) { throw new FormatException(String.Format( "Every parameter string must start with 0-9,a-z,A-Z,\",[,{{ or ', but parameter {0} started with '{1}' (charcode={2})", parameterList.Count, c, (UInt32)c)); } offset++; if (offset >= parametersString.Length) { return; } } Int32 nextSpace = Sos.NextNonQuotedWhitespace(parametersString, offset); parameterList.Add(parametersString.Substring(offset, nextSpace - offset)); offset = nextSpace + 1; if (offset >= parametersString.Length) { return; } } }
public void TestInvalidStringsForNextWhitespace() { String[] invalidStrings = new String[] { "\" ", "\"\\\\\\\" ", }; for (int i = 0; i < invalidStrings.Length; i++) { String invalidString = invalidStrings[i]; try { Sos.NextNonQuotedWhitespace(invalidString, 0); Assert.Fail("Expected format exception but didn't get one for '{0}'", invalidString); } catch (FormatException e) { Console.WriteLine("Expected format exception for '{0}': {1}", invalidString, e.Message); } } }
public void NextWhitespaceTest() { String[] validStrings = new String[] { "0 ", "9 ", "a ", "z ", "A ", "Z ", "\"\" ", "\"\\\"\" ", "\"\\\\\\\"\" ", "[ ", "{ ", }; for (int i = 0; i < validStrings.Length; i++) { String validString = validStrings[i]; Int32 offset = Sos.NextNonQuotedWhitespace(validString, 0); Assert.AreEqual(validString.Length - 1, offset); } }