iso88598.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  16. #include <config.h>
  17. #include <stdio.h>
  18. #include "iso88598.h"
  19. #include "univalues.h"
  20. #define ISO88598_HEB_ALEF 0xE0
  21. #define ISO88598_HEB_TAV 0xFA
  22. // The following 7 codes were taken from FriBiDi's fribidi_char_sets_iso8859_8.c.
  23. // These are "proposed extensions to ISO-8859-8."
  24. #define ISO88598_LRM 0xFD
  25. #define ISO88598_RLM 0xFE
  26. #define ISO88598_LRE 0xFB
  27. #define ISO88598_RLE 0xFC
  28. #define ISO88598_PDF 0xDD
  29. #define ISO88598_LRO 0xDB
  30. #define ISO88598_RLO 0xDC
  31. // int unicode_to_iso88598(unichar ch)
  32. //
  33. // This is a fallback function used for saving files when no iconv
  34. // implementation is present.
  35. //
  36. // It returns EOF when the unicode character can't be represented in
  37. // ISO-8859-9.
  38. int unicode_to_iso88598(unichar ch)
  39. {
  40. if (ch <= 0xA0)
  41. return ch;
  42. if (ch >= UNI_HEB_ALEF && ch <= UNI_HEB_TAV)
  43. return ISO88598_HEB_ALEF + (ch - UNI_HEB_ALEF);
  44. switch (ch) {
  45. case 0x00D7: return 0xAA; // MULTIPLICATION SIGN
  46. case 0x00F7: return 0xBA; // DIVISION SIGN
  47. case 0x2017: return 0xDF; // DOUBLE LOW LINE
  48. }
  49. if (ch >= 0xA2 && ch <= 0xBE)
  50. return ch;
  51. // The following are non-standard conversions.
  52. switch (ch) {
  53. case UNI_LRM: return ISO88598_LRM;
  54. case UNI_RLM: return ISO88598_RLM;
  55. case UNI_LRE: return ISO88598_LRE;
  56. case UNI_RLE: return ISO88598_RLE;
  57. case UNI_PDF: return ISO88598_PDF;
  58. case UNI_LRO: return ISO88598_LRO;
  59. case UNI_RLO: return ISO88598_RLO;
  60. }
  61. return EOF;
  62. }
  63. // unichar iso88598_to_unicode(unsigned char ch)
  64. //
  65. // This is a fallback function used for loading files when no iconv
  66. // implementation is present.
  67. //
  68. // It returns the Unicode Replacement Character when it encounters a
  69. // character which is illegal in ISO-8859-9.
  70. unichar iso88598_to_unicode(unsigned char ch)
  71. {
  72. if (ch <= 0xA0)
  73. return ch;
  74. if (ch >= ISO88598_HEB_ALEF && ch <= ISO88598_HEB_TAV)
  75. return UNI_HEB_ALEF + (ch - ISO88598_HEB_ALEF);
  76. switch (ch) {
  77. case 0xAA: return 0x00D7; // MULTIPLICATION SIGN
  78. case 0xBA: return 0x00F7; // DIVISION SIGN
  79. case 0xDF: return 0x2017; // DOUBLE LOW LINE
  80. }
  81. if (ch >= 0xA2 && ch <= 0xBE)
  82. return ch;
  83. // The following are non-standard conversions.
  84. switch (ch) {
  85. case ISO88598_LRM: return UNI_LRM;
  86. case ISO88598_RLM: return UNI_RLM;
  87. case ISO88598_LRE: return UNI_LRE;
  88. case ISO88598_RLE: return UNI_RLE;
  89. case ISO88598_PDF: return UNI_PDF;
  90. case ISO88598_LRO: return UNI_LRO;
  91. case ISO88598_RLO: return UNI_RLO;
  92. }
  93. return UNI_REPLACEMENT;
  94. }