global

def self.extract_quoted_strings(string)

Returns:
  • (IndexSet) - Hash of parsed from code strings and their start indices

Parameters:
  • string (String) -- A parsed scripts code string, containing raw Ruby code
def self.extract_quoted_strings(string)
    result = IndexSet.new

    skip_block = false
    in_quotes = false
    quote_type = nil
    buffer = []

    string.each_line do |line|
        stripped = line.strip

        next if stripped[0] == '#' ||
            !stripped.match?(/["']/) ||
            stripped.start_with?(/(Win|Lose)|_Fanfare/) ||
            stripped.match?(/eval\(/)

        skip_block = true if stripped.start_with?('=begin')
        skip_block = false if stripped.start_with?('=end')

        next if skip_block

        buffer.push('\#') if in_quotes

        line.each_char do |char|
            if %w[' "].include?(char)
                unless quote_type.nil? || char == quote_type
                    buffer.push(char)
                    next
                end

                quote_type = char
                in_quotes = !in_quotes
                result.add(buffer.join)
                buffer.clear
                next
            end

            buffer.push(char) if in_quotes
        end
    end

    result
end