subtitleMemorize.UtilsInputFiles.TokenizeInputString C# (CSharp) Method

TokenizeInputString() private method

Splits the input string on special charcters '<', >', '=' and ','. In case these characters are precedented by '\' they become normal characters and the string will not be split at this point. <encoding=utf-8,>
private TokenizeInputString ( String inputStr ) : String[]
inputStr String
return String[]
		private String[] TokenizeInputString(String inputStr) {
			LinkedList<String> strings = new LinkedList<String> ();


			int beginInterval = 0;
			int intervalLength = 0;
			bool nextIsEscapeChar = false;
			while (true) {
				char c = inputStr [beginInterval + intervalLength];

				if (nextIsEscapeChar) {
					if (c != '<' && c != '>' && c != '=' && c != ',' && c != '\\')
						throw new Exception ("Unknow escape character '" + c.ToString () + "'");
					nextIsEscapeChar = false;
					// nothing special, because this character is normal
				} else if (c == '\\') {
					nextIsEscapeChar = true;
				} else {
					if (c == '<' || c == '>' || c == '=' || c == ',') {
						if(intervalLength > 0) strings.AddLast (inputStr.Substring (beginInterval, intervalLength)); // text before special character
						strings.AddLast (inputStr.Substring (beginInterval + intervalLength, 1)); // special character

						// reset interval values
						beginInterval = beginInterval + intervalLength + 1;
						intervalLength = 0;

						if (beginInterval >= inputStr.Length)
							break;

						// counter next increment
						intervalLength--;
					}
				}


				// next character
				intervalLength++;

				if (beginInterval + intervalLength >= inputStr.Length)
					break;
			}

			// unhandled escape char
			if (nextIsEscapeChar)
				throw new Exception ("Unexpected EOL (unfinished escape sequence)");

				strings.AddLast (inputStr.Substring (beginInterval));

			// remove first and last empty strings
			while (strings.First.Value == "")
				strings.RemoveFirst ();
			while (strings.Last.Value == "")
				strings.RemoveLast ();


			return strings.ToArray ();
		}