unicode.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright (C) 2014 Free Software Foundation, Inc.
  2. *
  3. * This library is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Lesser General Public License as
  5. * published by the Free Software Foundation, either version 3 of the
  6. * License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library. If not, see
  15. * <http://www.gnu.org/licenses/>.
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include <ctype.h>
  21. #include <limits.h>
  22. #include <unicase.h>
  23. #include <unictype.h>
  24. #include <uniname.h>
  25. #include "libguile/_scm.h"
  26. #include "libguile/validate.h"
  27. #include "libguile/unicode.h"
  28. SCM_DEFINE (scm_char_to_formal_name, "char->formal-name", 1, 0, 0,
  29. (SCM ch),
  30. "Return the formal all-upper-case unicode name of @var{ch},\n"
  31. "as a string. If the character has no name, return @code{#f}.")
  32. #define FUNC_NAME s_scm_char_to_formal_name
  33. {
  34. char buf[UNINAME_MAX + 1];
  35. SCM_VALIDATE_CHAR (1, ch);
  36. memset(buf, 0, UNINAME_MAX + 1);
  37. if (unicode_character_name (SCM_CHAR (ch), buf))
  38. return scm_from_latin1_string (buf);
  39. return SCM_BOOL_F;
  40. }
  41. #undef FUNC_NAME
  42. SCM_DEFINE (scm_formal_name_to_char, "formal-name->char", 1, 0, 0,
  43. (SCM name),
  44. "Return the character whose formal all-upper-case unicode name is\n"
  45. "@var{name}, or @code{#f} if no such character is known.")
  46. #define FUNC_NAME s_scm_formal_name_to_char
  47. {
  48. char *c_name;
  49. scm_t_wchar ret;
  50. SCM_VALIDATE_STRING (1, name);
  51. c_name = scm_to_latin1_string (name);
  52. ret = unicode_name_character (c_name);
  53. free (c_name);
  54. return ret == UNINAME_INVALID ? SCM_BOOL_F : SCM_MAKE_CHAR (ret);
  55. }
  56. #undef FUNC_NAME
  57. static void
  58. scm_load_unicode (void)
  59. {
  60. #ifndef SCM_MAGIC_SNARFER
  61. #include "libguile/unicode.x"
  62. #endif
  63. }
  64. void
  65. scm_init_unicode (void)
  66. {
  67. scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
  68. "scm_init_unicode",
  69. (scm_t_extension_init_func)scm_load_unicode,
  70. NULL);
  71. }
  72. /*
  73. Local Variables:
  74. c-file-style: "gnu"
  75. End:
  76. */