At 2010-03-24 08:53 -0500, Strawn, M. Shane wrote:
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
        boundary="----_=_NextPart_001_01CACB59.729D3935"

In v3, fn:tokenize would do this:

fn:tokenize("word", "") ==> ("w", "o", "r", "d")

Â…but in v4 that returns an error:

[1.0-ml] XDMP-MATCHZERO: (err:FORX0003) fn:tokenize("word", "") -- Pattern matches zero-length string

With the 2nd param interpreted as a reg-ex pattern, I'm not sure why it ever worked, but it was handy.

Any comments on why this is the case?

It is specified to do so ... from 7.6.4 fn:tokenize:

  If the supplied $pattern matches a zero-length string,
  that is, if fn:matches("", $pattern, $flags) returns
  true, then an error is raised: [err:FORX0003].

I'm guessing because there would be an infinite number of occurrences of an empty string in-between two characters before "moving" to the next character in the search for non-matching substrings.

How's this on speed/efficiency for replicating it? Not that I know how fast the tokenize version was.

Nor do I ... but anything accomplished by the processor would be faster than anything coded by hand (modulo any optimization and rewriting done by the processor). So the objective would be to find a written algorithm that would compare well to other written algorithms.

for $pos in 1 to fn:string-length("word") return fn:substring("word", $pos, 1) ==> ("w", "o", "r", "d")

I think the following might be faster because you won't be indexing into the entire input string once for each character in the string, yet it is using the same number of function invocations:

T:\ftemp>type shane.xq
for $each in string-to-codepoints( "word" )
return codepoints-to-string( $each )
T:\ftemp>xquery shane.xq
<?xml version="1.0" encoding="UTF-8"?>w o r d
T:\ftemp>

I hope this helps.

. . . . . . . . . . . . Ken

--
XSLT/XQuery training:         San Carlos, California 2010-04-26/30
Principles of XSLT for XQuery Writers: San Francisco,CA 2010-05-03
XSLT/XQuery training:                 Ottawa, Canada 2010-05-10/14
XSLT/XQuery/UBL/Code List training: Trondheim,Norway 2010-06-02/11
Vote for your XML training:   http://www.CraneSoftwrights.com/q/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:[email protected]
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/q/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to