Sha256: f4990666df338c07820ce7eb9f58f99681e1e45c634c47d0b07a7ae14375fa46

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# -*- coding: utf-8; mode: ruby; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2
# -*- vim:fenc=utf-8:filetype=ruby:et:sw=2:ts=2:sts=2

# Provides content escaping helpers.
module GitCommitNotifier::EscapeHelper
  # Expand tabs into spaces.
  # @param [String] s Text to be expanded.
  # @param [FixNum] tabWidth One tab indentation (in count of spaces).
  # @return [String] Expanded text.
  def expand_tabs(s, tabWidth)
    delta = 0
    s.gsub(/\t/) do |m|
      add = tabWidth - (delta + $~.offset(0)[0]) % tabWidth
      delta += add - 1
      " " * add
    end
  end

  # Escapes expanded content using CGI.escapeHTML and {#expand_tabs}.
  # @param [String] s Text to be expanded and extended.
  # @return [String] Escaped and expanded text.
  # @see #expand_tabs
  def escape_content(s)
    CGI.escapeHTML(expand_tabs(s, 4)).gsub(" ", " ")
  end

  def decode_escaped_filename( filename )
    filename.gsub( /\\\d\d\d\\\d\d\d/ ) { |match|
      mb_char_code  = match.split( '\\' )[ 1, 2 ]
      mb_char_code.map! { |x| x.oct }
      mb_char_code.pack( 'C*' ).force_encoding( 'UTF-8')
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git-commit-notifier-0.12.10 lib/git_commit_notifier/escape_helper.rb