Mercurial > hg > soundsoftware-site
comparison lib/redmine/unified_diff.rb @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | 433d4f72a19b |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
26 @diff_type = options[:type] || 'inline' | 26 @diff_type = options[:type] || 'inline' |
27 @diff_style = options[:style] | 27 @diff_style = options[:style] |
28 lines = 0 | 28 lines = 0 |
29 @truncated = false | 29 @truncated = false |
30 diff_table = DiffTable.new(diff_type, diff_style) | 30 diff_table = DiffTable.new(diff_type, diff_style) |
31 diff.each do |line| | 31 diff.each do |line_raw| |
32 line_encoding = nil | 32 line = Redmine::CodesetUtil.to_utf8_by_setting(line_raw) |
33 if line.respond_to?(:force_encoding) | 33 unless diff_table.add_line(line) |
34 line_encoding = line.encoding | |
35 # TODO: UTF-16 and Japanese CP932 which is imcompatible with ASCII | |
36 # In Japan, diffrence between file path encoding | |
37 # and file contents encoding is popular. | |
38 line.force_encoding('ASCII-8BIT') | |
39 end | |
40 unless diff_table.add_line line | |
41 line.force_encoding(line_encoding) if line_encoding | |
42 self << diff_table if diff_table.length > 0 | 34 self << diff_table if diff_table.length > 0 |
43 diff_table = DiffTable.new(diff_type, diff_style) | 35 diff_table = DiffTable.new(diff_type, diff_style) |
44 end | 36 end |
45 lines += 1 | 37 lines += 1 |
46 if options[:max_lines] && lines > options[:max_lines] | 38 if options[:max_lines] && lines > options[:max_lines] |
81 @line_num_l = $2.to_i | 73 @line_num_l = $2.to_i |
82 @line_num_r = $5.to_i | 74 @line_num_r = $5.to_i |
83 @parsing = true | 75 @parsing = true |
84 end | 76 end |
85 else | 77 else |
86 if line =~ /^[^\+\-\s@\\]/ | 78 if line =~ %r{^[^\+\-\s@\\]} |
87 @parsing = false | 79 @parsing = false |
88 return false | 80 return false |
89 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/ | 81 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/ |
90 @line_num_l = $2.to_i | 82 @line_num_l = $2.to_i |
91 @line_num_r = $5.to_i | 83 @line_num_r = $5.to_i |
205 max = [line_left.size, line_right.size].min | 197 max = [line_left.size, line_right.size].min |
206 starting = 0 | 198 starting = 0 |
207 while starting < max && line_left[starting] == line_right[starting] | 199 while starting < max && line_left[starting] == line_right[starting] |
208 starting += 1 | 200 starting += 1 |
209 end | 201 end |
202 if (! "".respond_to?(:force_encoding)) && starting < line_left.size | |
203 while line_left[starting].ord.between?(128, 191) && starting > 0 | |
204 starting -= 1 | |
205 end | |
206 end | |
210 ending = -1 | 207 ending = -1 |
211 while ending >= -(max - starting) && line_left[ending] == line_right[ending] | 208 while ending >= -(max - starting) && line_left[ending] == line_right[ending] |
212 ending -= 1 | 209 ending -= 1 |
210 end | |
211 if (! "".respond_to?(:force_encoding)) && ending > (-1 * line_left.size) | |
212 while line_left[ending].ord.between?(128, 191) && ending > -1 | |
213 ending -= 1 | |
214 end | |
213 end | 215 end |
214 unless starting == 0 && ending == -1 | 216 unless starting == 0 && ending == -1 |
215 [starting, ending] | 217 [starting, ending] |
216 end | 218 end |
217 end | 219 end |
266 end | 268 end |
267 | 269 |
268 private | 270 private |
269 | 271 |
270 def line_to_html(line, offsets) | 272 def line_to_html(line, offsets) |
273 html = line_to_html_raw(line, offsets) | |
274 html.force_encoding('UTF-8') if html.respond_to?(:force_encoding) | |
275 html | |
276 end | |
277 | |
278 def line_to_html_raw(line, offsets) | |
271 if offsets | 279 if offsets |
272 s = '' | 280 s = '' |
273 unless offsets.first == 0 | 281 unless offsets.first == 0 |
274 s << CGI.escapeHTML(line[0..offsets.first-1]) | 282 s << CGI.escapeHTML(line[0..offsets.first-1]) |
275 end | 283 end |