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.
@@ -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
- module LibPath # :nodoc:
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
- def self.char_is_path_name_separator? c # :nodoc:
16
+ module Form # :nodoc:
19
17
 
20
- '/' == c || '\\' == c
21
- end
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
- # [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:
24
+ '/' == c || '\\' == c
25
+ end
28
26
 
29
- return s if self.char_is_path_name_separator?(s[-1])
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
- s + '\\'
32
- end
33
+ return s if self.char_is_path_name_separator?(s[-1])
33
34
 
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:
35
+ s + '\\'
36
+ end
39
37
 
40
- last = s[-1]
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
- self.char_is_path_name_separator?(last) ? last : nil
43
- end
44
+ last = s[-1]
44
45
 
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:
46
+ self.char_is_path_name_separator?(last) ? last : nil
47
+ end
50
48
 
51
- self.char_is_path_name_separator?(s[-1])
52
- end
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
- # [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:
55
+ self.char_is_path_name_separator?(s[-1])
56
+ end
59
57
 
60
- return s unless self.char_is_path_name_separator?(s[-1])
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
- s.chop
63
- end
64
+ return s unless self.char_is_path_name_separator?(s[-1])
64
65
 
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:
66
+ s.chop
67
+ end
70
68
 
71
- s.gsub(/[\\\/]{2,}/, '\\')
72
- end
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
- # [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
-
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
- if '\\' == s[0]
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
- if '\\' == s[1]
84
+ s.gsub!(/[\\\/]{2,}/, '\\')
110
85
 
111
- case s[2]
112
- when '?'
86
+ s
87
+ end
113
88
 
114
- if '\\' == s[3]
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
- if ':' == s[5] && ::LibPath::Internal_::Windows::Drive.character_is_drive_letter?(s[4])
114
+ if '\\' == s[0]
117
115
 
118
- # 3. \\?\X:
116
+ if '\\' == s[1]
119
117
 
120
- return [ s[0..5], s[6..-1], :form_3 ]
121
- end
118
+ case s[2]
119
+ when '?'
122
120
 
123
- if 'U' == s[4] && 'N' == s[5] && 'C' == s[6]
121
+ if '\\' == s[3]
124
122
 
125
- # 5. \\?\UNC\server\share
123
+ if ':' == s[5] && _Drive.character_is_drive_letter?(s[4])
126
124
 
127
- if s =~ /^\\\\\?\\UNC\\[^\\]+\\[^\\\/]+/
125
+ # 3. \\?\X:
128
126
 
