This file is indexed.

/usr/lib/ruby/vendor_ruby/maruku/input/charsource.rb is in ruby-maruku 0.7.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
require 'strscan'

module MaRuKu::In::Markdown::SpanLevelParser

  # a string scanner coded by me
  class CharSourceManual; end

  # a wrapper around StringScanner
  class CharSourceStrscan; end

  # A debug scanner that checks the correctness of both
  # by comparing their output
  class CharSourceDebug; end

  # Choose!

  CharSource = CharSourceManual     # faster! 58ms vs. 65ms
  #CharSource = CharSourceStrscan   # Faster on LONG documents. But StringScanner is buggy in Rubinius
  #CharSource = CharSourceDebug


  class CharSourceManual
    def initialize(s, parent=nil)
      raise "Passed #{s.class}" if not s.kind_of? String
      @buffer = s
      @buffer_index = 0
      @parent = parent
    end

    # Return current char as a String (or nil).
    def cur_char
      cur_chars(1)
    end

    # Return the next n chars as a String.
    def cur_chars(n)
      return nil if @buffer_index >= @buffer.size
      @buffer[@buffer_index, n]
    end

    # Return the char after current char as a String (or nil).
    def next_char
      return nil if @buffer_index + 1 >= @buffer.size
      @buffer[@buffer_index + 1, 1]
    end

    def shift_char
      c = cur_char
      @buffer_index += 1
      c
    end

    def ignore_char
      @buffer_index += 1
    end

    def ignore_chars(n)
      @buffer_index += n
    end

    def current_remaining_buffer
      @buffer[@buffer_index, @buffer.size - @buffer_index]
    end

    def cur_chars_are(string)
      cur_chars(string.size) == string
    end

    def next_matches(r)
      r2 = /^.{#{@buffer_index}}#{r}/m
      r2.match @buffer
    end

    def read_regexp(r)
      r2 = /^#{r}/
      rest = current_remaining_buffer
      m = r2.match(rest)
      if m
        @buffer_index += m.to_s.size
      end
      m
    end

    def consume_whitespace
      while c = cur_char
        break unless (c == ' ' || c == "\t")
        ignore_char
      end
    end

    def describe
      s = describe_pos(@buffer, @buffer_index)
      if @parent
        s += "\n\n" + @parent.describe
      end
      s
    end

    def describe_pos(buffer, buffer_index)
      len = 75
      num_before = [len/2, buffer_index].min
      num_after = [len/2, buffer.size - buffer_index].min
      num_before_max = buffer_index
      num_after_max = buffer.size - buffer_index

      num_before = [num_before_max, len - num_after].min
      num_after  = [num_after_max, len - num_before].min

      index_start = [buffer_index - num_before, 0].max
      index_end   = [buffer_index + num_after, buffer.size].min

      size = index_end - index_start

      str = buffer[index_start, size]
      str.gsub!("\n", 'N')
      str.gsub!("\t", 'T')

      if index_end == buffer.size
        str += "EOF"
      end

      pre_s = buffer_index - index_start
      pre_s = [pre_s, 0].max
      pre_s2 = [len - pre_s, 0].max
      pre = " " * pre_s

      "-" * len + "\n" +
        str + "\n" +
        "-" * pre_s + "|" + "-" * pre_s2 + "\n" +
        pre + "+--- Byte #{buffer_index}\n"+

        "Shown bytes [#{index_start} to #{size}] of #{buffer.size}:\n"+
        buffer.gsub(/^/, ">")
    end
  end

  class CharSourceStrscan

    def initialize(s, parent=nil)
      @scanner = StringScanner.new(s)
      @size = s.size
    end

    # Return current char as a String (or nil).
    def cur_char
      @scanner.peek(1)[0]
    end

    # Return the next n chars as a String.
    def cur_chars(n)
      @scanner.peek(n)
    end

    # Return the char after current char as a String (or nil).
    def next_char
      @scanner.peek(2)[1]
    end

    # Return a character as a String, advancing the pointer.
    def shift_char
      @scanner.getch[0]
    end

    # Advance the pointer
    def ignore_char
      @scanner.getch
    end

    # Advance the pointer by n
    def ignore_chars(n)
      n.times { @scanner.getch }
    end

    # Return the rest of the string
    def current_remaining_buffer
      @scanner.rest
    end

    # Returns true if string matches what we're pointing to
    def cur_chars_are(string)
      @scanner.peek(string.size) == string
    end

    # Returns true if Regexp r matches what we're pointing to
    def next_matches(r)
      @scanner.check(r)
    end

    def read_regexp(r)
      r.match(@scanner.scan(r))
    end

    def consume_whitespace
      @scanner.skip(/\s+/)
    end

    def describe
      len = 75
      num_before = [len/2, @scanner.pos].min
      num_after = [len/2, @scanner.rest_size].min
      num_before_max = @scanner.pos
      num_after_max = @scanner.rest_size

      num_before = [num_before_max, len - num_after].min
      num_after  = [num_after_max, len - num_before].min

      index_start = [@scanner.pos - num_before, 0].max
      index_end   = [@scanner.pos + num_after, @size].min

      size = index_end - index_start

      str = @scanner.string[index_start, size]
      str.gsub!("\n", 'N')
      str.gsub!("\t", 'T')

      if index_end == @size
        str += "EOF"
      end

      pre_s = @scanner.pos - index_start
      pre_s = [pre_s, 0].max
      pre_s2 = [len-pre_s, 0].max
      pre = " " * pre_s

      "-" * len + "\n" +
        str + "\n" +
        "-" * pre_s + "|" + "-" * pre_s2 + "\n" +
        pre + "+--- Byte #{@scanner.pos}\n" +
        "Shown bytes [#{index_start} to #{size}] of #{@size}:\n" +
        @scanner.string.gsub(/^/, ">")
    end
  end

  class CharSourceDebug
    def initialize(s, parent)
      @a = CharSourceManual.new(s, parent)
      @b = CharSourceStrscan.new(s, parent)
    end

    def method_missing(methodname, *args)
      a_bef = @a.describe
      b_bef = @b.describe

      a = @a.send(methodname, *args)
      b = @b.send(methodname, *args)

      if a.kind_of? MatchData
        if a.to_a != b.to_a
          puts "called: #{methodname}(#{args})"
          puts "Matchdata:\na = #{a.to_a.inspect}\nb = #{b.to_a.inspect}"
          puts "AFTER: " + @a.describe
          puts "AFTER: " + @b.describe
          puts "BEFORE: " + a_bef
          puts "BEFORE: " + b_bef
          puts caller.join("\n")
          exit
        end
      else
        if a != b
          puts "called: #{methodname}(#{args})"
          puts "Attenzione!\na = #{a.inspect}\nb = #{b.inspect}"
          puts "" + @a.describe
          puts "" + @b.describe
          puts caller.join("\n")
          exit
        end
      end

      if @a.cur_char != @b.cur_char
        puts "Fuori sincronia dopo #{methodname}(#{args})"
        puts "" + @a.describe
        puts "" + @b.describe
        exit
      end

      return a
    end
  end
end