Adding support for `fn:replace`
See original GitHub issueI just looked into this. I would like to be able to use the functx
library. I have gone through it and commented out all the functions that fontoxpath cannot currently compile. There are quite a lot, but they depend on a relatively few missing XQuery functions. The most interesting, for me, is replace
.
I had a look at CONTRIBUTING.md
and started to dig in. I see that the matches
implementation uses xspatterns
, which in turn relies on whynot
. Currently, xspatterns
only returns a boolean, which is enough for matches
but not for replace
. whynot
in turn will return the traces that matched, which is enough for replace
, but will still need some work to feed through xspatterns
, which would also need extending to implement captures.
Meanwhile, I see that the fontoxpath implementation of tokenize
does not use xspatterns
at all, but JavaScript’s RegExp
! (Again, not surprising, as xspatterns
would not be sufficient in this case.)
I am unsure how to proceed.
I see that the implementation of matches
does not support the flags
argument; in the first instance, this is fine for me, as I don’t need flags
for my use of replace
.
I would be happy to implement replace
using JavaScript regexes directly, which would be simple, but presumably not strictly XQuery-compliant. However, fontoxpath already does this for tokenize
.
It looks fairly simple to extend xspatterns
to return the match; but replace
(and tokenize
) need all the non-overlapping matching (effectively a g
flag).
If you can let me know what would work for the fontoxpath maintainers, I can consider how I might be able to help; in the mean time, I suspect I will simply implement the desired functx
functions directly in JavaScript. (In the first instance, I simply want trim
: as you can see, I’ve already gone down quite a deep rabbit hole in an effort to see how to do this “properly”!)
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
It’s in! 3.21.0 has this!
~I just shipped a new release: 3.20.0. This includes basic support for the
fn:pattern
function. Thanks a lot for the help!!~NVM, overlooked the fact this has not landed yet