UnivCharsetDesc.C 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.C /main/1 1996/07/29 17:07:43 cde-hp $ */
  24. // Copyright (c) 1994 James Clark
  25. // See the file COPYING for copying permission.
  26. #ifdef __GNUG__
  27. #pragma implementation
  28. #endif
  29. #include "splib.h"
  30. #include "UnivCharsetDesc.h"
  31. #include "macros.h"
  32. #include "constant.h"
  33. #ifdef SP_NAMESPACE
  34. namespace SP_NAMESPACE {
  35. #endif
  36. UnivCharsetDesc::UnivCharsetDesc()
  37. {
  38. }
  39. UnivCharsetDesc::UnivCharsetDesc(const Range *p, size_t n)
  40. {
  41. set(p, n);
  42. }
  43. void UnivCharsetDesc::set(const Range *p, size_t n)
  44. {
  45. for (size_t i = 0; i < n; i++) {
  46. const Range &r = p[i];
  47. WideChar max;
  48. if (r.count > wideCharMax || r.descMin > wideCharMax - r.count)
  49. max = wideCharMax;
  50. else
  51. max = r.descMin + (r.count - 1);
  52. if (max - r.descMin > univCharMax
  53. || r.univMin > univCharMax - (max - r.descMin))
  54. max = r.descMin + (univCharMax - r.univMin);
  55. descToUniv_.addRange(r.descMin, max, r.univMin);
  56. }
  57. }
  58. void UnivCharsetDesc::addBaseRange(const UnivCharsetDesc &baseSet,
  59. WideChar descMin,
  60. WideChar descMax,
  61. WideChar baseMin,
  62. ISet<WideChar> &baseMissing)
  63. {
  64. UnivCharsetDescIter iter(baseSet);
  65. WideChar baseMax = baseMin + (descMax - descMin);
  66. WideChar iDescMin, iDescMax;
  67. UnivChar iBaseMin;
  68. WideChar missingBaseMin = baseMin;
  69. Boolean usedAll = 0;
  70. while (iter.next(iDescMin, iDescMax, iBaseMin) && iDescMin <= baseMax) {
  71. // baseMin baseMax
  72. // iDescMin iDescMax
  73. if (iDescMax >= baseMin) {
  74. WideChar min = baseMin > iDescMin ? baseMin : iDescMin;
  75. if (min > missingBaseMin)
  76. baseMissing.addRange(missingBaseMin, min - 1);
  77. WideChar max = baseMax < iDescMax ? baseMax : iDescMax;
  78. missingBaseMin = max + 1;
  79. if (missingBaseMin == 0)
  80. usedAll = 1;
  81. ASSERT(min <= max);
  82. descToUniv_.addRange(descMin + (min - baseMin),
  83. descMin + (max - baseMin),
  84. iBaseMin + (min - iDescMin));
  85. }
  86. }
  87. if (!usedAll && baseMax >= missingBaseMin)
  88. baseMissing.addRange(missingBaseMin, baseMax);
  89. }
  90. #ifdef SP_NAMESPACE
  91. }
  92. #endif