libpath-ruby 0.2.2 → 0.2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +33 -0
- data/README.md +25 -8
- data/examples/path_from_arg0.md +43 -43
- data/examples/path_from_arg0.rb +25 -23
- data/lib/libpath/constants/unix.rb +71 -71
- data/lib/libpath/constants/windows.rb +72 -72
- data/lib/libpath/constants.rb +18 -19
- data/lib/libpath/diagnostics/parameter_checking.rb +25 -25
- data/lib/libpath/diagnostics.rb +1 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +13 -13
- data/lib/libpath/exceptions/malformed_name_exception.rb +23 -22
- data/lib/libpath/exceptions.rb +1 -1
- data/lib/libpath/form/unix.rb +104 -103
- data/lib/libpath/form/windows.rb +200 -199
- data/lib/libpath/form.rb +18 -18
- data/lib/libpath/internal_/array.rb +53 -53
- data/lib/libpath/internal_/platform.rb +24 -24
- data/lib/libpath/internal_/string.rb +18 -18
- data/lib/libpath/internal_/unix/form.rb +116 -116
- data/lib/libpath/internal_/windows/drive.rb +59 -59
- data/lib/libpath/internal_/windows/form.rb +189 -189
- data/lib/libpath/libpath.rb +3 -0
- data/lib/libpath/path/unix.rb +114 -112
- data/lib/libpath/path/windows.rb +120 -118
- data/lib/libpath/path.rb +18 -20
- data/lib/libpath/util/unix.rb +258 -258
- data/lib/libpath/util/windows.rb +400 -400
- data/lib/libpath/util.rb +18 -19
- data/lib/libpath/version.rb +23 -24
- data/lib/libpath.rb +1 -1
- data/test/performance/benchmark_drive_letter.rb +50 -10
- data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
- data/test/performance/benchmark_rindex2.rb +56 -48
- data/test/performance/benchmark_split.rb +16 -10
- data/test/unit/compare/ts_all.rb +4 -4
- data/test/unit/equate/ts_all.rb +4 -4
- data/test/unit/equate/unix/ts_all.rb +4 -4
- data/test/unit/equate/windows/ts_all.rb +4 -4
- data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
- data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
- data/test/unit/exceptions/ts_all.rb +4 -4
- data/test/unit/form/tc_absolute_functions.rb +242 -240
- data/test/unit/form/ts_all.rb +4 -4
- data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
- data/test/unit/form/unix/ts_all.rb +4 -4
- data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
- data/test/unit/form/windows/ts_all.rb +4 -4
- data/test/unit/internal_/tc_array.rb +36 -32
- data/test/unit/internal_/ts_all.rb +4 -4
- data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
- data/test/unit/internal_/unix/form/ts_all.rb +4 -4
- data/test/unit/internal_/unix/tc_split_path.rb +387 -384
- data/test/unit/internal_/unix/ts_all.rb +4 -4
- data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
- data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
- data/test/unit/internal_/windows/form/ts_all.rb +4 -4
- data/test/unit/internal_/windows/tc_split_path.rb +874 -869
- data/test/unit/internal_/windows/ts_all.rb +4 -4
- data/test/unit/parse/ts_all.rb +4 -4
- data/test/unit/path/tc_path.rb +732 -732
- data/test/unit/path/ts_all.rb +4 -4
- data/test/unit/path/unix/tc_path.rb +544 -540
- data/test/unit/path/unix/ts_all.rb +4 -4
- data/test/unit/path/windows/tc_path.rb +608 -603
- data/test/unit/path/windows/ts_all.rb +4 -4
- data/test/unit/tc_version.rb +25 -22
- data/test/unit/ts_all.rb +4 -4
- data/test/unit/util/tc_combine_paths.rb +110 -105
- data/test/unit/util/tc_derive_relative_path.rb +8 -3
- data/test/unit/util/tc_make_path_canonical.rb +142 -138
- data/test/unit/util/ts_all.rb +4 -4
- data/test/unit/util/unix/tc_combine_paths.rb +38 -34
- data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
- data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
- data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
- data/test/unit/util/unix/ts_all.rb +4 -4
- data/test/unit/util/windows/tc_combine_paths.rb +82 -77
- data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
- data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
- data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
- data/test/unit/util/windows/ts_all.rb +4 -4
- metadata +9 -8
data/lib/libpath/form/unix.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: libpath/form/unix.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: LibPath::Form::Unix module
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 8th January 2019
|
8
|
+
# Updated: 6th April 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/libpath.Ruby
|
11
11
|
#
|
12
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
14
15
|
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
16
|
# All rights reserved.
|
16
17
|
#
|
@@ -44,13 +45,13 @@
|
|
44
45
|
# ######################################################################## #
|
45
46
|
|
46
47
|
|
47
|
-
|
48
48
|
=begin
|
49
49
|
=end
|
50
50
|
|
51
51
|
require 'libpath/constants/unix'
|
52
52
|
require 'libpath/diagnostics'
|
53
53
|
|
54
|
+
|
54
55
|
module LibPath # :nodoc:
|
55
56
|
module Form # :nodoc:
|
56
57
|
module Unix # :nodoc:
|
@@ -59,148 +60,148 @@ module Unix # :nodoc:
|
|
59
60
|
# any class or module including/extending module LibPath::Form::Unix
|
60
61
|
module LibPath_Form_Unix_Methods
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
# Classifies a path
|
64
|
+
#
|
65
|
+
# === Return
|
66
|
+
#
|
67
|
+
# One of +:absolute+, +:homed+, +:relative+, for
|
68
|
+
# any paths that match precisely those classifications, or +nil+ if the
|
69
|
+
# path is empty
|
70
|
+
def classify_path path
|
70
71
|
|
71
|
-
|
72
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
72
73
|
|
73
|
-
|
74
|
+
return nil if path.nil? || path.empty?
|
74
75
|
|
75
|
-
|
76
|
+
return :homed if path_is_homed? path
|
76
77
|
|
77
|
-
|
78
|
+
return :absolute if path_is_absolute? path
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
:relative
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
83
|
+
# Evaluates whether the given name is malformed
|
84
|
+
#
|
85
|
+
# === Signature
|
86
|
+
#
|
87
|
+
# * *Options:*
|
88
|
+
# - +:reject_path_name_separators+:: (boolean) Reject the path
|
89
|
+
# separator character(s): +'/'+
|
90
|
+
# - +:reject_path_separators+:: (boolean) Reject the path separator
|
91
|
+
# character(s): +':'+
|
92
|
+
# - +:reject_shell_characters+:: (boolean) Reject the shell
|
93
|
+
# character(s): +'*'+, +'?'+, +'|'+
|
94
|
+
def name_is_malformed? name, **options
|
94
95
|
|
95
|
-
|
96
|
+
_Constants = ::LibPath::Constants::Unix
|
96
97
|
|
97
|
-
|
98
|
+
if name
|
98
99
|
|
99
|
-
|
100
|
+
if options[:reject_path_name_separators]
|
100
101
|
|
101
|
-
|
102
|
-
|
102
|
+
return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
|
103
|
+
end
|
103
104
|
|
104
|
-
|
105
|
+
if options[:reject_path_separators]
|
105
106
|
|
106
|
-
|
107
|
-
|
107
|
+
return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
|
108
|
+
end
|
108
109
|
|
109
|
-
|
110
|
+
if options[:reject_shell_characters]
|
110
111
|
|
111
|
-
|
112
|
-
|
112
|
+
return true if name =~ _Constants::InvalidCharacters::Shell::RE
|
113
|
+
end
|
113
114
|
|
114
|
-
|
115
|
+
return true if name =~ _Constants::InvalidCharacters::Innate::RE
|
115
116
|
|
116
|
-
|
117
|
-
|
117
|
+
false
|
118
|
+
else
|
118
119
|
|
119
|
-
|
120
|
-
|
121
|
-
|
120
|
+
true
|
121
|
+
end
|
122
|
+
end
|
122
123
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
124
|
+
# Evaluates whether the given path is absolute, which means it is either
|
125
|
+
# rooted (begins with '/') or is homed (is '~' or begins with '~/')
|
126
|
+
#
|
127
|
+
# === Signature
|
128
|
+
#
|
129
|
+
# * *Parameters:*
|
130
|
+
# - +path+:: (String) The path to be evaluated. May not be +nil+
|
131
|
+
def path_is_absolute? path
|
131
132
|
|
132
|
-
|
133
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
133
134
|
|
134
|
-
|
135
|
-
|
135
|
+
case path[0]
|
136
|
+
when '/'
|
136
137
|
|
137
|
-
|
138
|
-
|
138
|
+
true
|
139
|
+
when '~'
|
139
140
|
|
140
|
-
|
141
|
-
|
141
|
+
1 == path.size || '/' == path[1]
|
142
|
+
else
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
144
|
+
false
|
145
|
+
end
|
146
|
+
end
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
148
|
+
# Evaluates whether the given path is homed, which means it is '~' or
|
149
|
+
# begins with '~/'
|
150
|
+
#
|
151
|
+
# === Signature
|
152
|
+
#
|
153
|
+
# * *Parameters:*
|
154
|
+
# - +path+:: (String) The path to be evaluated. May not be +nil+
|
155
|
+
def path_is_homed? path
|
155
156
|
|
156
|
-
|
157
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
157
158
|
|
158
|
-
|
159
|
+
return false unless '~' == path[0]
|
159
160
|
|
160
|
-
|
161
|
+
if path.size > 1
|
161
162
|
|
162
|
-
|
163
|
-
|
163
|
+
return '/' == path[1]
|
164
|
+
end
|
164
165
|
|
165
|
-
|
166
|
-
|
166
|
+
true
|
167
|
+
end
|
167
168
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
169
|
+
# Evalutes whether the given path is rooted, which means it begins with
|
170
|
+
# '/'
|
171
|
+
#
|
172
|
+
# === Signature
|
173
|
+
#
|
174
|
+
# * *Parameters:*
|
175
|
+
# - +path+:: (String) The path to be evaluated. May not be +nil+
|
176
|
+
def path_is_rooted? path
|
176
177
|
|
177
|
-
|
178
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
178
179
|
|
179
|
-
|
180
|
-
|
180
|
+
'/' == path[0]
|
181
|
+
end
|
181
182
|
|
182
183
|
end # module LibPath_Form_Unix_Methods
|
183
184
|
|
184
185
|
# @!visibility private
|
185
186
|
def self.extended receiver # :nodoc:
|
186
187
|
|
187
|
-
|
188
|
+
receiver.class_eval do
|
188
189
|
|
189
|
-
|
190
|
-
|
190
|
+
extend LibPath_Form_Unix_Methods
|
191
|
+
end
|
191
192
|
|
192
|
-
|
193
|
+
$stderr.puts "#{receiver} extended by #{LibPath_Form_Unix_Methods}" if $DEBUG
|
193
194
|
end
|
194
195
|
|
195
196
|
# @!visibility private
|
196
197
|
def self.included receiver # :nodoc:
|
197
198
|
|
198
|
-
|
199
|
+
receiver.class_eval do
|
199
200
|
|
200
|
-
|
201
|
-
|
201
|
+
include LibPath_Form_Unix_Methods
|
202
|
+
end
|
202
203
|
|
203
|
-
|
204
|
+
$stderr.puts "#{receiver} included #{LibPath_Form_Unix_Methods}" if $DEBUG
|
204
205
|
end
|
205
206
|
|
206
207
|
extend LibPath_Form_Unix_Methods
|
@@ -210,6 +211,6 @@ end # module Unix
|
|
210
211
|
end # module Form
|
211
212
|
end # module LibPath
|
212
213
|
|
213
|
-
# ############################## end of file ############################# #
|
214
214
|
|
215
|
+
# ############################## end of file ############################# #
|
215
216
|
|