예제 #1
0
 public static char ToUpper(this char chr, [NotNull] CultureInfo culture) =>
 CharEx.ToUpper(chr, culture);
예제 #2
0
        public static int B_ToNumber(ILuaState lua)
        {
            LuaType t = lua.Type(2);

            if (t == LuaType.LUA_TNONE || t == LuaType.LUA_TNIL)              // standard conversion
            {
                bool   isnum;
                double n = lua.ToNumberX(1, out isnum);
                if (isnum)
                {
                    lua.PushNumber(n);
                    return(1);
                }                 // else not a number; must be something
                lua.L_CheckAny(1);
            }
            else
            {
                string s        = lua.L_CheckString(1);
                int    numBase  = lua.L_CheckInteger(2);
                bool   negative = false;
                lua.L_ArgCheck((2 <= numBase && numBase <= 36), 2,
                               "base out of range");
                s = s.Trim(' ', '\f', '\n', '\r', '\t', '\v');
                s = s + '\0';                 // guard
                int pos = 0;
                if (s[pos] == '-')
                {
                    pos++; negative = true;
                }
                else if (s[pos] == '+')
                {
                    pos++;
                }
                if (Char.IsLetterOrDigit(s, pos))
                {
                    double n = 0.0;
                    do
                    {
                        int digit;
                        if (Char.IsDigit(s, pos))
                        {
                            digit = Int32.Parse(s[pos].ToString());
                        }
                        else
                        {
                            digit = Char.ToUpper(s[pos]) - 'A' + 10;
                        }
                        if (digit >= numBase)
                        {
                            break;                             // invalid numeral; force a fail
                        }
                        n = n * (double)numBase + (double)digit;
                        pos++;
                    } while(Char.IsLetterOrDigit(s, pos));
                    if (pos == s.Length - 1)                      // except guard, no invalid trailing characters?
                    {
                        lua.PushNumber(negative ? -n : n);
                        return(1);
                    }             // else not a number
                }                 // else not a number
            }
            lua.PushNil();        // not a number
            return(1);
        }