Beispiel #1
0
        /// <summary>
        /// Matches a <see cref="DateTimeStamp"/>.
        /// </summary>
        /// <param name="this">This <see cref="StringMatcher"/>.</param>
        /// <param name="time">Resulting time stamp on successful match; <see cref="DateTimeStamp.Unknown"/> otherwise.</param>
        /// <returns>True if the time stamp has been matched.</returns>
        static public bool MatchDateTimeStamp(this StringMatcher @this, out DateTimeStamp time)
        {
            time = DateTimeStamp.Unknown;
            int      savedIndex = @this.StartIndex;
            DateTime t;

            if ([email protected](out t))
            {
                return(@this.SetError());
            }
            byte uniquifier = 0;

            if (@this.MatchChar('('))
            {
                int unique;
                if ([email protected](out unique, 0, 255) || [email protected](')'))
                {
                    return(@this.BackwardAddError(savedIndex));
                }
                uniquifier = (byte)unique;
            }
            time = new DateTimeStamp(t, uniquifier);
            return(@this.Forward(0));
        }
Beispiel #2
0
        /// <summary>
        /// Tries to parse a string formatted with the <see cref="FileNameUniqueTimeUtcFormat"/>.
        /// The string must contain only the time unless <paramref name="allowSuffix"/> is true.
        /// </summary>
        /// <param name="s">The string to parse.</param>
        /// <param name="time">Result time on success.</param>
        /// <param name="allowSuffix">True to accept a string that starts with the time and contains more text.</param>
        /// <returns>True if the string has been successfully parsed.</returns>
        public static bool TryParseFileNameUniqueTimeUtcFormat(string s, out DateTime time, bool allowSuffix = false)
        {
            var m = new StringMatcher(s);

            return(m.MatchFileNameUniqueTimeUtcFormat(out time) && (allowSuffix || m.IsEnd));
        }