コード例 #1
0
        public static CLCommandParameter Create(string parameterInputString, Type type, int index)
        {
            string name = "*NONE";

            // Detect parameter name
            if (type == Type.WITH_NAME_WITHOUT_QUOTATION_MARKS || type == Type.WITH_NAME_WITH_QUOTATION_MARKS)
            {
                int firstParenthesePosition = parameterInputString.IndexOf("(");
                int lastParenthesePosition  = parameterInputString.IndexOf(")");

                name = parameterInputString.Substring(0, firstParenthesePosition).Trim();
                parameterInputString = parameterInputString.Substring(firstParenthesePosition + 1, lastParenthesePosition - firstParenthesePosition - 1).Trim();
            }

            // Detect subparameters
            List <string> subparameters = new List <string>();

            // Example: NAME('TEST') || // Example: 'TEST'
            if (type == Type.WITH_NAME_WITH_QUOTATION_MARKS || type == Type.WITHOUT_NAME_WITH_QUOTATION_MARKS)
            {
                parameterInputString = parameterInputString.Substring(1);
                parameterInputString = parameterInputString.Remove(parameterInputString.Length - 1);
                subparameters.Add(parameterInputString);
            }

            // Example: TEST
            if (type == Type.WITHOUT_NAME_WITHOUT_QUOTATION_MARKS)
            {
                subparameters.Add(parameterInputString);
            }

            // Example: RECT(2 4 2 4)
            if (type == Type.WITH_NAME_WITHOUT_QUOTATION_MARKS)
            {
                foreach (string str in parameterInputString.Split(' '))
                {
                    subparameters.Add(str);
                }
            }

            CLCommandParameter parameter = new CLCommandParameter(name, subparameters, type, index);

            return(parameter);
        }
コード例 #2
0
        public static CLCommand Create(string commandInputString)
        {
            commandInputString = commandInputString.Trim();

            // Parse commandname
            int commandNameEndPosition = commandInputString.IndexOf(" ");

            // If there are no parameters: create and return
            if (commandNameEndPosition <= -1)
            {
                return(new CLCommand(commandInputString.Trim()));
            }

            CLCommand command = new CLCommand(commandInputString.Substring(0, commandNameEndPosition));

            // Get parameters
            commandInputString = commandInputString.Substring(commandInputString.IndexOf(" ")).Trim();

            int parameterIndex = 1;

            // Loop for each parameter
            while (commandInputString.Length > 0)
            {
                CLCommandParameter.Type parameterType = CLCommandParameter.detectNextParameterType(commandInputString);

                string parameterInputString = "";

                // Parse next parameter string

                // Parse LIB(TEST)
                if (parameterType == CLCommandParameter.Type.WITH_NAME_WITHOUT_QUOTATION_MARKS)
                {
                    int parenthesesClose = commandInputString.IndexOf(")");
                    parameterInputString = commandInputString.Substring(0, parenthesesClose + 1);
                    commandInputString   = commandInputString.Substring(parenthesesClose + 1).Trim();
                }

                // Parse LIB('TEST')
                if (parameterType == CLCommandParameter.Type.WITH_NAME_WITH_QUOTATION_MARKS)
                {
                    int parenthesesClose = commandInputString.IndexOf("')");
                    parameterInputString = commandInputString.Substring(0, parenthesesClose + 2);
                    commandInputString   = commandInputString.Substring(parenthesesClose + 2).Trim();
                }

                // Parse 'TEST'
                if (parameterType == CLCommandParameter.Type.WITHOUT_NAME_WITH_QUOTATION_MARKS)
                {
                    int quotationMarkClose = commandInputString.IndexOf("'", 1);
                    parameterInputString = commandInputString.Substring(0, quotationMarkClose + 1);
                    commandInputString   = commandInputString.Substring(quotationMarkClose + 1).Trim();
                }

                // Parse *TEST
                if (parameterType == CLCommandParameter.Type.WITHOUT_NAME_WITHOUT_QUOTATION_MARKS)
                {
                    int end = commandInputString.IndexOf(" ");
                    if (end < 0)
                    {
                        end = commandInputString.Length;
                    }
                    parameterInputString = commandInputString.Substring(0, end);
                    commandInputString   = commandInputString.Substring(end).Trim();
                }

                command._parameters.Add(CLCommandParameter.Create(parameterInputString, parameterType, parameterIndex));

                parameterIndex++;
            }

            return(command);
        }