TranslateInputCodingSystem.C 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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: TranslateInputCodingSystem.C /main/1 1996/07/29 17:06:28 cde-hp $ */
  24. // Copyright (c) 1995 James Clark
  25. // See the file COPYING for copying permission.
  26. #include "splib.h"
  27. #include "TranslateInputCodingSystem.h"
  28. #ifdef SP_NAMESPACE
  29. namespace SP_NAMESPACE {
  30. #endif
  31. class TranslateDecoder : public Decoder {
  32. public:
  33. TranslateDecoder(const Char *table);
  34. size_t decode(Char *to, const char *from, size_t fromLen,
  35. const char **rest);
  36. Boolean convertOffset(unsigned long &offset) const;
  37. private:
  38. const Char *table_;
  39. };
  40. TranslateInputCodingSystem::TranslateInputCodingSystem(const Char *table)
  41. : table_(table)
  42. {
  43. }
  44. Decoder *TranslateInputCodingSystem::makeDecoder() const
  45. {
  46. return new TranslateDecoder(table_);
  47. }
  48. TranslateDecoder::TranslateDecoder(const Char *table)
  49. : table_(table)
  50. {
  51. }
  52. size_t TranslateDecoder::decode(Char *to, const char *from, size_t fromLen,
  53. const char **rest)
  54. {
  55. for (size_t n = fromLen; n > 0; n--)
  56. *to++ = table_[(unsigned char)*from++]; // zero extend
  57. *rest = from;
  58. return fromLen;
  59. }
  60. Boolean TranslateDecoder::convertOffset(unsigned long &) const
  61. {
  62. return true;
  63. }
  64. #ifdef SP_NAMESPACE
  65. }
  66. #endif