UnivCharsetDesc.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: UnivCharsetDesc.h /main/1 1996/07/29 17:07:49 cde-hp $ */
  24. // Copyright (c) 1994 James Clark
  25. // See the file COPYING for copying permission.
  26. #ifndef UnivCharsetDesc_INCLUDED
  27. #define UnivCharsetDesc_INCLUDED 1
  28. #ifdef __GNUG__
  29. #pragma interface
  30. #endif
  31. #include <stddef.h>
  32. #include "types.h"
  33. #include "RangeMap.h"
  34. #include "Boolean.h"
  35. #include "ISet.h"
  36. #ifdef SP_NAMESPACE
  37. namespace SP_NAMESPACE {
  38. #endif
  39. #ifndef SP_API
  40. #define SP_API
  41. #endif
  42. class SP_API UnivCharsetDesc {
  43. public:
  44. struct SP_API Range {
  45. WideChar descMin;
  46. // Note that this is a count, as in the SGML declaration,
  47. // rather than a maximum.
  48. unsigned long count;
  49. UnivChar univMin;
  50. };
  51. enum {
  52. zero = 48,
  53. A = 65,
  54. a = 97,
  55. tab = 9,
  56. rs = 10,
  57. re = 13,
  58. space = 32,
  59. exclamation = 33,
  60. lessThan = 60,
  61. greaterThan = 62
  62. };
  63. UnivCharsetDesc();
  64. UnivCharsetDesc(const Range *, size_t);
  65. void set(const Range *, size_t);
  66. Boolean descToUniv(WideChar from, UnivChar &to) const;
  67. Boolean descToUniv(WideChar from, UnivChar &to, WideChar &alsoMax) const;
  68. // Return 0 for no matches, 1 for 1, 2 for more than 1
  69. unsigned univToDesc(UnivChar from, WideChar &to, ISet<WideChar> &toSet)
  70. const;
  71. unsigned univToDesc(UnivChar from, WideChar &to, ISet<WideChar> &toSet,
  72. WideChar &count)
  73. const;
  74. void addRange(WideChar descMin, WideChar descMax, UnivChar univMin);
  75. void addBaseRange(const UnivCharsetDesc &baseSet,
  76. WideChar descMin,
  77. WideChar descMax,
  78. WideChar baseMin,
  79. ISet<WideChar> &baseMissing);
  80. WideChar maxDesc() const;
  81. private:
  82. RangeMap<WideChar,UnivChar> descToUniv_;
  83. friend class UnivCharsetDescIter;
  84. };
  85. class SP_API UnivCharsetDescIter {
  86. public:
  87. UnivCharsetDescIter(const UnivCharsetDesc &);
  88. Boolean next(WideChar &descMin, WideChar &descMax, UnivChar &univMin);
  89. private:
  90. RangeMapIter<WideChar,UnivChar> iter_;
  91. };
  92. inline
  93. Boolean UnivCharsetDesc::descToUniv(WideChar from, UnivChar &to) const
  94. {
  95. WideChar tem;
  96. return descToUniv_.map(from, to, tem);
  97. }
  98. inline
  99. Boolean UnivCharsetDesc::descToUniv(WideChar from, UnivChar &to,
  100. WideChar &alsoMax) const
  101. {
  102. return descToUniv_.map(from, to, alsoMax);
  103. }
  104. inline
  105. unsigned UnivCharsetDesc::univToDesc(UnivChar from, WideChar &to,
  106. ISet<WideChar> &toSet) const
  107. {
  108. WideChar tem;
  109. return descToUniv_.inverseMap(from, to, toSet, tem);
  110. }
  111. inline
  112. unsigned UnivCharsetDesc::univToDesc(UnivChar from, WideChar &to,
  113. ISet<WideChar> &toSet,
  114. WideChar &count) const
  115. {
  116. return descToUniv_.inverseMap(from, to, toSet, count);
  117. }
  118. inline
  119. void UnivCharsetDesc::addRange(WideChar descMin,
  120. WideChar descMax,
  121. UnivChar univMin)
  122. {
  123. descToUniv_.addRange(descMin, descMax, univMin);
  124. }
  125. inline
  126. UnivCharsetDescIter::UnivCharsetDescIter(const UnivCharsetDesc &desc)
  127. : iter_(desc.descToUniv_)
  128. {
  129. }
  130. inline
  131. Boolean UnivCharsetDescIter::next(WideChar &descMin,
  132. WideChar &descMax,
  133. UnivChar &univMin)
  134. {
  135. return iter_.next(descMin, descMax, univMin);
  136. }
  137. #ifdef SP_NAMESPACE
  138. }
  139. #endif
  140. #endif /* not UnivCharsetDesc_INCLUDED */