CharsetInfo.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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: CharsetInfo.h /main/1 1996/07/29 16:47:24 cde-hp $ */
  24. // Copyright (c) 1994 James Clark
  25. // See the file COPYING for copying permission.
  26. #ifndef CharsetInfo_INCLUDED
  27. #define CharsetInfo_INCLUDED 1
  28. #ifdef __GNUG__
  29. #pragma interface
  30. #endif
  31. #include <limits.h>
  32. #include "UnivCharsetDesc.h"
  33. #include "Boolean.h"
  34. #include "types.h"
  35. #include "StringC.h"
  36. #include "ISet.h"
  37. #ifdef SP_NAMESPACE
  38. namespace SP_NAMESPACE {
  39. #endif
  40. class SP_API CharsetInfo {
  41. public:
  42. CharsetInfo();
  43. CharsetInfo(const UnivCharsetDesc &);
  44. void set(const UnivCharsetDesc &);
  45. // Use only for characters guaranteed to me in the C basic execution
  46. // character set and which have been verified to be in this
  47. // character set.
  48. Char execToDesc(char) const;
  49. StringC execToDesc(const char *s) const;
  50. Boolean descToUniv(WideChar from, UnivChar &to) const;
  51. Boolean descToUniv(WideChar from, UnivChar &to, WideChar &alsoMax) const;
  52. // Return 0 for no matches, 1 for 1, 2 for more than 1
  53. // to gets the first character; toSet gets all the characters
  54. // if there's more than 1.
  55. unsigned univToDesc(UnivChar from, WideChar &to, ISet<WideChar> &toSet)
  56. const;
  57. unsigned univToDesc(UnivChar from, WideChar &to, ISet<WideChar> &toSet,
  58. WideChar &count)
  59. const;
  60. void getDescSet(ISet<Char> &) const;
  61. int digitWeight(Char) const;
  62. const UnivCharsetDesc &desc() const;
  63. private:
  64. void init();
  65. UnivCharsetDesc desc_;
  66. enum { nSmall = 128 };
  67. // 0 for no matches, 1 for 1, 2 for more than 1
  68. unsigned smallUnivValid_[nSmall];
  69. WideChar smallUnivToDesc_[nSmall];
  70. PackedBoolean smallDescValid_[nSmall];
  71. UnivChar smallDescToUniv_[nSmall];
  72. Char execToDesc_[UCHAR_MAX + 1];
  73. };
  74. inline
  75. unsigned CharsetInfo::univToDesc(UnivChar from, WideChar &to,
  76. ISet<WideChar> &toSet)
  77. const
  78. {
  79. if (from < nSmall && smallUnivValid_[from] <= 1) {
  80. if (smallUnivValid_[from]) {
  81. to = smallUnivToDesc_[from];
  82. return 1;
  83. }
  84. else
  85. return 0;
  86. }
  87. else
  88. return desc_.univToDesc(from, to, toSet);
  89. }
  90. inline
  91. Boolean CharsetInfo::descToUniv(UnivChar from, WideChar &to) const
  92. {
  93. if (from < nSmall) {
  94. if (smallDescValid_[from]) {
  95. to = smallDescToUniv_[from];
  96. return 1;
  97. }
  98. else
  99. return 0;
  100. }
  101. else
  102. return desc_.descToUniv(from, to);
  103. }
  104. inline
  105. Char CharsetInfo::execToDesc(char c) const
  106. {
  107. return execToDesc_[(unsigned char)c];
  108. }
  109. inline
  110. Boolean CharsetInfo::descToUniv(WideChar from, UnivChar &to,
  111. WideChar &alsoMax) const
  112. {
  113. return desc_.descToUniv(from, to, alsoMax);
  114. }
  115. inline
  116. unsigned CharsetInfo::univToDesc(UnivChar from, WideChar &to,
  117. ISet<WideChar> &toSet, WideChar &count)
  118. const
  119. {
  120. return desc_.univToDesc(from, to, toSet, count);
  121. }
  122. inline
  123. const UnivCharsetDesc &CharsetInfo::desc() const
  124. {
  125. return desc_;
  126. }
  127. #ifdef SP_NAMESPACE
  128. }
  129. #endif
  130. #endif /* not CharsetInfo_INCLUDED */