FileOutputer.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. namespace csharp_sccd_compiler
  5. {
  6. public class FileOutputer
  7. {
  8. int indent_level = 0;
  9. int nr_of_indent_chars = 4;
  10. char indent_char = ' ';
  11. bool first_write = true;
  12. StreamWriter output_file;
  13. public FileOutputer(string output_file_path)
  14. {
  15. this.output_file = new StreamWriter(output_file_path, false);
  16. }
  17. public void write(string text = "")
  18. {
  19. if (this.first_write)
  20. {
  21. this.first_write = false;
  22. this.output_file.Write(new String(this.indent_char, this.indent_level * this.nr_of_indent_chars) + text);
  23. }
  24. else
  25. {
  26. this.output_file.WriteLine();
  27. this.output_file.Write(new String(this.indent_char, this.indent_level * this.nr_of_indent_chars) + text);
  28. }
  29. }
  30. public void extendWrite(string text = "")
  31. {
  32. this.output_file.Write(text);
  33. }
  34. public void indent()
  35. {
  36. this.indent_level += 1;
  37. }
  38. public void dedent()
  39. {
  40. this.indent_level -= 1;
  41. }
  42. public void close()
  43. {
  44. this.output_file.Close();
  45. }
  46. }
  47. }