1 using System.Globalization;
3 namespace System.Windows
6 /// Helper class for parsing serialized data structures from the System.Windows namespace.
8 internal class NumericListTokenizer
10 private readonly string _str;
11 private readonly char _separator;
12 private int _position;
22 public NumericListTokenizer (string str, IFormatProvider formatProvider)
24 _str = str ?? throw new ArgumentNullException (nameof(str));
25 _separator = GetSeparator (formatProvider ?? throw new ArgumentNullException (nameof(formatProvider)));
28 public static char GetSeparator (IFormatProvider formatProvider)
30 // By convention, string representations of target classes always use ';' as a separator
31 // if the decimal number separator is ','. Otherwise, the separator is ','.
32 return NumberFormatInfo.GetInstance (formatProvider).NumberDecimalSeparator != "," ? ',' : ';';
35 private Symbol GetCurrentSymbol ()
37 if (_position >= _str.Length)
38 return Symbol.EndOfLine;
39 if (_str[_position] == _separator)
40 return Symbol.Separator;
41 if (char.IsWhiteSpace (_str, _position))
42 return Symbol.Whitspace;
46 private void SkipAllWhitespaces ()
48 while (GetCurrentSymbol () == Symbol.Whitspace)
54 private void SkipNextDelimeter ()
56 SkipAllWhitespaces ();
57 switch (GetCurrentSymbol ())
61 case Symbol.Separator:
63 SkipAllWhitespaces ();
66 throw new InvalidOperationException ("Separator not found");
70 public bool HasNoMoreTokens ()
72 SkipAllWhitespaces ();
73 return GetCurrentSymbol () == Symbol.EndOfLine;
76 public string GetNextToken ()
81 SkipAllWhitespaces ();
88 while (GetCurrentSymbol () == Symbol.Token)
96 throw new InvalidOperationException ("Next token not found");
99 return _str.Substring (_position - length, length);