diff options
-rw-r--r-- | lib.c | 35 | ||||
-rw-r--r-- | txr.1 | 29 |
2 files changed, 34 insertions, 30 deletions
@@ -8657,6 +8657,11 @@ val lazy_str_force(val lstr) return lstr->ls.prefix; } +INLINE cnum max_str_chars(cnum max_len) +{ + return max_len < INT_PTR_MAX / 8 ? 8 * max(3, max_len) : INT_PTR_MAX; +} + val lazy_str_put(val lstr, val stream, struct strm_base *s) { val self = lit("lazy-str-put"); @@ -8664,7 +8669,7 @@ val lazy_str_put(val lstr, val stream, struct strm_base *s) val term = lstr->ls.props->term; val iter; cnum max_len = s->max_length; - cnum max_chr = if3(max_len, max(max_len, 15), 0); + cnum max_chr = max_len ? max_str_chars(max_len) : 0; put_string(lstr->ls.prefix, stream); @@ -8679,7 +8684,7 @@ val lazy_str_put(val lstr, val stream, struct strm_base *s) put_string(sub_str(str, zero, num(max_chr)), stream); goto max_reached; } - if (--max_len == 0) + if (--max_chr == 0) goto max_reached; max_chr -= c_num(length_str(str), self); } @@ -12189,7 +12194,7 @@ static void out_lazy_str(val lstr, val out, struct strm_base *strm) val iter; const wchar_t *wcterm; cnum max_len = strm->max_length; - cnum max_chr = if3(max_len, max(max_len, 15), 0); + cnum max_chr = max_len ? max_str_chars(max_len) : 0; wcterm = c_str(term); @@ -12208,7 +12213,7 @@ static void out_lazy_str(val lstr, val out, struct strm_base *strm) out_str_readable(c_str(sub_str(str, zero, num(max_chr))), out, &semi_flag); goto max_reached; } - if (--max_len == 0) + if (--max_chr == 0) goto max_reached; max_chr -= c_num(length_str(str), self); } @@ -12261,9 +12266,7 @@ static void out_quasi_str(val args, val out, struct strm_ctx *ctx) val self = lit("print"); val iter, next; cnum max_len = ctx->strm->max_length, max_count = max_len; - - if (max_len) - max_len = max(15, max_len); + cnum max_chr = max_len ? max_str_chars(max_len) : 0; for (iter = cdr(args); iter; iter = next) { val elem = car(iter); @@ -12271,14 +12274,14 @@ static void out_quasi_str(val args, val out, struct strm_ctx *ctx) if (stringp(elem)) { int semi_flag = 0; - if (max_len && length_str_gt(elem, num(max_len))) { - out_str_readable(c_str(sub_str(elem, zero, num(max_len))), out, &semi_flag); + if (max_len && length_str_gt(elem, num(max_chr))) { + out_str_readable(c_str(sub_str(elem, zero, num(max_chr))), out, &semi_flag); goto max_exceeded; } else { out_str_readable(c_str(elem), out, &semi_flag); if (max_len) { - max_len -= c_num(length(elem), self); - if (max_len == 0) { + max_chr -= c_num(length(elem), self); + if (max_chr == 0) { goto max_reached; } } @@ -12596,23 +12599,23 @@ dot: case STR: { cnum max_length = ctx->strm->max_length; - cnum eff_max_length = max(15, max_length); + cnum max_chr = max_str_chars(max_length); if (pretty) { - if (!max_length || le(length_str(obj), num(eff_max_length))) { + if (!max_length || le(length_str(obj), num(max_chr))) { put_string(obj, out); } else { - put_string(sub_str(obj, zero, num(eff_max_length)), out); + put_string(sub_str(obj, zero, num(max_chr)), out); put_string(lit("..."), out); } } else { int semi_flag = 0; put_char(chr('"'), out); - if (!max_length || le(length_str(obj), num(eff_max_length))) { + if (!max_length || le(length_str(obj), num(max_chr))) { out_str_readable(c_str(obj), out, &semi_flag); } else { - out_str_readable(c_str(sub_str(obj, zero, num(eff_max_length))), + out_str_readable(c_str(sub_str(obj, zero, num(max_chr))), out, &semi_flag); put_string(lit("\\..."), out); } @@ -55154,12 +55154,14 @@ printing the (three dots) character sequence as if it were an additional element. This sequence is an invalid token; it cannot be read as input. -When a character string is printed, any positive value of -the maximum length which is less than 15 is considered to be 15. -The maximum length specifies the number of characters of the -a string which are output. - -If a string which exceeds the maximum length is being printed +When a character string is printed, and the maximum length parameter +is nonzero, a maximum character count is determined as follows. +Firstly, if the maximum length value is less than 3, it is taken +to be 3. Then it is multiplied by 8. Thus, a maximum length +of 10 allows 80 characters, whereas a maximum length of 1 +allows 24 characters. + +If a string which exceeds the maximum number of characters is being printed with read-print consistency, as by the .code print function, then only a prefix of the string is printed, limited @@ -55171,7 +55173,7 @@ whose leading invalid escape sequence .code \e. (backslash, dot) ensures that the truncated object is not readable. -If a string which exceeds the maximum length is being printed +If a string which exceeds the maximum number of characters is being printed without read-print consistency, as by the .code pprint function, then only a prefix of the string is printed, limited @@ -55184,17 +55186,16 @@ Quasiliterals are treated using a combination of behaviors. Elements of a quasiliteral are literal sequence of text, and embedded variables and expressions. The maximum length specifies both the maximum number of elements in the quasiliteral, and the maximum number of characters in any element which -is a sequence of text. When either limit is exceeded, the quasiliteral -is immediately terminated with the sequence +is a sequence of text. When either limit is exceeded, the +quasiliteral is immediately terminated with the sequence .code \e...` -(escaped dot, dot, dot, backtick). The maximum limit is applied to +(escaped dot, dot, dot, backtick). The maximum character limit is applied to the units of text cumulatively, rather than individually. As in the case of -string literals, smaller limit values than 15 are treated as 15, -but only for the cumulative text length limit. For limiting the number of -elements, the count is used as-is. +string literals, the limit is determined by multiplying the length by 8, and +clamping at a minimum value of 24. When a QLL is printed, the space-separated elements -of the literal are individually subject to the maximum length limit as if +of the literal are individually subject to the maximum character limit as if they were independent quasiliterals. Furthermore, the sequence of these elements is subject to the maximum length. If there are more elements in the QLL, then the sequence |