| 8786 | } |
| 8787 | |
| 8788 | xpath_ast_node* parse_function(const xpath_lexer_string& name, size_t argc, xpath_ast_node* args[2]) |
| 8789 | { |
| 8790 | switch (name.begin[0]) |
| 8791 | { |
| 8792 | case 'b': |
| 8793 | if (name == PUGIXML_TEXT("boolean") && argc == 1) |
| 8794 | return new (alloc_node()) xpath_ast_node(ast_func_boolean, xpath_type_boolean, args[0]); |
| 8795 | |
| 8796 | break; |
| 8797 | |
| 8798 | case 'c': |
| 8799 | if (name == PUGIXML_TEXT("count") && argc == 1) |
| 8800 | { |
| 8801 | if (args[0]->rettype() != xpath_type_node_set) throw_error("Function has to be applied to node set"); |
| 8802 | return new (alloc_node()) xpath_ast_node(ast_func_count, xpath_type_number, args[0]); |
| 8803 | } |
| 8804 | else if (name == PUGIXML_TEXT("contains") && argc == 2) |
| 8805 | return new (alloc_node()) xpath_ast_node(ast_func_contains, xpath_type_string, args[0], args[1]); |
| 8806 | else if (name == PUGIXML_TEXT("concat") && argc >= 2) |
| 8807 | return new (alloc_node()) xpath_ast_node(ast_func_concat, xpath_type_string, args[0], args[1]); |
| 8808 | else if (name == PUGIXML_TEXT("ceiling") && argc == 1) |
| 8809 | return new (alloc_node()) xpath_ast_node(ast_func_ceiling, xpath_type_number, args[0]); |
| 8810 | |
| 8811 | break; |
| 8812 | |
| 8813 | case 'f': |
| 8814 | if (name == PUGIXML_TEXT("false") && argc == 0) |
| 8815 | return new (alloc_node()) xpath_ast_node(ast_func_false, xpath_type_boolean); |
| 8816 | else if (name == PUGIXML_TEXT("floor") && argc == 1) |
| 8817 | return new (alloc_node()) xpath_ast_node(ast_func_floor, xpath_type_number, args[0]); |
| 8818 | |
| 8819 | break; |
| 8820 | |
| 8821 | case 'i': |
| 8822 | if (name == PUGIXML_TEXT("id") && argc == 1) |
| 8823 | return new (alloc_node()) xpath_ast_node(ast_func_id, xpath_type_node_set, args[0]); |
| 8824 | |
| 8825 | break; |
| 8826 | |
| 8827 | case 'l': |
| 8828 | if (name == PUGIXML_TEXT("last") && argc == 0) |
| 8829 | return new (alloc_node()) xpath_ast_node(ast_func_last, xpath_type_number); |
| 8830 | else if (name == PUGIXML_TEXT("lang") && argc == 1) |
| 8831 | return new (alloc_node()) xpath_ast_node(ast_func_lang, xpath_type_boolean, args[0]); |
| 8832 | else if (name == PUGIXML_TEXT("local-name") && argc <= 1) |
| 8833 | return parse_function_helper(ast_func_local_name_0, ast_func_local_name_1, argc, args); |
| 8834 | |
| 8835 | break; |
| 8836 | |
| 8837 | case 'n': |
| 8838 | if (name == PUGIXML_TEXT("name") && argc <= 1) |
| 8839 | return parse_function_helper(ast_func_name_0, ast_func_name_1, argc, args); |
| 8840 | else if (name == PUGIXML_TEXT("namespace-uri") && argc <= 1) |
| 8841 | return parse_function_helper(ast_func_namespace_uri_0, ast_func_namespace_uri_1, argc, args); |
| 8842 | else if (name == PUGIXML_TEXT("normalize-space") && argc <= 1) |
| 8843 | return new (alloc_node()) xpath_ast_node(argc == 0 ? ast_func_normalize_space_0 : ast_func_normalize_space_1, xpath_type_string, args[0], args[1]); |
| 8844 | else if (name == PUGIXML_TEXT("not") && argc == 1) |
| 8845 | return new (alloc_node()) xpath_ast_node(ast_func_not, xpath_type_boolean, args[0]); |