Exemplo n.º 1
0
 internal static void HandleBackslash(PatternCursor pattern, SteppedPatternBuilder <TResult, TBucket> builder)
 {
     if (!pattern.MoveNext())
     {
         throw new InvalidPatternException(TextErrorMessages.EscapeAtEndOfString);
     }
     builder.AddLiteral(pattern.Current, ParseResult <TResult> .EscapedCharacterMismatch);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Handle a leading "%" which acts as a pseudo-escape - it's mostly used to allow format strings such as "%H" to mean
 /// "use a custom format string consisting of H instead of a standard pattern H".
 /// </summary>
 internal static void HandlePercent(PatternCursor pattern, SteppedPatternBuilder <TResult, TBucket> builder)
 {
     if (pattern.HasMoreCharacters)
     {
         if (pattern.PeekNext() != '%')
         {
             // Handle the next character as normal
             return;
         }
         throw new InvalidPatternException(TextErrorMessages.PercentDoubled);
     }
     throw new InvalidPatternException(TextErrorMessages.PercentAtEndOfString);
 }
Exemplo n.º 3
0
        private static void HandleHalfAmPmDesignator <TResult, TBucket>
            (int count, string specifiedDesignator, int specifiedDesignatorValue, Func <TResult, int> hourOfDayGetter, Action <TBucket, int> amPmSetter,
            SteppedPatternBuilder <TResult, TBucket> builder)
            where TBucket : ParseBucket <TResult>
        {
            CompareInfo compareInfo = builder.FormatInfo.CompareInfo;

            if (count == 1)
            {
                string abbreviation = specifiedDesignator.Substring(0, 1);
                builder.AddParseAction((str, bucket) =>
                {
                    int value = str.MatchCaseInsensitive(abbreviation, compareInfo, true) ? specifiedDesignatorValue : 1 - specifiedDesignatorValue;
                    amPmSetter(bucket, value);
                    return(null);
                });
                builder.AddFormatAction((value, sb) =>
                {
                    // Only append anything if it's the non-empty designator.
                    if (hourOfDayGetter(value) / 12 == specifiedDesignatorValue)
                    {
                        sb.Append(specifiedDesignator[0]);
                    }
                });
                return;
            }
            builder.AddParseAction((str, bucket) =>
            {
                int value = str.MatchCaseInsensitive(specifiedDesignator, compareInfo, true) ? specifiedDesignatorValue : 1 - specifiedDesignatorValue;
                amPmSetter(bucket, value);
                return(null);
            });
            builder.AddFormatAction((value, sb) =>
            {
                // Only append anything if it's the non-empty designator.
                if (hourOfDayGetter(value) / 12 == specifiedDesignatorValue)
                {
                    sb.Append(specifiedDesignator);
                }
            });
        }
Exemplo n.º 4
0
        internal static void HandleQuote(PatternCursor pattern, SteppedPatternBuilder <TResult, TBucket> builder)
        {
            string quoted = pattern.GetQuotedString(pattern.Current);

            builder.AddLiteral(quoted, ParseResult <TResult> .QuotedStringMismatch);
        }