ucnv_imp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 1999-2011, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. *
  9. *
  10. * ucnv_imp.h:
  11. * Contains all internal and external data structure definitions
  12. * Created & Maintained by Bertrand A. Damiba
  13. *
  14. *
  15. *
  16. * ATTENTION:
  17. * ---------
  18. * Although the data structures in this file are open and stack allocatable
  19. * we reserve the right to hide them in further releases.
  20. */
  21. #ifndef UCNV_IMP_H
  22. #define UCNV_IMP_H
  23. #include "unicode/utypes.h"
  24. #if !UCONFIG_NO_CONVERSION
  25. #include "unicode/uloc.h"
  26. #include "ucnv_bld.h"
  27. /*
  28. * Fast check for whether a charset name is "UTF-8".
  29. * This does not recognize all of the variations that ucnv_open()
  30. * and other functions recognize, but it covers most cases.
  31. * @param name const char * charset name
  32. * @return
  33. */
  34. #define UCNV_FAST_IS_UTF8(name) \
  35. (((name[0]=='U' ? \
  36. ( name[1]=='T' && name[2]=='F') : \
  37. (name[0]=='u' && name[1]=='t' && name[2]=='f'))) \
  38. && (name[3]=='-' ? \
  39. (name[4]=='8' && name[5]==0) : \
  40. (name[3]=='8' && name[4]==0)))
  41. typedef struct {
  42. char cnvName[UCNV_MAX_CONVERTER_NAME_LENGTH];
  43. char locale[ULOC_FULLNAME_CAPACITY];
  44. uint32_t options;
  45. } UConverterNamePieces;
  46. U_CFUNC UBool
  47. ucnv_canCreateConverter(const char *converterName, UErrorCode *err);
  48. /* figures out if we need to go to file to read in the data tables.
  49. * @param converterName The name of the converter
  50. * @param err The error code
  51. * @return the newly created converter
  52. */
  53. U_CAPI UConverter *
  54. ucnv_createConverter(UConverter *myUConverter, const char *converterName, UErrorCode * err);
  55. /*
  56. * Open a purely algorithmic converter, specified by a type constant.
  57. * @param myUConverter NULL, or pre-allocated UConverter structure to avoid
  58. * a memory allocation
  59. * @param type requested converter type
  60. * @param locale locale parameter, or ""
  61. * @param options converter options bit set (default 0)
  62. * @param err ICU error code, not tested for U_FAILURE on input
  63. * because this is an internal function
  64. * @internal
  65. */
  66. U_CFUNC UConverter *
  67. ucnv_createAlgorithmicConverter(UConverter *myUConverter,
  68. UConverterType type,
  69. const char *locale, uint32_t options,
  70. UErrorCode *err);
  71. /*
  72. * Creates a converter from shared data.
  73. * Adopts mySharedConverterData: No matter what happens, the caller must not
  74. * unload mySharedConverterData, except via ucnv_close(return value)
  75. * if this function is successful.
  76. */
  77. U_CFUNC UConverter *
  78. ucnv_createConverterFromSharedData(UConverter *myUConverter,
  79. UConverterSharedData *mySharedConverterData,
  80. UConverterLoadArgs *pArgs,
  81. UErrorCode *err);
  82. U_CFUNC UConverter *
  83. ucnv_createConverterFromPackage(const char *packageName, const char *converterName, UErrorCode *err);
  84. /**
  85. * Load a converter but do not create a UConverter object.
  86. * Simply return the UConverterSharedData.
  87. * Performs alias lookup etc.
  88. * The UConverterNamePieces need not be initialized
  89. * before calling this function.
  90. * The UConverterLoadArgs must be initialized
  91. * before calling this function.
  92. * If the args are passed in, then the pieces must be passed in too.
  93. * In other words, the following combinations are allowed:
  94. * - pieces==NULL && args==NULL
  95. * - pieces!=NULL && args==NULL
  96. * - pieces!=NULL && args!=NULL
  97. * @internal
  98. */
  99. U_CFUNC UConverterSharedData *
  100. ucnv_loadSharedData(const char *converterName,
  101. UConverterNamePieces *pieces,
  102. UConverterLoadArgs *pArgs,
  103. UErrorCode * err);
  104. /**
  105. * This may unload the shared data in a thread safe manner.
  106. * This will only unload the data if no other converters are sharing it.
  107. */
  108. U_CFUNC void
  109. ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData);
  110. /**
  111. * This is a thread safe way to increment the reference count.
  112. */
  113. U_CFUNC void
  114. ucnv_incrementRefCount(UConverterSharedData *sharedData);
  115. /**
  116. * These are the default error handling callbacks for the charset conversion framework.
  117. * For performance reasons, they are only called to handle an error (not normally called for a reset or close).
  118. */
  119. #define UCNV_TO_U_DEFAULT_CALLBACK ((UConverterToUCallback) UCNV_TO_U_CALLBACK_SUBSTITUTE)
  120. #define UCNV_FROM_U_DEFAULT_CALLBACK ((UConverterFromUCallback) UCNV_FROM_U_CALLBACK_SUBSTITUTE)
  121. #endif
  122. #endif /* _UCNV_IMP */