Пример #1
0
        public static bool StartsWith(this StringReference s, string text)
        {
            if (text.Length > s.Length)
            {
                return(false);
            }

            char[] chars = s.Chars;

            for (int i = 0; i < text.Length; i++)
            {
                if (text[i] != chars[i + s.StartIndex])
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
 public static int IndexOf(this StringReference s, char c)
 {
     return(IndexOf(s, c, 0, 0));
 }
Пример #3
0
        internal static bool TryParseDateTimeIso(StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt)
        {
            DateTimeParser dateTimeParser = new DateTimeParser();

            if (!dateTimeParser.Parse(text.Chars, text.StartIndex, text.Length))
            {
                dt = default(DateTime);
                return(false);
            }

            DateTime d = new DateTime(dateTimeParser.Year, dateTimeParser.Month, dateTimeParser.Day, dateTimeParser.Hour, dateTimeParser.Minute, dateTimeParser.Second);

            d = d.AddTicks(dateTimeParser.Fraction);

            long ticks;

            switch (dateTimeParser.Zone)
            {
            case ParserTimeZone.Utc:
                d = new DateTime(d.Ticks, DateTimeKind.Utc);
                break;

            case ParserTimeZone.LocalWestOfUtc:
            {
                TimeSpan offset = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0);
                ticks = d.Ticks + offset.Ticks;
                if (ticks <= DateTime.MaxValue.Ticks)
                {
                    d = new DateTime(ticks, DateTimeKind.Utc).ToLocalTime();
                }
                else
                {
                    ticks += d.GetUtcOffset().Ticks;
                    if (ticks > DateTime.MaxValue.Ticks)
                    {
                        ticks = DateTime.MaxValue.Ticks;
                    }

                    d = new DateTime(ticks, DateTimeKind.Local);
                }
                break;
            }

            case ParserTimeZone.LocalEastOfUtc:
            {
                TimeSpan offset = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0);
                ticks = d.Ticks - offset.Ticks;
                if (ticks >= DateTime.MinValue.Ticks)
                {
                    d = new DateTime(ticks, DateTimeKind.Utc).ToLocalTime();
                }
                else
                {
                    ticks += d.GetUtcOffset().Ticks;
                    if (ticks < DateTime.MinValue.Ticks)
                    {
                        ticks = DateTime.MinValue.Ticks;
                    }

                    d = new DateTime(ticks, DateTimeKind.Local);
                }
                break;
            }
            }

            dt = EnsureDateTime(d, dateTimeZoneHandling);
            return(true);
        }