name normalization for •ns.Get & •ns.Has

also fix •ns.Has error message & rename some function declarations
This commit is contained in:
dzaima 2023-03-19 23:25:53 +02:00
parent 0b32ef96ce
commit ca0c100b73
3 changed files with 26 additions and 4 deletions

View File

@ -66,8 +66,8 @@ bool isPervasiveDyExt(B x) {
return false;
}
B slash_c2(B f, B w, B x);
B shape_c2(B f, B w, B x);
B slash_c2(B t, B w, B x);
B shape_c2(B t, B w, B x);
B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
if (isAtm(w)) w = m_atomUnit(w);
if (isAtm(x)) x = m_atomUnit(x);

View File

@ -55,7 +55,7 @@ static B scan_and(B x, u64 ia) { // consumes x
decG(x); return FL_SET(r, fl_dsc|fl_squoze);
}
B slash_c1(B f, B x);
B slash_c1(B t, B x);
B scan_add_bool(B x, u64 ia) { // consumes x
u64* xp = bitarr_ptr(x);
u64 xs = bit_sum(xp, ia);

View File

@ -1110,6 +1110,26 @@ B getTermNS(void) {
return incG(termNS);
}
static bool name_isUpper(u32 c) { return (c>='A' & c<='Z') || (c>=U'À' && c<=U'Þ'); }
B slash_c2(B, B, B);
B ne_c2(B, B, B);
static NOINLINE B name_normalize(B x) {
usz ia = IA(x); SGetU(x)
for (ux i = 0; i < ia; i++) {
u32 c0 = o2cG(GetU(x, i));
if (name_isUpper(c0) || c0=='_') {
u32* rp; B r = m_c32arrv(&rp, ia);
COPY_TO(rp, el_c32, 0, x, 0, i);
while (i < ia) {
u32 c = o2cG(GetU(x, i));
rp[i] = name_isUpper(c)? c+32 : c;
i++;
}
return C2(slash, C2(ne, x, m_c32('_')), r);
}
}
return x;
}
B nKeys_c1(B t, B x) {
if (!isNsp(x)) thrM("•ns.Keys: 𝕩 must be a namespace");
@ -1129,13 +1149,15 @@ B nKeys_c1(B t, B x) {
B nGet_c2(B t, B w, B x) {
if (!isNsp(w)) thrM("•ns.Has: 𝕨 must be a namespace");
vfyStr(x, "•ns.Get", "𝕩");
x = name_normalize(x);
B r = ns_getNU(w, x, true);
decG(w); decG(x);
return inc(r);
}
B nHas_c2(B t, B w, B x) {
if (!isNsp(w)) thrM("•ns.Has: 𝕨 must be a namespace");
vfyStr(x, "•ns.Get", "𝕩");
vfyStr(x, "•ns.Has", "𝕩");
x = name_normalize(x);
B r = ns_getNU(w, x, false);
decG(w); decG(x);
return m_i32(!q_N(r));