/src/lib/io/filter/quoted_printable_input_stream.e

http://github.com/tybor/Liberty · Specman e · 125 lines · 87 code · 12 blank · 26 comment · 6 complexity · 4268eb6d2a862b21c7587713ebc1a767 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class QUOTED_PRINTABLE_INPUT_STREAM
  5. --
  6. -- A quoted-printable decoder. Plug it onto a quoted-printable-encoded stream.
  7. --
  8. inherit
  9. FILTER_INPUT_STREAM
  10. create {ANY}
  11. connect_to
  12. feature {ANY}
  13. last_character_flag: BOOLEAN
  14. feature {}
  15. local_can_disconnect: BOOLEAN True
  16. feature {FILTER_INPUT_STREAM}
  17. filtered_read_character
  18. local
  19. c: CHARACTER
  20. do
  21. if last_character_flag then
  22. swap_last_character
  23. last_character_flag := False
  24. else
  25. stream.filtered_read_character
  26. if stream.valid_last_character then
  27. c := stream.filtered_last_character
  28. if c /= '=' or else stream.end_of_input or else not read_quoted_character then
  29. filtered_last_character := c
  30. end
  31. end
  32. end
  33. end
  34. filtered_unread_character
  35. do
  36. swap_last_character
  37. last_character_flag := True
  38. end
  39. filtered_last_character: CHARACTER
  40. feature {}
  41. read_quoted_character: BOOLEAN
  42. local
  43. s: STRING; i: INTEGER
  44. do
  45. s := once ""
  46. s.clear_count
  47. stream.filtered_read_character
  48. s.extend(stream.filtered_last_character)
  49. if stream.end_of_input then
  50. stream.filtered_unread_character
  51. else
  52. stream.filtered_read_character
  53. s.extend(stream.filtered_last_character)
  54. i := from_hexadecimal(s)
  55. filtered_last_character := i.to_character
  56. Result := True
  57. end
  58. end
  59. last_character_swap: CHARACTER
  60. swap_last_character
  61. local
  62. c: CHARACTER
  63. do
  64. c := filtered_last_character
  65. filtered_last_character := last_character_swap
  66. last_character_swap := c
  67. end
  68. from_hexadecimal (s: STRING): INTEGER
  69. local
  70. i, n: INTEGER; c: CHARACTER
  71. do
  72. from
  73. i := s.lower
  74. until
  75. i > s.upper
  76. loop
  77. c := s.item(i)
  78. inspect
  79. c
  80. when '0' .. '9' then
  81. n := c.code - '0'.code
  82. when 'a' .. 'f' then
  83. n := c.code - 'a'.code + 10
  84. when 'A' .. 'F' then
  85. n := c.code - 'A'.code + 10
  86. else
  87. i := s.upper
  88. end
  89. Result := Result * 16 + n
  90. i := i + 1
  91. end
  92. end
  93. end -- class QUOTED_PRINTABLE_INPUT_STREAM
  94. --
  95. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  96. --
  97. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  98. -- of this software and associated documentation files (the "Software"), to deal
  99. -- in the Software without restriction, including without limitation the rights
  100. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  101. -- copies of the Software, and to permit persons to whom the Software is
  102. -- furnished to do so, subject to the following conditions:
  103. --
  104. -- The above copyright notice and this permission notice shall be included in
  105. -- all copies or substantial portions of the Software.
  106. --
  107. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  108. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  109. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  110. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  111. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  112. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  113. -- THE SOFTWARE.