newtRef NcClassOf(newtRefArg r) { if (NewtRefIsPointer(r)) return NewtObjClassOf(r); else return NewtRefTypeToClass(NewtGetRefType(r, false)); }
newtRef NsPrimClassOf(newtRefArg rcvr, newtRefArg r) { newtRefVar klass; if (NewtRefIsPointer(r)) { switch (NewtGetRefType(r, true)) { case kNewtFrame: klass = NSSYM0(frame); break; case kNewtArray: klass = NSSYM0(array); break; default: klass = NSSYM0(binary); break; } } else { klass = NSSYM(immediate); } return klass; }
newtRef NsSetLength(newtRefArg rcvr, newtRefArg r, newtRefArg len) { int32_t n; if (NewtRefIsReadonly(r)) return NewtThrow(kNErrObjectReadOnly, r); if (! NewtRefIsInteger(len)) return NewtThrow(kNErrNotAnInteger, len); n = NewtRefToInteger(len); switch (NewtGetRefType(r, true)) { case kNewtBinary: case kNewtString: NewtBinarySetLength(r, n); break; case kNewtArray: NewtSlotsSetLength(r, n, kNewtRefUnbind); break; case kNewtFrame: return NewtThrow(kNErrUnexpectedFrame, r); default: return NewtThrow(kNErrNotAnArrayOrString, r); } return r; }
newtRef NsStrCat(newtRefArg rcvr, newtRefArg str, newtRefArg v) { char wk[32]; char * s = NULL; switch (NewtGetRefType(v, true)) { case kNewtInt30: case kNewtInt32: { int n; n = (int)NewtRefToInteger(v); sprintf(wk, "%d", n); s = wk; } break; case kNewtReal: { double n; n = NewtRefToReal(v); sprintf(wk, "%f", n); s = wk; } break; case kNewtCharacter: { int c; c = NewtRefToCharacter(v); sprintf(wk, "%c", c); s = wk; } break; case kNewtSymbol: { newtSymDataRef sym; sym = NewtRefToSymbol(v); s = sym->name; } break; case kNewtString: s = NewtRefToString(v); break; } if (s != NULL) NewtStrCat(str, s); return str; }
newtRef NsSplit(newtRefArg rcvr, newtRefArg r, newtRefArg sep) { newtRefVar result; if (! NewtRefIsString(r)) return NewtThrow(kNErrNotAString, r); switch (NewtGetRefType(sep, true)) { case kNewtCharacter: { newtRefVar v; char * next; char * s; int c; s = NewtRefToString(r); c = NewtRefToCharacter(sep); result = NewtMakeArray(kNewtRefUnbind, 0); while (*s) { next = strchr(s, c); if (next == NULL) break; v = NewtMakeString2(s, next - s, false); NcAddArraySlot(result, v); s = next + 1; } if (s == NewtRefToString(r)) v = r; else v = NSSTR(s); NcAddArraySlot(result, v); } break; default: { newtRefVar initObj[] = {r}; result = NewtMakeArray2(kNewtRefNIL, sizeof(initObj) / sizeof(newtRefVar), initObj); } break; } return result; }