File: sst_entry.rb

package info (click to toggle)
ruby-spreadsheet 1.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,980 kB
  • sloc: ruby: 6,939; makefile: 10
file content (48 lines) | stat: -rw-r--r-- 1,248 bytes parent folder | download
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
require "spreadsheet/encodings"

module Spreadsheet
  module Excel
    ##
    # Shared String Table Entry
    class SstEntry
      include Spreadsheet::Encodings
      attr_accessor :chars, :phonetic, :richtext, :flags, :available,
        :continued_chars, :wide
      def initialize opts = {}
        @content = nil
        @offset = opts[:offset]
        @ole = opts[:ole]
        @reader = opts[:reader]
        @continuations = []
      end

      ##
      # Access the contents of this Shared String
      def content
        @content or begin
          data = @ole[@offset, @available]
          content, _ = @reader.read_string_body data, @flags, @available, @wide
          @continuations.each do |offset, len|
            @reader.continue_string(@ole[offset, len], [content, @chars])
          end
          content = client content, "UTF-16LE"
          if @reader.memoize?
            @content = content
          end
          content
        end
      end

      ##
      # Register the offset of a String continuation
      def continue offset, size, chars
        @continued_chars -= chars
        @continuations.push [offset, size]
      end

      def continued? # :nodoc:
        @continued_chars > 0
      end
    end
  end
end