Class: Git::EscapedPath
- Inherits:
-
Object
- Object
- Git::EscapedPath
- Defined in:
- lib/git/escaped_path.rb
Overview
Represents an escaped Git path string
Git commands that output paths (e.g. ls-files, diff), will escape unusual characters in the path with backslashes in the same way C escapes control characters (e.g. \t for TAB, \n for LF, \ for backslash) or bytes with values larger than 0x80 (e.g. octal \302\265 for "micro" in UTF-8).
Constant Summary collapse
- UNESCAPES =
{ 'a' => 0x07, 'b' => 0x08, 't' => 0x09, 'n' => 0x0a, 'v' => 0x0b, 'f' => 0x0c, 'r' => 0x0d, 'e' => 0x1b, '\\' => 0x5c, '"' => 0x22, "'" => 0x27 }.freeze
Instance Attribute Summary collapse
-
#path
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ EscapedPath
constructor
A new instance of EscapedPath.
-
#unescape
Convert an escaped path to an unescaped path.
Constructor Details
#initialize(path) ⇒ EscapedPath
Returns a new instance of EscapedPath.
31 32 33 |
# File 'lib/git/escaped_path.rb', line 31 def initialize(path) @path = path end |
Instance Attribute Details
#path (readonly)
Returns the value of attribute path.
29 30 31 |
# File 'lib/git/escaped_path.rb', line 29 def path @path end |
Instance Method Details
#unescape
Convert an escaped path to an unescaped path
36 37 38 39 40 |
# File 'lib/git/escaped_path.rb', line 36 def unescape bytes = escaped_path_to_bytes(path) str = bytes.pack('C*') str.force_encoding(Encoding::UTF_8) end |