Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimise shared_string_collection_parser #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/saxlsx/shared_string_collection_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,31 @@ def self.parse(file_system, &block)

def initialize(&block)
@block = block
@extract = false
end

def start_element(name)
@current_string = String.new if name == :si
case name
when :si then @current_string = nil
when :t then @extract = true
end
end

def end_element(name)
if name == :si
@block.call @current_string
@current_string = nil
case name
when :si then @block.call(@current_string)
when :t then @extract = false
end
end

def text(value)
@current_string << CGI.unescapeHTML(value) if @current_string
if @extract
if @current_string
@current_string << CGI.unescapeHTML(value)
else
@current_string = CGI.unescapeHTML(value)
end
end
end

end
end