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