/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

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