scrptrun.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. *
  6. * Copyright (C) 1999-2003, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. *******************************************************************************
  10. * file name: scrptrun.h
  11. *
  12. * created on: 10/17/2001
  13. * created by: Eric R. Mader
  14. */
  15. #ifndef __SCRPTRUN_H
  16. #define __SCRPTRUN_H
  17. #include "unicode/utypes.h"
  18. #include "unicode/uobject.h"
  19. #include "unicode/uscript.h"
  20. U_NAMESPACE_BEGIN
  21. struct ScriptRecord
  22. {
  23. UChar32 startChar;
  24. UChar32 endChar;
  25. UScriptCode scriptCode;
  26. };
  27. struct ParenStackEntry
  28. {
  29. int32_t pairIndex;
  30. UScriptCode scriptCode;
  31. };
  32. class ScriptRun : public UObject {
  33. public:
  34. ScriptRun();
  35. ScriptRun(const UChar chars[], int32_t length);
  36. ScriptRun(const UChar chars[], int32_t start, int32_t length);
  37. void reset();
  38. void reset(int32_t start, int32_t count);
  39. void reset(const UChar chars[], int32_t start, int32_t length);
  40. int32_t getScriptStart();
  41. int32_t getScriptEnd();
  42. UScriptCode getScriptCode();
  43. UBool next();
  44. /**
  45. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  46. *
  47. * @stable ICU 2.2
  48. */
  49. virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
  50. /**
  51. * ICU "poor man's RTTI", returns a UClassID for this class.
  52. *
  53. * @stable ICU 2.2
  54. */
  55. static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
  56. private:
  57. static UBool sameScript(int32_t scriptOne, int32_t scriptTwo);
  58. int32_t charStart;
  59. int32_t charLimit;
  60. const UChar *charArray;
  61. int32_t scriptStart;
  62. int32_t scriptEnd;
  63. UScriptCode scriptCode;
  64. ParenStackEntry parenStack[128];
  65. int32_t parenSP;
  66. static int8_t highBit(int32_t value);
  67. static int32_t getPairIndex(UChar32 ch);
  68. static UChar32 pairedChars[];
  69. static const int32_t pairedCharCount;
  70. static const int32_t pairedCharPower;
  71. static const int32_t pairedCharExtra;
  72. /**
  73. * The address of this static class variable serves as this class's ID
  74. * for ICU "poor man's RTTI".
  75. */
  76. static const char fgClassID;
  77. };
  78. inline ScriptRun::ScriptRun()
  79. {
  80. reset(NULL, 0, 0);
  81. }
  82. inline ScriptRun::ScriptRun(const UChar chars[], int32_t length)
  83. {
  84. reset(chars, 0, length);
  85. }
  86. inline ScriptRun::ScriptRun(const UChar chars[], int32_t start, int32_t length)
  87. {
  88. reset(chars, start, length);
  89. }
  90. inline int32_t ScriptRun::getScriptStart()
  91. {
  92. return scriptStart;
  93. }
  94. inline int32_t ScriptRun::getScriptEnd()
  95. {
  96. return scriptEnd;
  97. }
  98. inline UScriptCode ScriptRun::getScriptCode()
  99. {
  100. return scriptCode;
  101. }
  102. inline void ScriptRun::reset()
  103. {
  104. scriptStart = charStart;
  105. scriptEnd = charStart;
  106. scriptCode = USCRIPT_INVALID_CODE;
  107. parenSP = -1;
  108. }
  109. inline void ScriptRun::reset(int32_t start, int32_t length)
  110. {
  111. charStart = start;
  112. charLimit = start + length;
  113. reset();
  114. }
  115. inline void ScriptRun::reset(const UChar chars[], int32_t start, int32_t length)
  116. {
  117. charArray = chars;
  118. reset(start, length);
  119. }
  120. U_NAMESPACE_END
  121. #endif