129
- return [ $&, $', :form_5 ]
127
+ return [ s[0..5], s[6..-1], :form_3 ]
130
128
  end
131
- else
132
-
133
- if s =~ /^\\\\\?\\[^\\]+\\[^\\\/]+/
134
129
 
135
- # 4. \\?\server\share
136
-
137
- return [ $&, $', :form_4 ]
138
- end
139
- end
130
+ if 'U' == s[4] && 'N' == s[5] && 'C' == s[6]
140
131
 
141
- return [ s, '', :malformed ]
142
- end
143
- when '.'
132
+ # 5. \\?\UNC\server\share
144
133
 
145
- if s =~ /^\\\\\.\\[^\\]+/
134
+ if s =~ /^\\\\\?\\UNC\\[^\\]+\\[^\\\/]+/
146
135
 
147
- # 6. \\.\device
136
+ return [ $&, $', :form_5 ]
137
+ end
138
+ else
148
139
 
149
- return [ $&, $', :form_6 ]
150
- end
151
- else
140
+ if s =~ /^\\\\\?\\[^\\]+\\[^\\\/]+/
152
141
 
153
- if s =~ /^\\\\[^\\]+\\[^\\\/]+/
142
+ # 4. \\?\server\share
154
143
 
155
- # 2. \\server\share
144
+ return [ $&, $', :form_4 ]
145
+ end
146
+ end
156
147
 
157
- return [ $&, $', :form_2 ]
148
+ return [ s, '', :malformed ]
158
149
  end
159
- end
160
- else
150
+ when '.'
161
151
 
162
- end
163
- elsif ':' == s[1] && ::LibPath::Internal_::Windows::Drive.character_is_drive_letter?(s[0])
152
+ if s =~ /^\\\\\.\\[^\\]+/
164
153
 
165
- # 1. X:
154
+ # 6. \\.\device
166
155
 
167
- return [ s[0..1], s[2..-1], :form_1 ]
168
- end
156
+ return [ $&, $', :form_6 ]
157
+ end
158
+ else
169
159
 
170
- # 0. not matched
171
-
172
- [ nil, s, :form_0 ]
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
- 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 = []
164
+ return [ $&, $', :form_2 ]
165
+ end
166
+ end
167
+ else
199
168
 
200
- f1_volume, rem, frm = self.get_windows_volume s
169
+ end
170
+ elsif ':' == s[1] && _Drive.character_is_drive_letter?(s[0])
201
171
 
202
- self.elide_redundant_path_name_separators! rem
172
+ # 1. X:
203
173
 
204
- f1_volume.define_singleton_method(:form) { frm } if f1_volume
174
+ return [ s[0..1], s[2..-1], :form_1 ]
175
+ end
205
176
 
206
- if :malformed == frm
177
+ # 0. not matched
207
178
 
208
- return [ s, f1_volume, nil, nil, nil, nil, [], [] ]
179
+ [ nil, s, :form_0 ]
209
180
  end
210
181
 
211
- unless rem.empty?
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
- ri_slash = ::LibPath::Internal_::String.rindex2(rem, '/', '\\')
220
+ unless rem.empty?
214
221
 
215
- if ri_slash
222
+ ri_slash = _String.rindex2(rem, '/', '\\')
216
223
 
217
- f2_directory = rem[0..ri_slash]
218
- f3_basename = rem[(1 + ri_slash)..-1]
219
- else
224
+ if ri_slash
220
225
 
221
- f2_directory = nil
222
- f3_basename = rem
223
- end
226
+ f2_directory = rem[0..ri_slash]
227
+ f3_basename = rem[(1 + ri_slash)..-1]
228
+ else
224
229
 
225
- case f3_basename
226
- when '.', '..'
230
+ f2_directory = nil
231
+ f3_basename = rem
232
+ end
233
+
234
+ case f3_basename
235
+ when '.', '..'
227
236
 
228
- f4_stem = f3_basename
229
- f5_extension = nil
230
- else
237
+ f4_stem = f3_basename
238
+ f5_extension = nil
239
+ else
231
240
 
232
- ri_dot = f3_basename.rindex('.')
241
+ ri_dot = f3_basename.rindex('.')
233
242
 
234
- if ri_dot
243
+ if ri_dot
235
244
 
236
- f4_stem = f3_basename[0...ri_dot]
237
- f5_extension = f3_basename[ri_dot..-1]
238
- else
245
+ f4_stem = f3_basename[0...ri_dot]
246
+ f5_extension = f3_basename[ri_dot..-1]
247
+ else
239
248
 
240
- f4_stem = f3_basename
241
- f5_extension = nil
249
+ f4_stem = f3_basename
250
+ f5_extension = nil
251
+ end
242
252
  end
243
- end
244
253
 
245
- case f2_directory
246
- when nil
254
+ case f2_directory
255
+ when nil
247
256
 
248
- ;
249
- when '\\', '/'
257
+ ;
258
+ when '\\', '/'
250
259
 
251
- f6_dir_parts = [ f2_directory ]
252
- else
260
+ f6_dir_parts = [ f2_directory ]
261
+ else
253
262
 
254
- parts = f2_directory.split(/([\\\/])/)
263
+ parts = f2_directory.split(/([\\\/])/)
255
264
 
256
- f6_dir_parts = []
265
+ f6_dir_parts = []
257
266
 
258
- (0...(parts.size / 2)).each do |ix|
267
+ (0...(parts.size / 2)).each do |ix|
259
268
 
260
- f6_dir_parts << parts[2 * ix + 0] + parts[2 * ix + 1]
269
+ f6_dir_parts << parts[2 * ix + 0] + parts[2 * ix + 1]
270
+ end
261
271
  end
262
- end
263
272
 
264
- if f1_volume
273
+ if f1_volume
265
274
 
266
- f7_all_parts = f6_dir_parts.dup
275
+ f7_all_parts = f6_dir_parts.dup
267
276
 
268
- f7_all_parts[0] = f1_volume + f7_all_parts[0].to_s
269
- else
277
+ f7_all_parts[0] = f1_volume + f7_all_parts[0].to_s
278
+ else
270
279
 
271
- f7_all_parts = f6_dir_parts
280
+ f7_all_parts = f6_dir_parts
281
+ end
272
282
  end
273
- end
274
283
 
275
284
 
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
- 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
 
@@ -1,5 +1,5 @@
1
1
 
2
- # Top-level module for the *libpath.Ruby*
2
+ # Top-level module for the *libpath.Ruby* library
3
3
  module LibPath
4
4
 
5
5
  end # module LibPath