System.Char.IsWhiteSpace C# (CSharp) Method

IsWhiteSpace() public static method

public static IsWhiteSpace ( char c ) : bool
c char
return bool
        public static bool IsWhiteSpace(char c)
        {
            return (IsWhiteSpaceLatin1(c));
        }

Usage Example

Esempio n. 1
0
        internal static bool Parse(string s, bool tryParse, out int result, out Exception exc)
        {
            int  val = 0;
            int  len;
            int  i, sign = 1;
            bool digits_seen = false;

            result = 0;
            exc    = null;
            NumberFormatInfo nfi = Thread.CurrentThread.CurrentCulture.NumberFormat;

            if (s == null)
            {
                if (!tryParse)
                {
                    exc = new ArgumentNullException("s");
                }
                return(false);
            }

            len = s.Length;

            char c;

            for (i = 0; i < len; i++)
            {
                c = s [i];
                if (!Char.IsWhiteSpace(c))
                {
                    break;
                }
            }

            if (i == len)
            {
                if (!tryParse)
                {
                    exc = GetFormatException();
                }
                return(false);
            }

            var ps_length = nfi.PositiveSign.Length;
            var ns_length = nfi.NegativeSign.Length;

            if (len > ps_length && string.CompareOrdinalUnchecked(s, i, ns_length, nfi.PositiveSign, 0, ps_length) == 0)
            {
                i += ps_length;
            }
            else if (len > ns_length && string.CompareOrdinalUnchecked(s, i, ns_length, nfi.NegativeSign, 0, ns_length) == 0)
            {
                sign = -1;
                i   += ns_length;
            }

            for (; i < len; i++)
            {
                c = s [i];

                if (c == '\0')
                {
                    i = len;
                    continue;
                }

                if (c >= '0' && c <= '9')
                {
                    byte d = (byte)(c - '0');

                    if (val > (MaxValue / 10))
                    {
                        goto overflow;
                    }

                    if (val == (MaxValue / 10))
                    {
                        if ((d > (MaxValue % 10)) && (sign == 1 || (d > ((MaxValue % 10) + 1))))
                        {
                            goto overflow;
                        }
                        if (sign == -1)
                        {
                            val = (val * sign * 10) - d;
                        }
                        else
                        {
                            val = (val * 10) + d;
                        }

                        if (ProcessTrailingWhitespace(tryParse, s, i + 1, ref exc))
                        {
                            result = val;
                            return(true);
                        }
                        goto overflow;
                    }
                    else
                    {
                        val = val * 10 + d;
                    }

                    digits_seen = true;
                }
                else if (!ProcessTrailingWhitespace(tryParse, s, i, ref exc))
                {
                    return(false);
                }
            }
            if (!digits_seen)
            {
                if (!tryParse)
                {
                    exc = GetFormatException();
                }
                return(false);
            }

            if (sign == -1)
            {
                result = val * sign;
            }
            else
            {
                result = val;
            }

            return(true);

overflow:
            if (!tryParse)
            {
                exc = new OverflowException("Value is too large");
            }
            return(false);
        }
All Usage Examples Of System.Char::IsWhiteSpace