From e76b75a08a79c3cd29c905a57abaffbb49bdf8af Mon Sep 17 00:00:00 2001 From: japhie Date: Sun, 29 May 2005 15:19:16 +0000 Subject: [PATCH] New function lisp-to-c-name: return prin1 representation of object with all characters that are invalid in C identifiers replaced by underscore. --- src/cmp/cmputil.lsp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cmp/cmputil.lsp b/src/cmp/cmputil.lsp index fa1e58f1f..8bcaf7a75 100644 --- a/src/cmp/cmputil.lsp +++ b/src/cmp/cmputil.lsp @@ -206,3 +206,13 @@ (rem-sysprop symbol ':inline-safe) (rem-sysprop symbol 'lfun)) +(defun lisp-to-c-name (obj) + "Translate Lisp object prin1 representation to valid C identifier name" + (and obj + (map 'string + #'(lambda (c) + (let ((cc (char-code c))) + (if (or (<= #.(char-code #\a) cc #.(char-code #\z)) + (<= #.(char-code #\0) cc #.(char-code #\9))) + c #\_))) + (string-downcase (prin1-to-string obj)))))