Sha256: 5a8126f8afd6f8d81cd9f6e6c87e02e5c73f26b2f0ed114aa638a81521fac8e0

Contents?: true

Size: 1.33 KB

Versions: 15

Compression:

Stored size: 1.33 KB

Contents

# coding: utf-8

module Fig; end
class  Fig::TokenizedString; end

class Fig::TokenizedString::PlainSegment
  attr_reader :raw_value

  def initialize(raw_value)
    @raw_value     = raw_value

    return
  end

  def type
    return nil
  end

  def to_expanded_string(&block)
    return @raw_value.gsub(%r< \\ (.) >xm, '\1')
  end

  def to_escaped_string()
    return @raw_value
  end

  # Should not be invoked if original string was single quoted.
  def to_single_quoted_string()
    # Raw value will have come from a non-single quoted string, so we unescape
    # everything (including backslashes) and then escape backslashes and single
    # quotes (which cannot be escaped outside of single quotes).
    return \
      @raw_value.gsub(%r< \\ (.) >xm, '\1').gsub(%r< ([\\']) >xm, '\\\\\1')
  end

  # Should not be invoked if original string was not single quoted.
  def to_double_quotable_string(metacharacters)
    quoted_value = @raw_value.gsub %r< ( ["#{metacharacters}] ) >xm, '\\\\\1'

    quoted_value.gsub!(
      %r<
        (
          (?: ^ | [^\\] ) # New line or non-backslash
          (\\{2})*        # Even number of backslashes
        )

        # All single quotes must have been escaped.  The important bit is to
        # not lose escaped backslashes.
        \\'
      >xm,
      %q<\1'>
    )

    return quoted_value
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
fig-1.27.10 lib/fig/tokenized_string/plain_segment.rb
fig-1.27.8 lib/fig/tokenized_string/plain_segment.rb
fig-1.27.5 lib/fig/tokenized_string/plain_segment.rb
fig-1.27.4 lib/fig/tokenized_string/plain_segment.rb
fig-1.27.3 lib/fig/tokenized_string/plain_segment.rb
fig-1.27.0 lib/fig/tokenized_string/plain_segment.rb
fig-1.26.1.beta.1 lib/fig/tokenized_string/plain_segment.rb
fig-1.26.0 lib/fig/tokenized_string/plain_segment.rb
fig-1.25.1.beta.1 lib/fig/tokenized_string/plain_segment.rb
fig-1.25.0 lib/fig/tokenized_string/plain_segment.rb
fig-1.24.1.beta.3 lib/fig/tokenized_string/plain_segment.rb
fig-1.24.1.beta.2 lib/fig/tokenized_string/plain_segment.rb
fig-1.24.1.beta.1 lib/fig/tokenized_string/plain_segment.rb
fig-1.24.0 lib/fig/tokenized_string/plain_segment.rb
fig-1.23.1.beta.1 lib/fig/tokenized_string/plain_segment.rb