PageRenderTime 14ms CodeModel.GetById 9ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/src/tools/wrappers-generator/formatter.e

http://github.com/tybor/Liberty
Specman e | 112 lines | 70 code | 16 blank | 26 comment | 1 complexity | ba58007176a8639539a4ebcb07c965ad MD5 | raw file
  1class FORMATTER
  2   -- A STRING_FORMATTER class using a buffer string as output.
  3   -- Strings and messages can be easily appended with `append' and
  4   -- `put_message'.
  5   -- The formatted content can be printed on streams with `print_on' and
  6   -- appended to other strings with `append_on'
  7
  8inherit
  9   STRING_FORMATTER
 10      redefine default_create, out, print_on
 11      end
 12
 13create {ANY}
 14   default_create
 15
 16feature {ANY}
 17   clear, reset
 18         -- Clears the content of Current's buffer.
 19      do
 20         if buffer.is_empty then
 21            debug
 22               std_error.put_line(once "Unnecessary invocation of FORMATTER.reset")
 23               -- That's way too verbose print_run_time_stack
 24            end
 25         else
 26            buffer.clear_count
 27         end
 28      end
 29
 30   reset_with (a_string: STRING)
 31         -- Overwrite the content of Current's buffer with a copy of `a_string'.
 32      do
 33         buffer.copy(a_string)
 34      end
 35
 36   out: STRING
 37         -- A newly create copy of Current content
 38      do
 39         create Result.copy(buffer)
 40      end
 41
 42   append (a_string: ABSTRACT_STRING)
 43         -- Append `a_string' to the content of Current
 44      do
 45         buffer.append(a_string)
 46      end
 47
 48   append_new_line
 49         -- Append a new line to Current
 50      do
 51         buffer.append(once "%N")
 52      end
 53
 54   append_on (a_string: STRING)
 55         -- Append the content of Current to `a_string'
 56      require
 57         a_string /= Void
 58      do
 59         a_string.append(buffer)
 60      end
 61
 62   print_on (a_stream: OUTPUT_STREAM)
 63         -- Put current content on `a_stream'
 64      do
 65         a_stream.put_string(buffer)
 66         reset
 67      ensure
 68         is_empty
 69      end
 70
 71   is_empty: BOOLEAN
 72         -- Is current empty?
 73      do
 74         Result := buffer.is_empty
 75      end
 76
 77   count: INTEGER
 78         -- Content length
 79      do
 80         Result := buffer.count
 81      end
 82
 83   default_create
 84      do
 85         create buffer.make_empty
 86      end
 87
 88   put (c: CHARACTER)
 89      do
 90         buffer.append_character(c)
 91      end
 92
 93feature {} -- Implementation
 94   put_item (item: ABSTRACT_STRING)
 95      do
 96         buffer.append(item.out)
 97      end
 98
 99   buffer: STRING
100
101end -- class FORMATTER
102-- Copyright (C) 2008-2017: ,2009 Paolo Redaelli
103-- eiffel-gcc-xml  is free software: you can redistribute it and/or modify it
104-- under the terms of the GNU General Public License as publhed by the Free
105-- Software Foundation, either version 2 of the License, or (at your option)
106-- any later version.
107-- eiffel-gcc-xml is distributed in the hope that it will be useful, but
108-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
109-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
110-- more details.
111-- You should have received a copy of the GNU General Public License along with
112-- th program.  If not, see <http://www.gnu.org/licenses/>.