/** * * Replace any non-legal char (or Z) with ZNN where NN are the hex codes * in UTF-8 * @param anonymousID Is something that corresponds to an XMLName * @return an ascii string that is legal NTriple */ public static String escapeNTriple(String anonymousID) { Matcher matcher = ntripleBnode.matcher(anonymousID); if (matcher.matches()) return anonymousID; matcher.reset(); StringBuilder rslt = new StringBuilder(); int lastNotMatched = 0; while (matcher.find()) { String unmatched = anonymousID.substring(lastNotMatched, matcher.start()); rslt.append(escapeUTF8(unmatched)); lastNotMatched = matcher.end(); rslt.append(matcher.group()); } rslt.append(escapeUTF8(anonymousID.substring(lastNotMatched))); return rslt.toString(); }
/** * * Replace any non-legal char (or Z) with ZNN where NN are the hex codes * in UTF-8 * @param anonymousID Is something that corresponds to an XMLName * @return an ascii string that is legal NTriple */ public static String escapeNTriple(String anonymousID) { Matcher matcher = ntripleBnode.matcher(anonymousID); if (matcher.matches()) return anonymousID; matcher.reset(); StringBuilder rslt = new StringBuilder(); int lastNotMatched = 0; while (matcher.find()) { String unmatched = anonymousID.substring(lastNotMatched, matcher.start()); rslt.append(escapeUTF8(unmatched)); lastNotMatched = matcher.end(); rslt.append(matcher.group()); } rslt.append(escapeUTF8(anonymousID.substring(lastNotMatched))); return rslt.toString(); }