/** * Adds a local function. * * @param fun function instance * @param ii input info * @return function id * @throws QueryException query exception */ public int add(final UserFunc fun, final InputInfo ii) throws QueryException { final QNm name = fun.name; final byte[] uri = name.uri(); if (uri.length == 0) FUNNONS.thrw(ii, name.string()); if (NSGlobal.standard(uri)) { if (fun.declared) NAMERES.thrw(ii, name.string()); funError(name, ii); } final byte[] ln = name.local(); for (int l = 0; l < func.length; ++l) { final QNm qn = func[l].name; final byte[] u = qn.uri(); final byte[] nm = qn.local(); if (eq(ln, nm) && eq(uri, u) && fun.args.length == func[l].args.length) { // declare function that has been called before if (!func[l].declared) { func[l] = fun; return l; } // duplicate declaration FUNCDEFINED.thrw(ii, fun); } } // add function skeleton func = Array.add(func, fun); calls = Array.add(calls, new UserFuncCall[0]); return func.length - 1; }
/** * Throws an error if one of the pre-defined functions is similar to the specified function name. * * @param name function name * @param ii input info * @throws QueryException query exception */ public void error(final QNm name, final InputInfo ii) throws QueryException { // compare specified name with names of predefined functions final byte[] ln = name.local(); final Levenshtein ls = new Levenshtein(); for (int k = 1; k < size; ++k) { final int i = indexOf(keys[k], '}'); final byte[] u = substring(keys[k], 2, i); final byte[] l = substring(keys[k], i + 1); if (eq(ln, l)) { final byte[] ur = name.uri(); FUNSIMILAR.thrw( ii, new TokenBuilder(NSGlobal.prefix(ur)).add(':').add(l), new TokenBuilder(NSGlobal.prefix(u)).add(':').add(l)); } else if (ls.similar(ln, l, 0)) { FUNSIMILAR.thrw(ii, name.string(), l); } } }