Trim() private method

private Trim ( string thisObject ) : string
thisObject string
return string
示例#1
0
        public FunctionInstance Construct(params string[] argumentsAndBody)
        {
            // Passing no arguments results in an empty function.
            if (argumentsAndBody.Length == 0)
            {
                return(new UserDefinedFunction(this.InstancePrototype, "anonymous", new string[0], string.Empty));
            }

            // Split any comma-delimited names.
            var argumentNames = new List <string>();

            for (int i = 0; i < argumentsAndBody.Length - 1; i++)
            {
                var splitNames = argumentsAndBody[i].Split(',');
                if (splitNames.Length > 1 || StringInstance.Trim(splitNames[0]) != string.Empty)
                {
                    for (int j = 0; j < splitNames.Length; j++)
                    {
                        // Trim any whitespace from the start and end of the argument name.
                        string argumentName = StringInstance.Trim(splitNames[j]);
                        if (argumentName == string.Empty)
                        {
                            throw new JavaScriptException(this.Engine, "SyntaxError", "Unexpected ',' in argument");
                        }

                        // Check the name is valid and resolve any escape sequences.
                        argumentName = Compiler.Lexer.ResolveIdentifier(this.Engine, argumentName);
                        if (argumentName == null)
                        {
                            throw new JavaScriptException(this.Engine, "SyntaxError", "Expected identifier");
                        }
                        splitNames[j] = argumentName;
                    }
                }
                argumentNames.AddRange(splitNames);
            }

            // Create a new function.
            return(new UserDefinedFunction(this.InstancePrototype, "anonymous", argumentNames, argumentsAndBody[argumentsAndBody.Length - 1]));
        }