class CountLnString < String def initialize(filename) @filename = filename @lnchar = "\n" @buf = "" @str = "" @countln = 1 @current = 1 super(report_line) end def report_line "#line #{@current} \"#{@filename}\"\n" end def concat0(s) ln(caller[0]) @buf.concat(s) @str.concat(s) end def concat1(s) ln(caller[0]) @buf.concat(s) end def ln(status=nil) case status when /:(\d+):/ n = $1.to_i else n = status.to_i end return if n == @current if @current != @countln || @postpone if /\A\s*\z/ =~ @str || /\A#line / =~ @buf || /\n\z/ !~ self @postpone = true elsif @in_comment @postpone = false else concat(report_line) @postpone = false end end concat(@buf) b = @buf.gsub(/".*?(?