Sha256: 7aa558fd5bb0f9e2c76637056102edecf637859a67ee97425ff3d2191db88d16

Contents?: true

Size: 688 Bytes

Versions: 6

Compression:

Stored size: 688 Bytes

Contents

module Vobject
  class << self
    MAX_LINE_WIDTH = 75
    def unfold(str)
      str.gsub(/(\r|\n|\r\n)[ \t]/, "")
    end

    # This implements the line folding as specified in
    # http://tools.ietf.org/html/rfc6350#section-3.2
    # NOTE: the "line" here is not including the trailing \n
    def fold_line(line)
      folded_line    = line[0, MAX_LINE_WIDTH]
      remainder_line = line[MAX_LINE_WIDTH, line.length - MAX_LINE_WIDTH] || ""

      max_width = MAX_LINE_WIDTH - 1

      (0..((remainder_line.length - 1) / max_width)).each do |i|
        folded_line << "\n "
        folded_line << remainder_line[i * max_width, max_width]
      end

      folded_line
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vobject-1.1.0 lib/vobject.rb
ruby-vobject-1.0.99 lib/vobject.rb
vobject-1.0.2 lib/vobject.rb
ruby-vobject-1.0.1 lib/vobject.rb
ruby-vobject-1.0.0-x86_64-darwin-18 lib/vobject.rb
ruby-vobject-0.2.0-x86_64-darwin-16 lib/vobject.rb