diff options
Diffstat (limited to 'generic/tclStringObj.c')
| -rw-r--r-- | generic/tclStringObj.c | 56 | 
1 files changed, 56 insertions, 0 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 1b35c56..493378c 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -434,6 +434,7 @@ Tcl_GetCharLength(  	return length;      } +      /*       * OK, need to work with the object as a string.       */ @@ -464,6 +465,50 @@ Tcl_GetCharLength(      }      return numChars;  } + + + +/* + *---------------------------------------------------------------------- + * + * TclCheckEmptyString -- + * + *	Determine whether the string value of an object is or would be the + *	empty string, without generating a string representation. + * + * Results: + *	Returns 1 if empty, 0 if not, and -1 if unknown. + * + * Side effects: + *	None. + * + *---------------------------------------------------------------------- + */ +int +TclCheckEmptyString ( +    Tcl_Obj *objPtr +) { +    int length = -1; + +    if (objPtr->bytes == tclEmptyStringRep) { +	return TCL_EMPTYSTRING_YES; +    } + +    if (TclIsPureList(objPtr)) { +	Tcl_ListObjLength(NULL, objPtr, &length); +	return length == 0; +    } + +    if (TclIsPureDict(objPtr)) { +	Tcl_DictObjSize(NULL, objPtr, &length); +	return length == 0; +    } +     +    if (objPtr->bytes == NULL) { +	return TCL_EMPTYSTRING_UNKNOWN; +    } +    return objPtr->length == 0; +}  /*   *---------------------------------------------------------------------- @@ -1831,6 +1876,11 @@ Tcl_AppendFormatToObj(  	width = 0;  	if (isdigit(UCHAR(ch))) {  	    width = strtoul(format, &end, 10); +	    if (width < 0) { +		msg = overflow; +		errCode = "OVERFLOW"; +		goto errorMsg; +	    }  	    format = end;  	    step = TclUtfToUniChar(format, &ch);  	} else if (ch == '*') { @@ -1951,6 +2001,12 @@ Tcl_AppendFormatToObj(  		goto error;  	    }  	    length = Tcl_UniCharToUtf(code, buf); +#if TCL_UTF_MAX > 3 +	    if (!length) { +		/* Special case for handling upper surrogates. */ +		length = Tcl_UniCharToUtf(-1, buf); +	    } +#endif  	    segment = Tcl_NewStringObj(buf, length);  	    Tcl_IncrRefCount(segment);  	    allocSegment = 1;  | 
