Sha256: c9ccd03373c016265c4adc433f337a40e7c1f8821b3e16fa5e822a833eaa5216

Contents?: true

Size: 1.86 KB

Versions: 6

Compression:

Stored size: 1.86 KB

Contents

require 'java-properties/encoding/special_chars'
require 'java-properties/encoding/separators'
require 'java-properties/encoding/unicode'

module JavaProperties
  # Module to encode and decode
  #
  # Usage:
  #    encoded = Encoding.encode!("Some text to be encoded")
  #    decoded = Encoding.decode!("Some text to be decoded")
  #
  # You can disable separate encoding (and decoding) steps,
  # by passing in additional flags:
  #
  # * SKIP_SEPARATORS: Do not code the separators (space,:,=)
  # * SKIP_UNICODE: Do not code unicode chars
  # * SKIP_SPECIAL_CHARS: Do not code newlines, tab stops, ...
  #
  module Encoding

    # Flag for skipping separators encodings / decoding
    # @return [Symbol]
    SKIP_SEPARATORS=:skip_separators

    # Flag for skipping separators encodings / decoding
    # @return [Symbol]
    SKIP_UNICODE=:skip_unicode

    # Flag for skipping separators encodings / decoding
    # @return [Symbol]
    SKIP_SPECIAL_CHARS=:skip_special_chars

    # Encode a given text in place
    # @param text [String]
    # @param *flags [Array] Optional flags to skip encoding steps
    # @return [String] The encoded text for chaining
    def self.encode!(text, *flags)
      SpecialChars.encode!(text)  unless flags.include?(SKIP_SPECIAL_CHARS)
      Separators.encode!(text)    unless flags.include?(SKIP_SEPARATORS)
      Unicode.encode!(text)       unless flags.include?(SKIP_UNICODE)
      text
    end
    
    # Decodes a given text in place
    # @param text [String]
    # @param *flags [Array] Optional flags to skip decoding steps
    # @return [String] The decoded text for chaining
    def self.decode!(text, *flags)
      Unicode.decode!(text)       unless flags.include?(SKIP_UNICODE)
      Separators.decode!(text)    unless flags.include?(SKIP_SEPARATORS)
      SpecialChars.decode!(text)  unless flags.include?(SKIP_SPECIAL_CHARS)
      text
    end

  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
java-properties-0.3.0 lib/java-properties/encoding.rb
java-properties-0.2.1 lib/java-properties/encoding.rb
java-properties-0.2.0 lib/java-properties/encoding.rb
java-properties-0.1.1 lib/java-properties/encoding.rb
java-properties-0.1.0 lib/java-properties/encoding.rb
ruby-properties-file-0.0.2 lib/java-properties/encoding.rb