diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2025-02-19 08:37:41 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2025-02-19 08:37:41 (GMT) |
| commit | 5e3e3efa52b25b6a2dac9c5f974975021c8f1c61 (patch) | |
| tree | a6c9fe95c3313d5a9762caa78ee206c8c76f2397 /generic/tclStringObj.c | |
| parent | b43caa2a524637c0e771614db9290499b786e7f9 (diff) | |
| parent | cea29dc862927d59885d2b5c560fa7ca71130681 (diff) | |
| download | tcl-core-tip-711.zip tcl-core-tip-711.tar.gz tcl-core-tip-711.tar.bz2 | |
Rebase to 9.1core-tip-711
Diffstat (limited to 'generic/tclStringObj.c')
| -rw-r--r-- | generic/tclStringObj.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 059f8dd..b3e6dec 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -4360,6 +4360,49 @@ ExtendUnicodeRepWithString( } *dst = 0; } + +/* + *---------------------------------------------------------------------- + * + * Tcl_IsEmpty -- + * + * Check whether the obj is the empty string. + * + * Results: + * 1 if the obj is "" + * 0 otherwise + * + * Side effects: + * If there is no other way to determine whethere the string + * representation is the empty string, the string representation + * is generated. + * + *---------------------------------------------------------------------- + */ + +int +Tcl_IsEmpty( + Tcl_Obj *objPtr) +{ + if (objPtr == NULL) { + Tcl_Panic("%s: objPtr is NULL", "Tcl_IsEmpty"); + } + if (!objPtr->bytes) { + if (TclHasInternalRep(objPtr, &tclDictType)) { + /* Since "dict" doesn't have a lengthProc */ + Tcl_Size size; + Tcl_DictObjSize(NULL, objPtr, &size); + return !size; + } + + Tcl_ObjTypeLengthProc *proc = TclObjTypeHasProc(objPtr, lengthProc); + if (proc != NULL) { + return !proc(objPtr); + } + (void)TclGetString(objPtr); + } + return !objPtr->length; +} /* *---------------------------------------------------------------------- |
