Class: Git::EscapedPath Private
- Inherits:
-
Object
- Object
- Git::EscapedPath
- Defined in:
- lib/git/escaped_path.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps single-character escapes to their decoded byte values
{ '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 ⇒ String
readonly
private
Returns the escaped path as provided by git output.
Instance Method Summary collapse
-
#initialize(path)
constructor
private
Initializes an escaped path wrapper.
-
#unescape ⇒ String
private
Converts an escaped path to an unescaped UTF-8 path.
Constructor Details
#initialize(path)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes an escaped path wrapper
44 45 46 |
# File 'lib/git/escaped_path.rb', line 44 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the escaped path as provided by git output
37 38 39 |
# File 'lib/git/escaped_path.rb', line 37 def path @path end |
Instance Method Details
#unescape ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts an escaped path to an unescaped UTF-8 path
55 56 57 58 59 |
# File 'lib/git/escaped_path.rb', line 55 def unescape bytes = escaped_path_to_bytes(path) str = bytes.pack('C*') str.force_encoding(Encoding::UTF_8) end |