Generate Java code to build a Java string from an ACL2 string.
Often, an ACL2 string can be turned into a Java string literal
that is valid when pretty-printed.
Examples are
However, if the ACL2 string includes characters like
If the ACL2 string consists of only pritable ASCII characters
(i.e. space and visible ASCII characters),
we turn it into a Java string literal.
Otherwise, we turn it into a Java array creation expression
that is passed as argument to a Java class instance creation expression
for a
Function:
(defun atj-gen-jstring (string) (declare (xargs :guard (stringp string))) (let ((__function__ 'atj-gen-jstring)) (declare (ignorable __function__)) (b* ((chars (explode string))) (if (str::printable-charlist-p chars) (jexpr-literal-string string) (jexpr-newclass (jtype-class "String") (list (jexpr-newarray-init (jtype-char) (atj-chars-to-jhexcodes chars))))))))
Theorem:
(defthm jexprp-of-atj-gen-jstring (b* ((expr (atj-gen-jstring string))) (jexprp expr)) :rule-classes :rewrite)