Пример #1
0
 private static bool ProcessTerminalState(ref NumberSpanRawInfo raw, NumberSpanStandardStyles style, ref NumberSpanResult result)
 {
     if (raw._lastSeenTTT == TTT.Num)
     {
         var tok = new NumberSpanToken
         {
             _ttt = TTT.Sep,
             _sep = string.Empty
         };
         if (!raw.ProcessToken(ref tok, ref result))
         {
             result.SetFailure(ParseFailureKind.Format, "Format_BadNumberSpan");
             return false;
         }
     }
     switch (raw._numCount)
     {
         case 1: return ProcessTerminal_C(ref raw, style, ref result);
         case 2: return ProcessTerminal_CT(ref raw, style, ref result);
         case 3: return ProcessTerminal_FULL(ref raw, style, ref result);
     }
     result.SetFailure(ParseFailureKind.Format, "Format_BadNumberSpan");
     return false;
 }
Пример #2
0
 private static bool TryParseNumberSpan(string input, NumberSpanStandardStyles style, IFormatProvider formatProvider, ref NumberSpanResult result)
 {
     if (input == null)
     {
         result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "input");
         return false;
     }
     input = input.Trim();
     if (input == string.Empty)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadNumberSpan");
         return false;
     }
     var tokenizer = new NumberSpanTokenizer();
     tokenizer.Init(input);
     var raw = new NumberSpanRawInfo();
     raw.Init(); //DateTimeFormatInfo.GetInstance(formatProvider));
     for (var token = tokenizer.GetNextToken(); token._ttt != TTT.End; token = tokenizer.GetNextToken())
         if (!raw.ProcessToken(ref token, ref result))
         {
             result.SetFailure(ParseFailureKind.Format, "Format_BadNumberSpan");
             return false;
         }
     if (!tokenizer.EOL)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadNumberSpan");
         return false;
     }
     if (!ProcessTerminalState(ref raw, style, ref result))
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadNumberSpan");
         return false;
     }
     return true;
 }