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