unicode.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJ_UNICODE_H__
  20. #define __PJ_UNICODE_H__
  21. #include <pj/types.h>
  22. /**
  23. * @defgroup PJ_UNICODE Unicode Support
  24. * @ingroup PJ_MISC
  25. * @{
  26. */
  27. PJ_BEGIN_DECL
  28. /**
  29. * @file unicode.h
  30. * @brief Provides Unicode conversion for Unicode OSes
  31. */
  32. /**
  33. * Convert ANSI strings to Unicode strings.
  34. *
  35. * @param str The ANSI string to be converted.
  36. * @param len The length of the input string.
  37. * @param wbuf Buffer to hold the Unicode string output.
  38. * @param wbuf_count Buffer size, in number of elements (not bytes).
  39. *
  40. * @return The Unicode string, NULL terminated.
  41. */
  42. PJ_DECL(wchar_t*) pj_ansi_to_unicode(const char *str, int len,
  43. wchar_t *wbuf, int wbuf_count);
  44. /**
  45. * Convert Unicode string to ANSI string.
  46. *
  47. * @param wstr The Unicode string to be converted.
  48. * @param len The length of the input string.
  49. * @param buf Buffer to hold the ANSI string output.
  50. * @param buf_size Size of the output buffer.
  51. *
  52. * @return The ANSI string, NULL terminated.
  53. */
  54. PJ_DECL(char*) pj_unicode_to_ansi(const wchar_t *wstr, pj_ssize_t len,
  55. char *buf, int buf_size);
  56. #if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
  57. /**
  58. * This macro is used to declare temporary Unicode buffer for ANSI to
  59. * Unicode conversion, and should be put in declaration section of a block.
  60. * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
  61. * macro will expand to nothing.
  62. */
  63. # define PJ_DECL_UNICODE_TEMP_BUF(buf,size) wchar_t buf[size];
  64. /**
  65. * This macro will convert ANSI string to native, when the platform's
  66. * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
  67. */
  68. # define PJ_STRING_TO_NATIVE(s,buf,max) pj_ansi_to_unicode( \
  69. s, strlen(s), \
  70. buf, max)
  71. /**
  72. * This macro is used to declare temporary ANSI buffer for Unicode to
  73. * ANSI conversion, and should be put in declaration section of a block.
  74. * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
  75. * macro will expand to nothing.
  76. */
  77. # define PJ_DECL_ANSI_TEMP_BUF(buf,size) char buf[size];
  78. /**
  79. * This macro will convert Unicode string to ANSI, when the platform's
  80. * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
  81. */
  82. # define PJ_NATIVE_TO_STRING(cs,buf,max) pj_unicode_to_ansi( \
  83. cs, wcslen(cs), \
  84. buf, max)
  85. #else
  86. /**
  87. * This macro is used to declare temporary Unicode buffer for ANSI to
  88. * Unicode conversion, and should be put in declaration section of a block.
  89. * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
  90. * macro will expand to nothing.
  91. */
  92. # define PJ_DECL_UNICODE_TEMP_BUF(var,size)
  93. /**
  94. * This macro will convert ANSI string to native, when the platform's
  95. * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
  96. */
  97. # define PJ_STRING_TO_NATIVE(s,buf,max) ((char*)s)
  98. /**
  99. * This macro is used to declare temporary ANSI buffer for Unicode to
  100. * ANSI conversion, and should be put in declaration section of a block.
  101. * When PJ_NATIVE_STRING_IS_UNICODE macro is not defined, this
  102. * macro will expand to nothing.
  103. */
  104. # define PJ_DECL_ANSI_TEMP_BUF(buf,size)
  105. /**
  106. * This macro will convert Unicode string to ANSI, when the platform's
  107. * native string is Unicode (PJ_NATIVE_STRING_IS_UNICODE is non-zero).
  108. */
  109. # define PJ_NATIVE_TO_STRING(cs,buf,max) ((char*)(const char*)cs)
  110. #endif
  111. PJ_END_DECL
  112. /**
  113. * @}
  114. */
  115. #endif /* __PJ_UNICODE_H__ */