internal bool TryParse(string input, ref TimeSpanParse.TimeSpanResult result) { long num; result.parsedTimeSpan._ticks = 0L; if (input == null) { result.SetFailure(TimeSpanParse.ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "input"); return false; } this.str = input; this.len = input.Length; this.pos = -1; this.NextChar(); this.SkipBlanks(); bool flag = false; if (this.ch == '-') { flag = true; this.NextChar(); } if (this.NextNonDigit() == ':') { if (!this.ParseTime(out num, ref result)) { return false; } } else { int num2; if (!this.ParseInt(0xa2e3ff, out num2, ref result)) { return false; } num = num2 * 0xc92a69c000L; if (this.ch == '.') { long num3; this.NextChar(); if (!this.ParseTime(out num3, ref result)) { return false; } num += num3; } } if (flag) { num = -num; if (num > 0L) { result.SetFailure(TimeSpanParse.ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge"); return false; } } else if (num < 0L) { result.SetFailure(TimeSpanParse.ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge"); return false; } this.SkipBlanks(); if (this.pos < this.len) { result.SetFailure(TimeSpanParse.ParseFailureKind.Format, "Format_BadTimeSpan"); return false; } result.parsedTimeSpan._ticks = num; return true; }
private bool AddNum(TimeSpanParse.TimeSpanToken num, ref TimeSpanParse.TimeSpanResult result) { if ((this.NumCount >= 5) || (this.tokenCount >= 11)) { result.SetFailure(TimeSpanParse.ParseFailureKind.Format, "Format_BadTimeSpan", null); return false; } this.numbers[this.NumCount++] = num; this.tokenCount++; return true; }
private bool AddSep(string sep, ref TimeSpanParse.TimeSpanResult result) { if ((this.SepCount >= 6) || (this.tokenCount >= 11)) { result.SetFailure(TimeSpanParse.ParseFailureKind.Format, "Format_BadTimeSpan", null); return false; } this.literals[this.SepCount++] = sep; this.tokenCount++; return true; }
internal bool ProcessToken(ref TimeSpanParse.TimeSpanToken tok, ref TimeSpanParse.TimeSpanResult result) { if (tok.ttt == TimeSpanParse.TTT.NumOverflow) { result.SetFailure(TimeSpanParse.ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge", null); return false; } if ((tok.ttt != TimeSpanParse.TTT.Sep) && (tok.ttt != TimeSpanParse.TTT.Num)) { result.SetFailure(TimeSpanParse.ParseFailureKind.Format, "Format_BadTimeSpan", null); return false; } switch (tok.ttt) { case TimeSpanParse.TTT.Num: if ((this.tokenCount != 0) || this.AddSep(string.Empty, ref result)) { if (!this.AddNum(tok, ref result)) { return false; } break; } return false; case TimeSpanParse.TTT.Sep: if (this.AddSep(tok.sep, ref result)) { break; } return false; } this.lastSeenTTT = tok.ttt; return true; }
internal bool ParseTime(out long time, ref TimeSpanParse.TimeSpanResult result) { int num; time = 0L; if (!this.ParseInt(0x17, out num, ref result)) { return false; } time = num * 0x861c46800L; if (this.ch != ':') { result.SetFailure(TimeSpanParse.ParseFailureKind.Format, "Format_BadTimeSpan"); return false; } this.NextChar(); if (!this.ParseInt(0x3b, out num, ref result)) { return false; } time += num * 0x23c34600L; if (this.ch == ':') { this.NextChar(); if (this.ch != '.') { if (!this.ParseInt(0x3b, out num, ref result)) { return false; } time += num * 0x989680L; } if (this.ch == '.') { this.NextChar(); int num2 = 0x989680; while (((num2 > 1) && (this.ch >= '0')) && (this.ch <= '9')) { num2 /= 10; time += (this.ch - '0') * num2; this.NextChar(); } } } return true; }
internal bool ParseInt(int max, out int i, ref TimeSpanParse.TimeSpanResult result) { i = 0; int pos = this.pos; while ((this.ch >= '0') && (this.ch <= '9')) { if ((((long) i) & 0xf0000000L) != 0L) { result.SetFailure(TimeSpanParse.ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge"); return false; } i = ((i * 10) + this.ch) - 0x30; if (i < 0) { result.SetFailure(TimeSpanParse.ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge"); return false; } this.NextChar(); } if (pos == this.pos) { result.SetFailure(TimeSpanParse.ParseFailureKind.Format, "Format_BadTimeSpan"); return false; } if (i > max) { result.SetFailure(TimeSpanParse.ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge"); return false; } return true; }