Raymond Toy pushed to branch issue-367-count-octets-for-encoding at cmucl / cmucl Commits: afc9afb0 by Raymond Toy at 2025-01-15T09:04:00-08:00 Hack to handle composing formats in string-octet-count I can't figure out how to make `string-octet-count` work when using composing formats (like (:latin1 :crlf) to output CR/LF for every LF). As a workaround, if the external format is a composing format, use `string-to-octets` to get the number of octets. This is not great, but allows `string-octet-count` to work with composing formats. - - - - - 1 changed file: - src/code/extfmts.lisp Changes: ===================================== src/code/extfmts.lisp ===================================== @@ -1165,9 +1165,21 @@ character and illegal outputs are replaced by a question mark.") "Compute the number of octets needed to convert String using the specified External-format. The string is bound by Start (defaulting to 0) and End (defaulting to the end of the string)." - (lisp::with-array-data ((string string) (start start) (end end)) - (funcall (ef-string-octet-count external-format) - string start end error))) + (let ((composing-format-p + ;; Determine is the external format is a composing format + ;; which we determine by seeing that the name of the format + ;; is a cons. Probably not the best way. + (consp (ef-name (find-external-format external-format))))) + ;; We currently don't know how to get just the number of octets + ;; when a composing external format is used. As a workaround, use + ;; STRING-TO-OCTETS to find the number of octets. + (if composing-format-p + (nth-value 1 + (string-to-octets string :start start :end end + :external-format external-format)) + (lisp::with-array-data ((string string) (start start) (end end)) + (funcall (ef-string-octet-count external-format) + string start end error))))) (def-ef-macro ef-encode (extfmt lisp::lisp +ef-max+ +ef-en+) `(lambda (string start end result error &aux (ptr 0) (state nil)) View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/afc9afb0e69ec877fafa02b1... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/afc9afb0e69ec877fafa02b1... You're receiving this email because of your account on gitlab.common-lisp.net.
participants (1)
-
Raymond Toy (@rtoy)