private TimeSpan?LookForHourChar(TimeState state, bool beenHere = false) { while (true) { char c = _stream.ReadChar(); if (c == EOF) { return(beenHere && state.IsComplete ? state.ToTimeSpan() : null); } switch (c) { case '0': case '1': case '2': if (beenHere) { state.Hour *= 10; state.Hour += c - ZERO_CHAR; return(LookForDelimiter(state)); } else { state.Hour = c - ZERO_CHAR; beenHere = true; continue; } case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (beenHere) { state.Hour *= 10; state.Hour += c - ZERO_CHAR; } else { state.Hour = c - ZERO_CHAR; } return(LookForDelimiter(state)); case ' ': case '\t': case '\r': case '\n': beenHere = false; continue; default: return(null); } } }
private static TimeSpan?Finish(TimeState state) { return(state.IsComplete ? state.ToTimeSpan() : null); }
private TimeSpan?LookForMinuteChar(TimeState state, bool beenHere = false) { while (true) { char c = _stream.ReadChar(); if (c == EOF) { return(beenHere && state.IsComplete ? state.ToTimeSpan() : null); } switch (c) { case 'a': case 'A': case 'p': case 'P': _stream.Backup(1); return(LookForAmPm(state)); case ' ': case '\t': case '\r': case '\n': beenHere = false; continue; case '0': case '1': case '2': case '3': case '4': case '5': if (beenHere) { state.Minute *= 10; state.Minute += c - ZERO_CHAR; return(LookForAmPm(state)); } else { state.Minute = c - ZERO_CHAR; beenHere = true; continue; } case '6': case '7': case '8': case '9': if (!beenHere) { return(null); // minutes can't start with 6-9 } state.Minute *= 10; state.Minute += c - ZERO_CHAR; return(LookForAmPm(state)); default: return(null); // invalid character } } }
private TimeSpan? LookForMinuteChar(TimeState state, bool beenHere = false) { while (true) { char c = _stream.ReadChar(); if (c == EOF) return beenHere && state.IsComplete ? state.ToTimeSpan() : null; switch (c) { case 'a': case 'A': case 'p': case 'P': _stream.Backup(1); return LookForAmPm(state); case ' ': case '\t': case '\r': case '\n': beenHere = false; continue; case '0': case '1': case '2': case '3': case '4': case '5': if (beenHere) { state.Minute *= 10; state.Minute += c - ZERO_CHAR; return LookForAmPm(state); } else { state.Minute = c - ZERO_CHAR; beenHere = true; continue; } case '6': case '7': case '8': case '9': if (!beenHere) return null; // minutes can't start with 6-9 state.Minute *= 10; state.Minute += c - ZERO_CHAR; return LookForAmPm(state); default: return null; // invalid character } } }
private TimeSpan? LookForHourChar(TimeState state, bool beenHere = false) { while (true) { char c = _stream.ReadChar(); if (c == EOF) return beenHere && state.IsComplete ? state.ToTimeSpan() : null; switch (c) { case '0': case '1': case '2': if (beenHere) { state.Hour *= 10; state.Hour += c - ZERO_CHAR; return LookForDelimiter(state); } else { state.Hour = c - ZERO_CHAR; beenHere = true; continue; } case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (beenHere) { state.Hour *= 10; state.Hour += c - ZERO_CHAR; } else state.Hour = c - ZERO_CHAR; return LookForDelimiter(state); case ' ': case '\t': case '\r': case '\n': beenHere = false; continue; default: return null; } } }
private static TimeSpan? Finish(TimeState state) { return state.IsComplete ? state.ToTimeSpan() : null; }
private TimeSpan? LookForHourChar(TimeState state, bool beenHere = false) { char c = stream.ReadChar(); if (c == EOF) return beenHere && state.IsComplete ? state.ToTimeSpan() : null; switch (c) { case '0': case '1': case '2': if (beenHere) { state.Hour *= 10; state.Hour += ((int)c) - zeroChar; return LookForDelimiter(state); } else { state.Hour = ((int)c) - zeroChar; return LookForHourChar(state, true); } case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (beenHere) { state.Hour *= 10; state.Hour += ((int)c) - zeroChar; } else state.Hour = ((int)c) - zeroChar; return LookForDelimiter(state); case ' ': case '\t': case '\r': case '\n': return LookForHourChar(state, false); default: return null; } }