• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jnbt / java-properties / 4254512104

pending completion
4254512104

Pull #21

github

GitHub
Merge bd6a0ab8d into c409d01fa
Pull Request #21: Test on Ruby 3.1 and 3.2

334 of 339 relevant lines covered (98.53%)

134.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/java-properties/encoding/special_chars.rb
1
module JavaProperties
7✔
2
  module Encoding
7✔
3
    # Module to escape and unescape special chars
4
    # @see JavaProperties::Encoding
5
    module SpecialChars
7✔
6

7
      # Lookup table for escaping special chars
8
      # @return [Hash]
9
      ESCAPING = {
2✔
10
        "\t" => '\\t',
5✔
11
        "\r" => '\\r',
12
        "\n" => '\\n',
13
        "\f" => '\\f',
14
        "\\" => '\\\\',
15
      }.freeze
16

17
      # Lookup table to remove escaping from special chars
18
      # @return [Hash]
19
      DESCAPING = ESCAPING.invert.freeze
7✔
20

21
      # Marks a segment which has is an encoding special char
22
      # @return [Regexp]
23
      DESCAPING_MARKER = /\\./
7✔
24

25
      # Encodes the content a text by escaping all special chars
26
      # @param text [String]
27
      # @return [String] The escaped text for chaining
28
      def self.encode!(text)
7✔
29
        buffer = StringIO.new
574✔
30
        text.each_char do |char|
574✔
31
          buffer << ESCAPING.fetch(char, char)
5,621✔
32
        end
33
        text.replace buffer.string
574✔
34
        text
574✔
35
      end
36

37
      # Decodes the content a text by removing all escaping from special chars
38
      # @param text [String]
39
      # @return [String] The unescaped text for chaining
40
      def self.decode!(text)
7✔
41
        text.gsub!(DESCAPING_MARKER) do |match|
294✔
42
          DESCAPING.fetch(match, match)
189✔
43
        end
44
        text
294✔
45
      end
46

47
    end
48
  end
49
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc