msgformat_data.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | http://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Stanislav Malyshev <stas@zend.com> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #include <unicode/ustring.h>
  20. #include "msgformat_data.h"
  21. #include "msgformat_class.h"
  22. /* {{{ void msgformat_data_init( msgformat_data* mf_data )
  23. * Initialize internals of msgformat_data.
  24. */
  25. void msgformat_data_init( msgformat_data* mf_data TSRMLS_DC )
  26. {
  27. if( !mf_data )
  28. return;
  29. mf_data->umsgf = NULL;
  30. mf_data->orig_format = NULL;
  31. mf_data->arg_types = NULL;
  32. mf_data->tz_set = 0;
  33. intl_error_reset( &mf_data->error TSRMLS_CC );
  34. }
  35. /* }}} */
  36. /* {{{ void msgformat_data_free( msgformat_data* mf_data )
  37. * Clean up memory allocated for msgformat_data
  38. */
  39. void msgformat_data_free(msgformat_data* mf_data TSRMLS_DC)
  40. {
  41. if (!mf_data)
  42. return;
  43. if (mf_data->umsgf)
  44. umsg_close(mf_data->umsgf);
  45. if (mf_data->orig_format) {
  46. efree(mf_data->orig_format);
  47. mf_data->orig_format = NULL;
  48. }
  49. if (mf_data->arg_types) {
  50. zend_hash_destroy(mf_data->arg_types);
  51. efree(mf_data->arg_types);
  52. mf_data->arg_types = NULL;
  53. }
  54. mf_data->umsgf = NULL;
  55. intl_error_reset(&mf_data->error TSRMLS_CC);
  56. }
  57. /* }}} */
  58. /* {{{ msgformat_data* msgformat_data_create()
  59. * Allocate memory for msgformat_data and initialize it with default values.
  60. */
  61. msgformat_data* msgformat_data_create( TSRMLS_D )
  62. {
  63. msgformat_data* mf_data = ecalloc( 1, sizeof(msgformat_data) );
  64. msgformat_data_init( mf_data TSRMLS_CC );
  65. return mf_data;
  66. }
  67. /* }}} */
  68. #ifdef MSG_FORMAT_QUOTE_APOS
  69. int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec)
  70. {
  71. if(*spattern && *spattern_len && u_strchr(*spattern, (UChar)'\'')) {
  72. UChar *npattern = safe_emalloc(sizeof(UChar)*2, *spattern_len, sizeof(UChar));
  73. uint32_t npattern_len;
  74. npattern_len = umsg_autoQuoteApostrophe(*spattern, *spattern_len, npattern, 2*(*spattern_len)+1, ec);
  75. efree(*spattern);
  76. if( U_FAILURE(*ec) )
  77. {
  78. return FAILURE;
  79. }
  80. npattern = erealloc(npattern, sizeof(UChar)*(npattern_len+1));
  81. *spattern = npattern;
  82. *spattern_len = npattern_len;
  83. }
  84. return SUCCESS;
  85. }
  86. #endif
  87. /*
  88. * Local variables:
  89. * tab-width: 4
  90. * c-basic-offset: 4
  91. * End:
  92. * vim600: noet sw=4 ts=4 fdm=marker
  93. * vim<600: noet sw=4 ts=4
  94. */