CodingSystem.C 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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: CodingSystem.C /main/2 1996/08/08 12:10:51 mgreess $ */
  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 "CodingSystem.h"
  31. #ifdef SP_SHORT_HEADERS
  32. #include <strstrea.h>
  33. #else
  34. #if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
  35. #include <strstream>
  36. #else
  37. #include <strstream.h>
  38. #endif
  39. #endif
  40. #include <string.h>
  41. #include <sys/param.h>
  42. #ifdef SP_NAMESPACE
  43. namespace SP_NAMESPACE {
  44. #endif
  45. InputCodingSystem::~InputCodingSystem()
  46. {
  47. }
  48. StringC InputCodingSystem::convertIn(const char *s) const
  49. {
  50. Decoder *decoder = makeDecoder();
  51. StringC str;
  52. str.resize(strlen(s));
  53. str.resize(decoder->decode(&str[0], s, strlen(s), &s));
  54. delete decoder;
  55. return str;
  56. }
  57. Boolean InputCodingSystem::isIdentity() const
  58. {
  59. return 0;
  60. }
  61. OutputCodingSystem::~OutputCodingSystem()
  62. {
  63. }
  64. unsigned OutputCodingSystem::fixedBytesPerChar() const
  65. {
  66. return 0;
  67. }
  68. String<char> OutputCodingSystem::convertOut(const StringC &str) const
  69. {
  70. Encoder *encoder = makeEncoder();
  71. strstreambuf stream(MAXPATHLEN);
  72. StringC copy(str);
  73. encoder->output(copy.data(), copy.size(), &stream);
  74. delete encoder;
  75. char *s = stream.str();
  76. #if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
  77. String<char> result(s, stream.pcount());
  78. #else
  79. String<char> result(s, stream.out_waiting());
  80. #endif
  81. result += '\0';
  82. stream.freeze(0);
  83. #ifdef __lucid
  84. // Workaround lcc bug (3.1p2 with -O -XF).
  85. String<char> temp(result);
  86. return temp;
  87. #else
  88. return result;
  89. #endif
  90. }
  91. Decoder::Decoder(unsigned minBytesPerChar)
  92. : minBytesPerChar_(minBytesPerChar)
  93. {
  94. }
  95. Decoder::~Decoder()
  96. {
  97. }
  98. Boolean Decoder::convertOffset(unsigned long &) const
  99. {
  100. return false;
  101. }
  102. Encoder::Encoder()
  103. : unencodableHandler_(0)
  104. {
  105. }
  106. Encoder::~Encoder()
  107. {
  108. }
  109. void Encoder::output(Char *s, size_t n, streambuf *sp)
  110. {
  111. output((const Char *)s, n, sp);
  112. }
  113. void Encoder::startFile(streambuf *)
  114. {
  115. }
  116. #ifdef SP_NAMESPACE
  117. }
  118. #endif