ScmChar Scm_UcsToChar(int n) { if (n < 0) Scm_Error("bad character code: %d", n); #if defined(GAUCHE_CHAR_ENCODING_UTF_8) return (ScmChar)n; #elif defined(GAUCHE_CHAR_ENCODING_EUC_JP) || defined(GAUCHE_CHAR_ENCODING_SJIS) if (n < 0x80) return (ScmChar)n; /*ASCII range*/ if (ucs2char_hook == NULL) { /* NB: we don't need mutex here, for the loading of gauche.charconv is serialized in Scm_Require. */ Scm_Require(SCM_MAKE_STR("gauche/charconv"), SCM_LOAD_PROPAGATE_ERROR, NULL); if (ucs2char_hook == NULL) { Scm_Error("couldn't autoload gauche.charconv"); } } return ucs2char_hook(n); #else /* Encoding == 'none'. It would be safer to reject anything beyond 0xff, but it prevents 'none' gosh from reading any source files that have escaped characters in that range, even the section is cond-expanded. That's awfully incovenient, so we use a substitution character '?' here, relying the programmer to properly conditionalize the code. We plan to drop 'none' encoding support in 1.0, so this kludge is just a temporary measure. */ if (n < 0x100) return (ScmChar)n; /* ISO8859-1 */ else return (ScmChar)'?'; #endif }
ScmChar Scm_UcsToChar(int n) { if (n < 0) Scm_Error("bad character code: %d", n); #if defined(GAUCHE_CHAR_ENCODING_UTF_8) return (ScmChar)n; #elif defined(GAUCHE_CHAR_ENCODING_EUC_JP) || defined(GAUCHE_CHAR_ENCODING_SJIS) if (n < 0x80) return (ScmChar)n; /*ASCII range*/ if (ucs2char_hook == NULL) { /* NB: we don't need mutex here, for the loading of gauche.charconv is serialized in Scm_Require. */ Scm_Require(SCM_MAKE_STR("gauche/charconv"), SCM_LOAD_PROPAGATE_ERROR, NULL); if (ucs2char_hook == NULL) { Scm_Error("couldn't autoload gauche.charconv"); } } return ucs2char_hook(n); #else if (n < 0x100) return (ScmChar)n; /* ISO8859-1 */ else return SCM_CHAR_INVALID; #endif }