Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * DiffOutput.java
  3. * Copyright (c) 2001 Andre Kaplan
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package jdiff.util;
  20. import java.io.IOException;
  21. import java.io.Writer;
  22. import java.io.OutputStreamWriter;
  23. /** A base class for printing edit scripts produced by Diff. */
  24. public abstract class DiffOutput {
  25. /** Set to the lines of the files being compared. */
  26. protected Object[] file0;
  27. protected Object[] file1;
  28. protected String lineSeparator;
  29. protected Writer out;
  30. protected DiffOutput(Object[] a,Object[] b) {
  31. this.lineSeparator = System.getProperty("java.line.separator");
  32. this.out = new OutputStreamWriter(System.out);
  33. this.file0 = a;
  34. this.file1 = b;
  35. }
  36. public void setOut(Writer out) {
  37. this.out = out;
  38. }
  39. public void setLineSeparator(String lineSeparator) {
  40. this.lineSeparator = lineSeparator;
  41. }
  42. abstract public void writeScript(Diff.change script) throws IOException;
  43. protected void writeLine(String prefix, Object line) throws IOException {
  44. out.write(prefix + line.toString() + this.lineSeparator);
  45. }
  46. /** Write a pair of line numbers separated with sepChar.
  47. If the two numbers are identical, print just one number.
  48. Args a and b are internal line numbers (ranging from 0)
  49. We write the translated (real) line numbers ranging from 1).
  50. */
  51. protected void writeNumberRange(char sepChar, int a, int b) throws IOException {
  52. /* Note: we can have b < a in the case of a range of no lines.
  53. In this case, we should write the line number before the range,
  54. which is b. */
  55. if (++b > ++a) {
  56. out.write(Integer.toString(a));
  57. out.write(sepChar);
  58. out.write(Integer.toString(b));
  59. } else {
  60. out.write(Integer.toString(b));
  61. }
  62. }
  63. public static char changeLetter(int inserts, int deletes) {
  64. if (inserts == 0) {
  65. return 'd';
  66. } else if (deletes == 0) {
  67. return 'a';
  68. } else {
  69. return 'c';
  70. }
  71. }
  72. }