Version 1.7.2: Add support external character formats for underlying implementation.
[uffi.git] / src / i18n.lisp
diff --git a/src/i18n.lisp b/src/i18n.lisp
new file mode 100644 (file)
index 0000000..e2d204a
--- /dev/null
@@ -0,0 +1,57 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: UFFI -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name:          i18n.lisp
+;;;; Purpose:       non-ASCII character support
+;;;; Programmer:    Kevin M. Rosenberg
+;;;; Date Started:  Feb 2010
+;;;;
+;;;; This file, part of UFFI, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
+;;;;
+;;;; *************************************************************************
+
+(in-package #:uffi)
+
+#-(or (and lispworks unicode) (and sbcl sb-unicode)
+      (and allegro ics) (and clisp i18n)
+      (and openmcl openmcl-unicode-strings))
+(pushnew 'no-i18n *features*)
+
+(defvar *default-external-character-encoding*
+  nil
+  "Normalized name of default external character encoding to use
+for foreign string conversions. nil means use implementation default
+encoding.")
+
+(defvar *external-encoding-mapping*
+    #+(and lispworks unicode)
+    '((:ascii . :ascii) (:latin-1 . :latin-1) (:ucs-2 . :unicode)
+      (:utf-8 . :utf-8) (:jis . :jis) (:sjis . :sjis) (:gbk . :gbk))
+    #+(and sbcl sb-unicode)
+    '((:ascii . :ascii) (:latin-1 . :latin-1) (:utf-8 . :utf-8)
+      (:ucs-2 . :ucs-2) (:sjis . :sjis) (:gbk . :gbk))
+    #+(and allegro ics)
+    '((:ascii . :ascii) (:latin-1 . :latin1) (:utf-8 . :utf-8)
+      (:sjis . :shift-jis) (:euc-jp . :euc) (:gbk . :gb2313)
+      (:ucs-2 . :unicode))
+    #+(and clisp unicode)
+    '((:ascii . charset:ascii) (:ucs-2 . charset:ucs-2)
+      (:utf-8 . charset:utf-8) (:latin-1 . charset:iso-8859-1)
+      (:jis . charset:jis_x0201) (:jis . charset:shift-jis)
+      (:gbk . charset:gbk) (:euc-jp . charset:euc-jp))
+    #+(and openmcl openmcl-unicode-strings)
+    '((:ascii . :ascii) (:latin-1 . :iso-8859-1) (:utf-8 . :utf-8)
+      (:ucs-2 . :ucs-2) (:euc-jp . :euc-jp))
+    #-(or (and lispworks unicode) (and sbcl sb-unicode)
+          (and allegro ics) (and clisp unicode)
+          (and openmcl openmcl-unicode-strings))
+    nil
+  "Mapping between normalized external encoding name and implementation name.")
+
+(defvar *external-character-encodings*
+  (mapcar 'car *external-encoding-mapping*)
+  "List of normalized names of external encodings support by underlying implementation.")
+
+(defun map-normalized-external-encoding (normalized)
+  (cdr (assoc normalized *external-encoding-mapping* :test 'eql)))