Skip to content

Commit

Permalink
#95,new function lower-case
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Mar 31, 2024
1 parent 360713b commit c9362c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ func (b *builder) processFunction(root *functionNode, props *builderProp) (query

var qyOutput query
switch root.FuncName {
case "lower-case":
arg, err := b.processNode(root.Args[0], flagsEnum.None, props)
if err != nil {
return nil, err
}
qyOutput = &functionQuery{Input: arg, Func: lowerCaseFunc}
case "starts-with":
arg1, err := b.processNode(root.Args[0], flagsEnum.None, props)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,9 @@ func stringJoinFunc(arg1 query) func(query, iterator) interface{} {
return strings.Join(parts, separator)
}
}

// lower-case is XPATH function that converts a string to lower case.
func lowerCaseFunc(q query, t iterator) interface{} {
v := functionArgs(q).Evaluate(t)
return strings.ToLower(asString(t, v))
}
7 changes: 7 additions & 0 deletions xpath_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ func Test_func_normalize_space(t *testing.T) {
test_xpath_eval(t, book_example, `normalize-space(//book[1]/title)`, "Everyday Italian")
}

func Test_func_lower_case(t *testing.T) {
test_xpath_eval(t, empty_example, `lower-case("ABc!D")`, "abc!d")
test_xpath_count(t, employee_example, `//name[@from="ca"]`, 0)
test_xpath_elements(t, employee_example, `//name[lower-case(@from) = "ca"]`, 9)
//test_xpath_eval(t, employee_example, `//employee/name/lower-case(text())`, "opal kole", "max miller", "beccaa moss")
}

func Benchmark_NormalizeSpaceFunc(b *testing.B) {
b.ReportAllocs()
const strForNormalization = "\t \rloooooooonnnnnnngggggggg \r \n tes \u00a0 t strin \n\n \r g "
Expand Down

0 comments on commit c9362c3

Please sign in to comment.