- From: Jeremy Carroll <jjc@hplb.hpl.hp.com>
- Date: Fri, 26 Mar 2004 17:18:16 +0000
- To: Eric Jain <Eric.Jain@isb-sib.ch>
- Cc: rdf-interest <www-rdf-interest@w3.org>
Eric Jain wrote: > I have long wondered what is the correct way to extract a namespace and > local name from arbitrary resources. This is what I am doing, currently: > ... > I suspect this approach is broken (for example, there is no requirement > that the last part of a path be a valid QName etc.). So how are other > people handling this? > * The algorithm tries to find the longest NCName at the end * of the uri, not immediately preceeded by the first colon * in the string. (Note complexities to do with NCName chars being a bigger set than NCNameStart chars) public static int splitNamespace(String uri) { char ch; int lg = uri.length(); if (lg == 0) return 0; int j; int i; for (i = lg - 1; i >= 1; i--) { ch = uri.charAt(i); if (!XMLChar.isNCName(ch)) break; } for (j = i + 1; j < lg; j++) { ch = uri.charAt(j); if (XMLChar.isNCNameStart(ch)) { if (uri.charAt(j - 1) == ':' && uri.lastIndexOf(':', j - 2) == -1) continue; // split "mailto:me" as "mailto:m" and "e" ! else break; } } return j; } http://cvs.sourceforge.net/viewcvs.py/jena/jena2/src/com/hp/hpl/jena/rdf/model/impl/Util.java?view=markup
Received on Friday, 26 March 2004 12:23:15 UTC