libpath-ruby 0.2.1 → 0.2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +3 -3
- 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 +20 -17
- data/lib/libpath/internal_/unix/form.rb +117 -112
- data/lib/libpath/internal_/windows/drive.rb +62 -59
- data/lib/libpath/internal_/windows/form.rb +193 -188
- 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 -23
- 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
@@ -5,277 +5,282 @@ require 'libpath/internal_/windows/drive'
|
|
5
5
|
module LibPath # :nodoc:
|
6
6
|
# @!visibility private
|
7
7
|
module Internal_ # :nodoc: all
|
8
|
+
# @!visibility private
|
8
9
|
module Windows # :nodoc:
|
9
10
|
|
11
|
+
# @!visibility private
|
10
12
|
module Form # :nodoc:
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
15
|
+
# time
|
16
|
+
#
|
17
|
+
# @!visibility private
|
18
|
+
def self.char_is_path_name_separator? c # :nodoc:
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
'/' == c || '\\' == c
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
24
|
+
# time
|
25
|
+
#
|
26
|
+
# @!visibility private
|
27
|
+
def self.append_trailing_slash s # :nodoc:
|
26
28
|
|
27
|
-
|
29
|
+
return s if self.char_is_path_name_separator?(s[-1])
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
s + '\\'
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
35
|
+
# time
|
36
|
+
#
|
37
|
+
# @!visibility private
|
38
|
+
def self.get_trailing_slash s # :nodoc:
|
37
39
|
|
38
|
-
|
40
|
+
last = s[-1]
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
self.char_is_path_name_separator?(last) ? last : nil
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
46
|
+
# time
|
47
|
+
#
|
48
|
+
# @!visibility private
|
49
|
+
def self.has_trailing_slash? s # :nodoc:
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
self.char_is_path_name_separator?(s[-1])
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
55
|
+
# time
|
56
|
+
#
|
57
|
+
# @!visibility private
|
58
|
+
def self.trim_trailing_slash s # :nodoc:
|
57
59
|
|
58
|
-
|
60
|
+
return s unless self.char_is_path_name_separator?(s[-1])
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
+
s.chop
|
63
|
+
end
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
66
|
+
# time
|
67
|
+
#
|
68
|
+
# @!visibility private
|
69
|
+
def self.elide_redundant_path_name_separators s # :nodoc:
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
+
s.gsub(/[\\\/]{2,}/, '\\')
|
72
|
+
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
75
|
+
# time
|
76
|
+
#
|
77
|
+
# @!visibility private
|
78
|
+
def self.elide_redundant_path_name_separators! s # :nodoc:
|
77
79
|
|
78
|
-
|
80
|
+
s.gsub!(/[\\\/]{2,}/, '\\')
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
+
s
|
83
|
+
end
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
85
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
86
|
+
# time
|
87
|
+
#
|
88
|
+
# === Signature
|
89
|
+
#
|
90
|
+
# * *Parameters:*
|
91
|
+
# - +s+ (String)
|
92
|
+
#
|
93
|
+
# === Return
|
94
|
+
# A 3-element array, consisting of [ volume, remainder, form ]
|
95
|
+
#
|
96
|
+
# @!visibility private
|
97
|
+
def self.get_windows_volume s # :nodoc:
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
99
|
+
# 0. not matched
|
100
|
+
# 1. X:
|
101
|
+
# 2. \\server\share
|
102
|
+
# 3. \\?\X:
|
103
|
+
# 4. \\?\server\share
|
104
|
+
# 5. \\?\UNC\server\share
|
105
|
+
# 6. \\.\device
|
104
106
|
|
105
|
-
|
107
|
+
if '\\' == s[0]
|
106
108
|
|
107
|
-
|
109
|
+
if '\\' == s[1]
|
108
110
|
|
109
|
-
|
110
|
-
|
111
|
+
case s[2]
|
112
|
+
when '?'
|
111
113
|
|
112
|
-
|
114
|
+
if '\\' == s[3]
|
113
115
|
|
114
|
-
|
116
|
+
if ':' == s[5] && ::LibPath::Internal_::Windows::Drive.character_is_drive_letter?(s[4])
|
115
117
|
|
116
|
-
|
118
|
+
# 3. \\?\X:
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
+
return [ s[0..5], s[6..-1], :form_3 ]
|
121
|
+
end
|
120
122
|
|
121
|
-
|
123
|
+
if 'U' == s[4] && 'N' == s[5] && 'C' == s[6]
|
122
124
|
|
123
|
-
|
125
|
+
# 5. \\?\UNC\server\share
|
124
126
|
|
125
|
-
|
127
|
+
if s =~ /^\\\\\?\\UNC\\[^\\]+\\[^\\\/]+/
|
126
128
|
|
127
|
-
|
128
|
-
|
129
|
-
|
129
|
+
return [ $&, $', :form_5 ]
|
130
|
+
end
|
131
|
+
else
|
130
132
|
|
131
|
-
|
133
|
+
if s =~ /^\\\\\?\\[^\\]+\\[^\\\/]+/
|
132
134
|
|
133
|
-
|
135
|
+
# 4. \\?\server\share
|
134
136
|
|
135
|
-
|
136
|
-
|
137
|
-
|
137
|
+
return [ $&, $', :form_4 ]
|
138
|
+
end
|
139
|
+
end
|
138
140
|
|
139
|
-
|
140
|
-
|
141
|
-
|
141
|
+
return [ s, '', :malformed ]
|
142
|
+
end
|
143
|
+
when '.'
|
142
144
|
|
143
|
-
|
145
|
+
if s =~ /^\\\\\.\\[^\\]+/
|
144
146
|
|
145
|
-
|
147
|
+
# 6. \\.\device
|
146
148
|
|
147
|
-
|
148
|
-
|
149
|
-
|
149
|
+
return [ $&, $', :form_6 ]
|
150
|
+
end
|
151
|
+
else
|
150
152
|
|
151
|
-
|
153
|
+
if s =~ /^\\\\[^\\]+\\[^\\\/]+/
|
152
154
|
|
153
|
-
|
155
|
+
# 2. \\server\share
|
154
156
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
157
|
+
return [ $&, $', :form_2 ]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
else
|
159
161
|
|
160
|
-
|
161
|
-
|
162
|
+
end
|
163
|
+
elsif ':' == s[1] && ::LibPath::Internal_::Windows::Drive.character_is_drive_letter?(s[0])
|
162
164
|
|
163
|
-
|
165
|
+
# 1. X:
|
164
166
|
|
165
|
-
|
166
|
-
|
167
|
+
return [ s[0..1], s[2..-1], :form_1 ]
|
168
|
+
end
|
167
169
|
|
168
|
-
|
170
|
+
# 0. not matched
|
169
171
|
|
170
|
-
|
171
|
-
|
172
|
+
[ nil, s, :form_0 ]
|
173
|
+
end
|
172
174
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
175
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
176
|
+
# time
|
177
|
+
#
|
178
|
+
# Returns tuple of:
|
179
|
+
#
|
180
|
+
# 0. source path (with redundant path name separators elided)
|
181
|
+
# 1. Windows volume (which is always nil)
|
182
|
+
# 2. Directory
|
183
|
+
# 3. Basename
|
184
|
+
# 4. Stem
|
185
|
+
# 5. Extension
|
186
|
+
# 6. Directory parts
|
187
|
+
# 7. Directory path parts
|
188
|
+
#
|
189
|
+
# @!visibility private
|
190
|
+
def self.split_path s # :nodoc:
|
189
191
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
192
|
+
f1_volume = nil
|
193
|
+
f2_directory = nil
|
194
|
+
f3_basename = nil
|
195
|
+
f4_stem = nil
|
196
|
+
f5_extension = nil
|
197
|
+
f6_dir_parts = []
|
198
|
+
f7_all_parts = []
|
197
199
|
|
198
|
-
|
200
|
+
f1_volume, rem, frm = self.get_windows_volume s
|
199
201
|
|
200
|
-
|
202
|
+
self.elide_redundant_path_name_separators! rem
|
201
203
|
|
202
|
-
|
204
|
+
f1_volume.define_singleton_method(:form) { frm } if f1_volume
|
203
205
|
|
204
|
-
|
206
|
+
if :malformed == frm
|
205
207
|
|
206
|
-
|
207
|
-
|
208
|
+
return [ s, f1_volume, nil, nil, nil, nil, [], [] ]
|
209
|
+
end
|
208
210
|
|
209
|
-
|
211
|
+
unless rem.empty?
|
210
212
|
|
211
|
-
|
213
|
+
ri_slash = ::LibPath::Internal_::String.rindex2(rem, '/', '\\')
|
212
214
|
|
213
|
-
|
215
|
+
if ri_slash
|
214
216
|
|
215
|
-
|
216
|
-
|
217
|
-
|
217
|
+
f2_directory = rem[0..ri_slash]
|
218
|
+
f3_basename = rem[(1 + ri_slash)..-1]
|
219
|
+
else
|
218
220
|
|
219
|
-
|
220
|
-
|
221
|
-
|
221
|
+
f2_directory = nil
|
222
|
+
f3_basename = rem
|
223
|
+
end
|
222
224
|
|
223
|
-
|
224
|
-
|
225
|
+
case f3_basename
|
226
|
+
when '.', '..'
|
225
227
|
|
226
|
-
|
227
|
-
|
228
|
-
|
228
|
+
f4_stem = f3_basename
|
229
|
+
f5_extension = nil
|
230
|
+
else
|
229
231
|
|
230
|
-
|
232
|
+
ri_dot = f3_basename.rindex('.')
|
231
233
|
|
232
|
-
|
234
|
+
if ri_dot
|
233
235
|
|
234
|
-
|
235
|
-
|
236
|
-
|
236
|
+
f4_stem = f3_basename[0...ri_dot]
|
237
|
+
f5_extension = f3_basename[ri_dot..-1]
|
238
|
+
else
|
237
239
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
240
|
+
f4_stem = f3_basename
|
241
|
+
f5_extension = nil
|
242
|
+
end
|
243
|
+
end
|
242
244
|
|
243
|
-
|
244
|
-
|
245
|
+
case f2_directory
|
246
|
+
when nil
|
245
247
|
|
246
|
-
|
247
|
-
|
248
|
+
;
|
249
|
+
when '\\', '/'
|
248
250
|
|
249
|
-
|
250
|
-
|
251
|
+
f6_dir_parts = [ f2_directory ]
|
252
|
+
else
|
251
253
|
|
252
|
-
|
254
|
+
parts = f2_directory.split(/([\\\/])/)
|
253
255
|
|
254
|
-
|
256
|
+
f6_dir_parts = []
|
255
257
|
|
256
|
-
|
258
|
+
(0...(parts.size / 2)).each do |ix|
|
257
259
|
|
258
|
-
|
259
|
-
|
260
|
-
|
260
|
+
f6_dir_parts << parts[2 * ix + 0] + parts[2 * ix + 1]
|
261
|
+
end
|
262
|
+
end
|
261
263
|
|
262
|
-
|
264
|
+
if f1_volume
|
263
265
|
|
264
|
-
|
266
|
+
f7_all_parts = f6_dir_parts.dup
|
265
267
|
|
266
|
-
|
267
|
-
|
268
|
+
f7_all_parts[0] = f1_volume + f7_all_parts[0].to_s
|
269
|
+
else
|
268
270
|
|
269
|
-
|
270
|
-
|
271
|
-
|
271
|
+
f7_all_parts = f6_dir_parts
|
272
|
+
end
|
273
|
+
end
|
272
274
|
|
273
275
|
|
274
|
-
|
275
|
-
|
276
|
+
[ "#{f1_volume}#{rem}", f1_volume, f2_directory, f3_basename, f4_stem, f5_extension, f6_dir_parts, f7_all_parts ].map { |v| ::String === v && v.empty? ? nil : v }
|
277
|
+
end
|
276
278
|
end # module Form
|
277
279
|
|
278
280
|
end # module Windows
|
279
281
|
end # module Internal_
|
280
282
|
end # module LibPath
|
281
283
|
|
284
|
+
|
285
|
+
# ############################## end of file ############################# #
|
286
|
+
|