apr_xlate.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_XLATE_H
  17. #define APR_XLATE_H
  18. #include "apu.h"
  19. #include "apr_pools.h"
  20. #include "apr_errno.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif /* __cplusplus */
  24. /**
  25. * @file apr_xlate.h
  26. * @brief APR I18N translation library
  27. */
  28. /**
  29. * @defgroup APR_XLATE I18N translation library
  30. * @ingroup APR
  31. * @{
  32. */
  33. /** Opaque translation buffer */
  34. typedef struct apr_xlate_t apr_xlate_t;
  35. /**
  36. * Set up for converting text from one charset to another.
  37. * @param convset The handle to be filled in by this function
  38. * @param topage The name of the target charset
  39. * @param frompage The name of the source charset
  40. * @param pool The pool to use
  41. * @remark
  42. * Specify APR_DEFAULT_CHARSET for one of the charset
  43. * names to indicate the charset of the source code at
  44. * compile time. This is useful if there are literal
  45. * strings in the source code which must be translated
  46. * according to the charset of the source code.
  47. * APR_DEFAULT_CHARSET is not useful if the source code
  48. * of the caller was not encoded in the same charset as
  49. * APR at compile time.
  50. *
  51. * @remark
  52. * Specify APR_LOCALE_CHARSET for one of the charset
  53. * names to indicate the charset of the current locale.
  54. *
  55. * @remark
  56. * Return APR_EINVAL if unable to procure a convset, or APR_ENOTIMPL
  57. * if charset transcoding is not available in this instance of
  58. * apr-util at all (i.e., APR_HAS_XLATE is undefined).
  59. */
  60. APU_DECLARE(apr_status_t) apr_xlate_open(apr_xlate_t **convset,
  61. const char *topage,
  62. const char *frompage,
  63. apr_pool_t *pool);
  64. /**
  65. * This is to indicate the charset of the sourcecode at compile time
  66. * names to indicate the charset of the source code at
  67. * compile time. This is useful if there are literal
  68. * strings in the source code which must be translated
  69. * according to the charset of the source code.
  70. */
  71. #define APR_DEFAULT_CHARSET (const char *)0
  72. /**
  73. * To indicate charset names of the current locale
  74. */
  75. #define APR_LOCALE_CHARSET (const char *)1
  76. /**
  77. * Find out whether or not the specified conversion is single-byte-only.
  78. * @param convset The handle allocated by apr_xlate_open, specifying the
  79. * parameters of conversion
  80. * @param onoff Output: whether or not the conversion is single-byte-only
  81. * @remark
  82. * Return APR_ENOTIMPL if charset transcoding is not available
  83. * in this instance of apr-util (i.e., APR_HAS_XLATE is undefined).
  84. */
  85. APU_DECLARE(apr_status_t) apr_xlate_sb_get(apr_xlate_t *convset, int *onoff);
  86. /**
  87. * Convert a buffer of text from one codepage to another.
  88. * @param convset The handle allocated by apr_xlate_open, specifying
  89. * the parameters of conversion
  90. * @param inbuf The address of the source buffer
  91. * @param inbytes_left Input: the amount of input data to be translated
  92. * Output: the amount of input data not yet translated
  93. * @param outbuf The address of the destination buffer
  94. * @param outbytes_left Input: the size of the output buffer
  95. * Output: the amount of the output buffer not yet used
  96. * @remark
  97. * Returns APR_ENOTIMPL if charset transcoding is not available
  98. * in this instance of apr-util (i.e., APR_HAS_XLATE is undefined).
  99. * Returns APR_INCOMPLETE if the input buffer ends in an incomplete
  100. * multi-byte character.
  101. *
  102. * To correctly terminate the output buffer for some multi-byte
  103. * character set encodings, a final call must be made to this function
  104. * after the complete input string has been converted, passing
  105. * the inbuf and inbytes_left parameters as NULL. (Note that this
  106. * mode only works from version 1.1.0 onwards)
  107. */
  108. APU_DECLARE(apr_status_t) apr_xlate_conv_buffer(apr_xlate_t *convset,
  109. const char *inbuf,
  110. apr_size_t *inbytes_left,
  111. char *outbuf,
  112. apr_size_t *outbytes_left);
  113. /* @see apr_file_io.h the comment in apr_file_io.h about this hack */
  114. #ifdef APR_NOT_DONE_YET
  115. /**
  116. * The purpose of apr_xlate_conv_char is to translate one character
  117. * at a time. This needs to be written carefully so that it works
  118. * with double-byte character sets.
  119. * @param convset The handle allocated by apr_xlate_open, specifying the
  120. * parameters of conversion
  121. * @param inchar The character to convert
  122. * @param outchar The converted character
  123. */
  124. APU_DECLARE(apr_status_t) apr_xlate_conv_char(apr_xlate_t *convset,
  125. char inchar, char outchar);
  126. #endif
  127. /**
  128. * Convert a single-byte character from one charset to another.
  129. * @param convset The handle allocated by apr_xlate_open, specifying the
  130. * parameters of conversion
  131. * @param inchar The single-byte character to convert.
  132. * @warning This only works when converting between single-byte character sets.
  133. * -1 will be returned if the conversion can't be performed.
  134. */
  135. APU_DECLARE(apr_int32_t) apr_xlate_conv_byte(apr_xlate_t *convset,
  136. unsigned char inchar);
  137. /**
  138. * Close a codepage translation handle.
  139. * @param convset The codepage translation handle to close
  140. * @remark
  141. * Return APR_ENOTIMPL if charset transcoding is not available
  142. * in this instance of apr-util (i.e., APR_HAS_XLATE is undefined).
  143. */
  144. APU_DECLARE(apr_status_t) apr_xlate_close(apr_xlate_t *convset);
  145. /** @} */
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif /* ! APR_XLATE_H */