最近一直在學習用cl-closure-template處理模版,發現一個問題,當把模版函數保存在一個文件中,使用文件路徑編譯時,模版函數中的中文字符變爲亂碼,這個是cl-closure-template讀取文件時使用了系統默認編碼方式致使的(alexandria:read-file-into-string obj),要解決此問題,能夠在cl-closure-template模塊的src/parser/command.lisp的函數parse-template中加入指定編碼方式的語句(紅色部分):函數
(defun parse-template (obj)
(closure-template-parse 'namespace
(typecase obj
(string obj)
(pathname (alexandria:read-file-into-string obj :external-format :utf-8)))))學習
問題即可解決。編碼