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

jnbt / java-properties / 4254520611

pending completion
4254520611

push

github

GitHub
Merge pull request #21 from jnbt/update-ruby

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/separators.rb
1
module JavaProperties
7✔
2
  module Encoding
7✔
3
    # Module to escape separators as : or =
4
    # @see JavaProperties::Encoding
5
    module Separators
7✔
6

7
      # Marker for all separators
8
      # @return [Regexp]
9
      ENCODE_SEPARATOR_MARKER = /[ :=]/
7✔
10

11
      # Marker for already escaped separators
12
      # @return [Regexp]
13
      ESCAPING_MARKER  = /\\/
7✔
14

15
      # Char to use for escaping
16
      # @return [String]
17
      ESCAPE           = "\\"
7✔
18

19
      # Marker for all escaped separators
20
      # @return [Regexp]
21
      DECODE_SEPARATOR_MARKER = /\\([ :=])/
7✔
22

23
      # Escapes all not already escaped separators
24
      # @param text [text]
25
      # @return [String] The escaped text for chaining
26
      def self.encode!(text)
7✔
27
        buffer = StringIO.new
294✔
28
        last_token = ''
294✔
29
        text.each_char do |char|
294✔
30
          if char =~ ENCODE_SEPARATOR_MARKER && last_token !~ ESCAPING_MARKER
2,366✔
31
            buffer << ESCAPE
301✔
32
          end
33
          buffer << char
2,366✔
34
          last_token = char
2,366✔
35
        end
36
        text.replace buffer.string
294✔
37
        text
294✔
38
      end
39

40
      # Removes escapes from escaped separators
41
      # @param text [text]
42
      # @return [String] The unescaped text for chaining
43
      def self.decode!(text)
7✔
44
        text.gsub!(DECODE_SEPARATOR_MARKER) do
154✔
45
          $1
259✔
46
        end
47
        text
154✔
48
      end
49

50
    end
51
  end
52
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