Skip to content
Snippets Groups Projects
Commit 2773f0c4 authored by Ladislav Lhotka's avatar Ladislav Lhotka
Browse files

Implement XPath function string-length().

parent e6019bef
No related branches found
No related tags found
No related merge requests found
......@@ -372,6 +372,8 @@ def test_xpath(instance):
xptest("substring('12345', -1 div 0, 1 div 0)", "")
xptest("substring('12345', -1 div 0)", "12345")
xptest("substring(//listA[last()]/leafE, 3)", "BA")
xptest("string-length(llistB)", 3)
xptest("string-length() = 6", node=lr)
def test_instance_paths(data_model, instance):
rid1 = data_model.parse_resource_id("/test:contA/testb:leafN")
......
......@@ -511,6 +511,12 @@ class FuncString(UnaryExpr):
return xctx.cnode.schema_node.type.canonical_string(xctx.cnode.value)
return self.expr._eval_string(xctx)
class FuncStringLength(UnaryExpr):
def _eval(self, xctx: XPathContext) -> str:
string = self.expr._eval_string(xctx) if self.expr else str(xctx.cnode)
return float(len(string))
class FuncSubstring(BinaryExpr):
def __init__(self, string: Expr, start: Expr,
......@@ -864,6 +870,9 @@ class XPathParser(Parser):
def _func_string(self) -> FuncString:
return FuncString(self._opt_arg())
def _func_string_length(self) -> FuncStringLength:
return FuncStringLength(self._opt_arg())
def _func_substring(self) -> FuncSubstring:
string, start = self._two_args()
if self.test_string(","):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment