lookup with max lentgth

This commit is contained in:
Vitor Santos Costa 2010-05-06 10:58:25 +01:00
parent 849c96cb38
commit ecaf6aa713
2 changed files with 41 additions and 0 deletions

View File

@ -296,6 +296,46 @@ Yap_LookupMaybeWideAtom(wchar_t *atom)
return at;
}
Atom
Yap_LookupMaybeWideAtomWithLength(wchar_t *atom, size_t len)
{ /* lookup atom in atom table */
wchar_t *p = atom, c;
size_t len0 = 0;
Atom at;
int wide = FALSE;
while ((c = *p++)) {
if (c > 255) wide = TRUE;
len0++;
if (len0 == len) break;
}
if (p[0] == '\0' && wide) return LookupWideAtom(atom);
else if (wide) {
wchar_t *ptr, *ptr0;
p = atom;
ptr0 = ptr = (wchar_t *)Yap_AllocCodeSpace(sizeof(wchar_t)*(len+1));
if (!ptr)
return NIL;
while (len--) {*ptr++ = *p++;}
ptr[0] = '\0';
at = LookupWideAtom(ptr0);
Yap_FreeCodeSpace(ptr0);
return at;
} else {
char *ptr, *ptr0;
/* not really a wide atom */
p = atom;
ptr0 = ptr = Yap_AllocCodeSpace(len+1);
if (!ptr)
return NIL;
while (len--) {*ptr++ = *p++;}
ptr[0] = '\0';
at = LookupAtom(ptr0);
Yap_FreeCodeSpace(ptr0);
return at;
}
}
Atom
Yap_LookupAtom(char *atom)
{ /* lookup atom in atom table */

View File

@ -31,6 +31,7 @@ int STD_PROTO(Yap_HasOp,(Atom));
struct operator_entry *STD_PROTO(Yap_GetOpPropForAModuleHavingALock,(AtomEntry *, Term));
Atom STD_PROTO(Yap_LookupAtom,(char *));
Atom STD_PROTO(Yap_LookupMaybeWideAtom,(wchar_t *));
Atom STD_PROTO(Yap_LookupMaybeWideAtomWithLength,(wchar_t *, size_t));
Atom STD_PROTO(Yap_FullLookupAtom,(char *));
void STD_PROTO(Yap_LookupAtomWithAddress,(char *,AtomEntry *));
Prop STD_PROTO(Yap_NewPredPropByFunctor,(struct FunctorEntryStruct *, Term));