Exemplo n.º 1
0
 static bool CheckForDoubleEscapedLiteralCharacter(char[] formatArray, int startPosition,
                                                   out string result, out string error)
 {
     error  = "";
     result = DateTimeParser.ForwardLookup(formatArray, startPosition, 2);
     return(result == "''");
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Performs a forward lookup for the given forwardLookupIndex and checks the results against known
        ///     date time format parts. Returns true if part is found otherwise false.
        /// </summary>
        private static bool TryGetDateTimeFormatPart(char[] formatArray, int startPosition, char forwardLookupIndex,
                                                     Dictionary <char, List <int> > dateTimeFormatForwardLookups,
                                                     Dictionary <string, List <IDateTimeFormatPartOptionTO> > dateTimeFormatPartOptions, out string result,
                                                     out string error)
        {
            bool nothingDied = true;

            error  = "";
            result = "";

            List <int> lookupLengths;

            if (dateTimeFormatForwardLookups.TryGetValue(forwardLookupIndex, out lookupLengths))
            {
                //
                // Perform all forward lookups
                //
                List <string> lookupResults =
                    lookupLengths.Select(i => DateTimeParser.ForwardLookup(formatArray, startPosition, i)).ToList();

                int count = 0;
                while (count < lookupResults.Count && nothingDied)
                {
                    //
                    // Check if forward lookup result is a known date time format part
                    //
                    List <IDateTimeFormatPartOptionTO> tmp;
                    if (dateTimeFormatPartOptions.TryGetValue(lookupResults[count], out tmp))
                    {
                        result = lookupResults[count];
                        count  = lookupResults.Count;
                    }
                    else if (count == lookupLengths.Count - 1)
                    {
                        nothingDied = false;
                        error       =
                            string.Concat("Failed to find any format part matches in forward lookups from character '",
                                          forwardLookupIndex, "' at index ", startPosition, " of format.");
                    }

                    count++;
                }
            }
            else
            {
                nothingDied = false;
                error       = string.Format(ErrorResource.UnexpectedCharacterAtIndex, startPosition);
            }

            return(nothingDied);
        }
Exemplo n.º 3
0
        static bool TryGetDateTimeFormatPart(char[] formatArray, int startPosition, char forwardLookupIndex,
                                             Dictionary <char, List <int> > dateTimeFormatForwardLookups,
                                             Dictionary <string, List <IDateTimeFormatPartOptionTO> > dateTimeFormatPartOptions, out string result,
                                             out string error)
        {
            var nothingDied = true;

            error  = "";
            result = "";

            List <int> lookupLengths;

            if (dateTimeFormatForwardLookups.TryGetValue(forwardLookupIndex, out lookupLengths))
            {
                var lookupResults =
                    lookupLengths.Select(i => DateTimeParser.ForwardLookup(formatArray, startPosition, i)).ToList();

                var count = 0;
                while (count < lookupResults.Count && nothingDied)
                {
                    //
                    // Check if forward lookup result is a known date time format part
                    //
                    List <IDateTimeFormatPartOptionTO> tmp;
                    if (dateTimeFormatPartOptions.TryGetValue(lookupResults[count], out tmp))
                    {
                        result = lookupResults[count];
                        count  = lookupResults.Count;
                    }
                    else
                    {
                        CheckLookupLengths(startPosition, forwardLookupIndex, lookupLengths, count, ref error, ref nothingDied);
                    }

                    count++;
                }
            }
            else
            {
                nothingDied = false;
                error       = string.Format(ErrorResource.UnexpectedCharacterAtIndex, startPosition);
            }

            return(nothingDied);
        }