PageRenderTime 25ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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