示例#1
0
        /// <summary>
        /// Attempts to parse a method call with format MethodId(Args)
        /// </summary>
        static public bool TryParse(StringSlice inData, out MethodCall outMethodCall)
        {
            int openParenIdx  = inData.IndexOf('(');
            int closeParenIdx = inData.LastIndexOf(')');

            if (openParenIdx <= 0 || closeParenIdx <= 0 || closeParenIdx <= openParenIdx)
            {
                outMethodCall = default(MethodCall);
                return(false);
            }

            StringSlice methodSlice = inData.Substring(0, openParenIdx).Trim();

            if (!VariantUtils.IsValidIdentifier(methodSlice))
            {
                outMethodCall = default(MethodCall);
                return(false);
            }

            StringSlice afterMethod = inData.Substring(closeParenIdx + 1);

            if (!afterMethod.IsWhitespace)
            {
                outMethodCall = default(MethodCall);
                return(false);
            }

            int argsLength = closeParenIdx - 1 - openParenIdx;

            outMethodCall.Id   = methodSlice.Hash32();
            outMethodCall.Args = inData.Substring(openParenIdx + 1, argsLength).Trim();

            return(true);
        }