collationfastlatinbuilder.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. * Copyright (C) 2013-2016, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. *******************************************************************************
  8. * collationfastlatinbuilder.h
  9. *
  10. * created on: 2013aug09
  11. * created by: Markus W. Scherer
  12. */
  13. #ifndef __COLLATIONFASTLATINBUILDER_H__
  14. #define __COLLATIONFASTLATINBUILDER_H__
  15. #include "unicode/utypes.h"
  16. #if !UCONFIG_NO_COLLATION
  17. #include "unicode/ucol.h"
  18. #include "unicode/unistr.h"
  19. #include "unicode/uobject.h"
  20. #include "collation.h"
  21. #include "collationfastlatin.h"
  22. #include "uvectr64.h"
  23. U_NAMESPACE_BEGIN
  24. struct CollationData;
  25. class U_I18N_API CollationFastLatinBuilder : public UObject {
  26. public:
  27. CollationFastLatinBuilder(UErrorCode &errorCode);
  28. ~CollationFastLatinBuilder();
  29. UBool forData(const CollationData &data, UErrorCode &errorCode);
  30. const uint16_t *getTable() const {
  31. return reinterpret_cast<const uint16_t *>(result.getBuffer());
  32. }
  33. int32_t lengthOfTable() const { return result.length(); }
  34. private:
  35. // space, punct, symbol, currency (not digit)
  36. enum { NUM_SPECIAL_GROUPS = UCOL_REORDER_CODE_CURRENCY - UCOL_REORDER_CODE_FIRST + 1 };
  37. UBool loadGroups(const CollationData &data, UErrorCode &errorCode);
  38. UBool inSameGroup(uint32_t p, uint32_t q) const;
  39. void resetCEs();
  40. void getCEs(const CollationData &data, UErrorCode &errorCode);
  41. UBool getCEsFromCE32(const CollationData &data, UChar32 c, uint32_t ce32,
  42. UErrorCode &errorCode);
  43. UBool getCEsFromContractionCE32(const CollationData &data, uint32_t ce32,
  44. UErrorCode &errorCode);
  45. void addContractionEntry(int32_t x, int64_t cce0, int64_t cce1, UErrorCode &errorCode);
  46. void addUniqueCE(int64_t ce, UErrorCode &errorCode);
  47. uint32_t getMiniCE(int64_t ce) const;
  48. UBool encodeUniqueCEs(UErrorCode &errorCode);
  49. UBool encodeCharCEs(UErrorCode &errorCode);
  50. UBool encodeContractions(UErrorCode &errorCode);
  51. uint32_t encodeTwoCEs(int64_t first, int64_t second) const;
  52. static UBool isContractionCharCE(int64_t ce) {
  53. return (uint32_t)(ce >> 32) == Collation::NO_CE_PRIMARY && ce != Collation::NO_CE;
  54. }
  55. static const uint32_t CONTRACTION_FLAG = 0x80000000;
  56. // temporary "buffer"
  57. int64_t ce0, ce1;
  58. int64_t charCEs[CollationFastLatin::NUM_FAST_CHARS][2];
  59. UVector64 contractionCEs;
  60. UVector64 uniqueCEs;
  61. /** One 16-bit mini CE per unique CE. */
  62. uint16_t *miniCEs;
  63. // These are constant for a given root collator.
  64. uint32_t lastSpecialPrimaries[NUM_SPECIAL_GROUPS];
  65. uint32_t firstDigitPrimary;
  66. uint32_t firstLatinPrimary;
  67. uint32_t lastLatinPrimary;
  68. // This determines the first normal primary weight which is mapped to
  69. // a short mini primary. It must be >=firstDigitPrimary.
  70. uint32_t firstShortPrimary;
  71. UBool shortPrimaryOverflow;
  72. UnicodeString result;
  73. int32_t headerLength;
  74. };
  75. U_NAMESPACE_END
  76. #endif // !UCONFIG_NO_COLLATION
  77. #endif // __COLLATIONFASTLATINBUILDER_H__