libpath-ruby 0.2.2.1 → 0.2.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@
5
5
  # Purpose: LibPath::Form::Windows module
6
6
  #
7
7
  # Created: 8th January 2019
8
- # Updated: 6th April 2024
8
+ # Updated: 13th April 2024
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/libpath.Ruby
11
11
  #
@@ -45,310 +45,323 @@
45
45
  # ######################################################################## #
46
46
 
47
47
 
48
- =begin
49
- =end
50
-
51
48
  require 'libpath/constants/windows'
52
49
  require 'libpath/diagnostics'
53
50
  require 'libpath/internal_/windows/drive'
54
51
  require 'libpath/internal_/windows/form'
55
52
 
56
53
 
57
- module LibPath # :nodoc:
58
- module Form # :nodoc:
59
- module Windows # :nodoc:
54
+ =begin
55
+ =end
60
56
 
61
- # Module defining instance functions that will be included and extended into
62
- # any class or module including/extending module LibPath::Form::Windows
63
- module LibPath_Form_Windows_Methods
57
+ module LibPath
58
+ module Form
59
+ module Windows
64
60
 
65
- # Classifies a path
66
- #
67
- # === Return
68
- #
69
- # One of +:absolute+, +:drived+, +:homed+, +:relative+, +:rooted+, for
70
- # any paths that match precisely those classifications, or +nil+ if the
71
- # path is empty
72
- def classify_path path
61
+ # Module defining instance functions that will be included and extended into
62
+ # any class or module including/extending module LibPath::Form::Windows
63
+ module LibPath_Form_Windows_Methods
73
64
 
74
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
65
+ # Classifies a path
66
+ #
67
+ # === Return
68
+ #
69
+ # One of +:absolute+, +:drived+, +:homed+, +:relative+, +:rooted+, for
70
+ # any paths that match precisely those classifications, or +nil+ if the
71
+ # path is empty
72
+ def classify_path path
75
73
 
76
- return nil if path.nil? || path.empty?
74
+ _Form = Internal_::Windows::Form
77
75
 
78
- return :homed if path_is_homed? path
76
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
79
77
 
80
- vol, rem, _ = Internal_::Windows::Form.get_windows_volume(path)
78
+ return nil if path.nil? || path.empty?
81
79
 
82
- rooted = Internal_::Windows::Form.char_is_path_name_separator? rem[0]
80
+ return :homed if path_is_homed? path
83
81
 
84
- if rooted
82
+ vol, rem, _ = _Form.get_windows_volume(path)
85
83
 
86
- if vol
84
+ rooted = _Form.char_is_path_name_separator? rem[0]
87
85
 
88
- return :absolute
89
- else
86
+ if rooted
90
87
 
91
- return :rooted
92
- end
93
- else
88
+ if vol
94
89
 
95
- if vol
90
+ return :absolute
91
+ else
96
92
 
97
- return :drived
93
+ return :rooted
94
+ end
98
95
  else
99
96
 
100
- return :relative
97
+ if vol
98
+
99
+ return :drived
100
+ else
101
+
102
+ return :relative
103
+ end
101
104
  end
105
+
102
106
  end
103
107
 
104
- end
108
+ # Evaluates whether the given name is malformed, according to the given
109
+ # options.
110
+ #
111
+ # If no options are specified, the only invalid character(s) are: +'\0'+
112
+ #
113
+ # === Signature
114
+ #
115
+ # * *Options:*
116
+ # - +:reject_path_name_separators+:: (boolean) Reject the path
117
+ # separator character(s): +'\\'+ and +'/'+
118
+ # - +:reject_path_separators+:: (boolean) Reject the path separator
119
+ # character(s): +';'+
120
+ # - +:reject_shell_characters+:: (boolean) Reject the shell
121
+ # character(s): +'*'+, +'?'+, +'|'+
122
+ def name_is_malformed? name, **options
123
+
124
+ _Constants = ::LibPath::Constants::Windows
125
+
126
+ if name
127
+
128
+ if options[:reject_shell_characters]
129
+
130
+ return true if name =~ _Constants::InvalidCharacters::Shell::RE
131
+ end
105
132
 
106
- # Evaluates whether the given name is malformed, according to the given
107
- # options.
108
- #
109
- # If no options are specified, the only invalid character(s) are: +'\0'+
110
- #
111
- # === Signature
112
- #
113
- # * *Options:*
114
- # - +:reject_path_name_separators+:: (boolean) Reject the path
115
- # separator character(s): +'\\'+ and +'/'+
116
- # - +:reject_path_separators+:: (boolean) Reject the path separator
117
- # character(s): +';'+
118
- # - +:reject_shell_characters+:: (boolean) Reject the shell
119
- # character(s): +'*'+, +'?'+, +'|'+
120
- def name_is_malformed? name, **options
121
-
122
- _Constants = ::LibPath::Constants::Windows
123
-
124
- if name
125
-
126
- if options[:reject_shell_characters]
127
-
128
- return true if name =~ _Constants::InvalidCharacters::Shell::RE
129
- end
133
+ if options[:reject_path_separators]
130
134
 
131
- if options[:reject_path_separators]
135
+ return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
136
+ end
132
137
 
133
- return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
134
- end
138
+ if options[:reject_path_name_separators]
135
139
 
136
- if options[:reject_path_name_separators]
140
+ return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
141
+ end
137
142
 
138
- return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
139
- end
143
+ return true if name =~ _Constants::InvalidCharacters::Innate::RE
140
144
 
141
- return true if name =~ _Constants::InvalidCharacters::Innate::RE
145
+ if '\\' == name[0] && '\\' == name[1]
142
146
 
143
- if '\\' == name[0] && '\\' == name[1]
147
+ return true if name !~ /^\\\\[^\\]+\\[^\\]+/
148
+ end
149
+
150
+ false
151
+ else
144
152
 
145
- return true if name !~ /^\\\\[^\\]+\\[^\\]+/
153
+ true
146
154
  end
155
+ end
147
156
 
148
- false
149
- else
157
+ # Evaluates whether the given path is absolute, which means it is either
158
+ # rooted (begins with '/') or is homed (is '~' or begins with '~/')
159
+ #
160
+ # === Signature
161
+ #
162
+ # * *Parameters:*
163
+ # - +path+:: (String) The path to be evaluated. May not be +nil+
164
+ def path_is_absolute? path
150
165
 
151
- true
152
- end
153
- end
166
+ _Form = Internal_::Windows::Form
154
167
 
155
- # Evaluates whether the given path is absolute, which means it is either
156
- # rooted (begins with '/') or is homed (is '~' or begins with '~/')
157
- #
158
- # === Signature
159
- #
160
- # * *Parameters:*
161
- # - +path+:: (String) The path to be evaluated. May not be +nil+
162
- def path_is_absolute? path
168
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
163
169
 
164
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
170
+ return true if path_is_homed? path
165
171
 
166
- return true if path_is_homed? path
172
+ vol, rem, _ = _Form.get_windows_volume(path)
167
173
 
168
- vol, rem, _ = Internal_::Windows::Form.get_windows_volume(path)
174
+ return false unless vol
175
+ return false unless rem
169
176
 
170
- return false unless vol
171
- return false unless rem
177
+ _Form.char_is_path_name_separator? rem[0]
178
+ end
172
179
 
173
- Internal_::Windows::Form.char_is_path_name_separator? rem[0]
174
- end
180
+ # Evaluates whether the given path is "letter drived", which means that
181
+ # it contains a drive specification. Given the two letter sequence 'X:'
182
+ # representing any ASCII letter (a-zA-Z) and a colon, this function
183
+ # recognises six sequences: +'X:'+, +'X:\'+, +'X:/'+, +'\\?\X:'+,
184
+ # +'\\?\X:\'+, +'\\?\X:/'+
185
+ #
186
+ # === Return
187
+ # - +nil+:: if it is not "drived";
188
+ # - 2:: it begins with the form +'X:'+
189
+ # - 3:: it begins with the form +'X:\'+ or +'X:/'+
190
+ # - 6:: it begins with the form +'\\?\X:'+
191
+ # - 7:: it begins with the form +'\\?\X:\'+ or +'\\?\X:/'+
192
+ def path_is_letter_drived? path
175
193
 
176
- # Evaluates whether the given path is "letter drived", which means that
177
- # it contains a drive specification. Given the two letter sequence 'X:'
178
- # representing any ASCII letter (a-zA-Z) and a colon, this function
179
- # recognises six sequences: +'X:'+, +'X:\'+, +'X:/'+, +'\\?\X:'+,
180
- # +'\\?\X:\'+, +'\\?\X:/'+
181
- #
182
- # === Return
183
- # - +nil+:: if it is not "drived";
184
- # - 2:: it begins with the form +'X:'+
185
- # - 3:: it begins with the form +'X:\'+ or +'X:/'+
186
- # - 6:: it begins with the form +'\\?\X:'+
187
- # - 7:: it begins with the form +'\\?\X:\'+ or +'\\?\X:/'+
188
- def path_is_letter_drived? path
194
+ _Drive = Internal_::Windows::Drive
195
+ _Form = Internal_::Windows::Form
189
196
 
190
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
197
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
191
198
 
192
- if path.size >= 2
199
+ if path.size >= 2
193
200
 
194
- base_index = 0
201
+ base_index = 0
195
202
 
196
- if '\\' == path[0]
203
+ if '\\' == path[0]
197
204
 
198
- if '\\' == path[1]
205
+ if '\\' == path[1]
199
206
 
200
- if '?' == path[2]
207
+ if '?' == path[2]
201
208
 
202
- if '\\' == path[3]
209
+ if '\\' == path[3]
203
210
 
204
- base_index = 4
211
+ base_index = 4
212
+ end
205
213
  end
206
214
  end
207
215
  end
208
- end
209
216
 
210
- if ':' == path[base_index + 1]
217
+ if ':' == path[base_index + 1]
211
218
 
212
- if Internal_::Windows::Drive.character_is_drive_letter? path[base_index + 0]
219
+ if _Drive.character_is_drive_letter? path[base_index + 0]
213
220
 
214
- if Internal_::Windows::Form.char_is_path_name_separator? path[base_index + 2]
221
+ if _Form.char_is_path_name_separator? path[base_index + 2]
215
222
 
216
- return 4 == base_index ? 7 : 3
217
- else
223
+ return 4 == base_index ? 7 : 3
224
+ else
218
225
 
219
- return 4 == base_index ? 6 : 2
226
+ return 4 == base_index ? 6 : 2
227
+ end
220
228
  end
221
229
  end
222
230
  end
231
+
232
+ nil
223
233
  end
224
234
 
225
- nil
226
- end
235
+ # Evaluates whether the given path is homed, which means it is '~' or
236
+ # begins with '~/' or '~\'
237
+ #
238
+ # === Signature
239
+ #
240
+ # * *Parameters:*
241
+ # - +path+:: (String) The path to be evaluated. May not be +nil+
242
+ def path_is_homed? path
227
243
 
228
- # Evaluates whether the given path is homed, which means it is '~' or
229
- # begins with '~/' or '~\'
230
- #
231
- # === Signature
232
- #
233
- # * *Parameters:*
234
- # - +path+:: (String) The path to be evaluated. May not be +nil+
235
- def path_is_homed? path
244
+ _Form = Internal_::Windows::Form
236
245
 
237
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
246
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
238
247
 
239
- return false unless '~' == path[0]
248
+ return false unless '~' == path[0]
240
249
 
241
- if path.size > 1
250
+ if path.size > 1
242
251
 
243
- return Internal_::Windows::Form.char_is_path_name_separator? path[1]
244
- end
252
+ return _Form.char_is_path_name_separator? path[1]
253
+ end
245
254
 
246
- true
247
- end
255
+ true
256
+ end
248
257
 
249
- # Evalutes whether the given path is rooted, which means it begins with
250
- # '/'
251
- #
252
- # === Signature
253
- #
254
- # * *Parameters:*
255
- # - +path+:: (String) The path to be evaluated. May not be +nil+
256
- def path_is_rooted? path
258
+ # Evalutes whether the given path is rooted, which means it begins with
259
+ # '/'
260
+ #
261
+ # === Signature
262
+ #
263
+ # * *Parameters:*
264
+ # - +path+:: (String) The path to be evaluated. May not be +nil+
265
+ def path_is_rooted? path
257
266
 
258
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
267
+ _Drive = Internal_::Windows::Drive
268
+ _Form = Internal_::Windows::Form
259
269
 
260
- case path[0]
261
- when '/'
270
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
262
271
 
263
- true
264
- when '\\'
272
+ case path[0]
273
+ when '/'
265
274
 
266
- case path[1]
275
+ true
267
276
  when '\\'
268
277
 
269
- vol, rem, _ = Internal_::Windows::Form.get_windows_volume(path)
278
+ case path[1]
279
+ when '\\'
270
280
 
271
- return false unless vol
281
+ vol, rem, _ = _Form.get_windows_volume(path)
272
282
 
273
- if rem && Internal_::Windows::Form.char_is_path_name_separator?(rem[0])
283
+ return false unless vol
274
284
 
275
- true
285
+ if rem && _Form.char_is_path_name_separator?(rem[0])
286
+
287
+ true
288
+ else
289
+
290
+ false
291
+ end
276
292
  else
277
293
 
278
- false
294
+ true
279
295
  end
280
296
  else
281
297
 
282
- true
283
- end
284
- else
298
+ if path.size > 2
285
299
 
286
- if path.size > 2
300
+ if ':' == path[1]
287
301
 
288
- if ':' == path[1]
302
+ if _Drive.character_is_drive_letter? path[0]
289
303
 
290
- if Internal_::Windows::Drive.character_is_drive_letter? path[0]
291
-
292
- return Internal_::Windows::Form.char_is_path_name_separator? path[2]
304
+ return _Form.char_is_path_name_separator? path[2]
305
+ end
293
306
  end
294
307
  end
295
- end
296
308
 
297
- false
309
+ false
310
+ end
298
311
  end
299
- end
300
312
 
301
- # Evalutes whether the given path is UNC
302
- #
303
- # === Signature
304
- #
305
- # * *Parameters:*
306
- # - +path+:: (String) The path to be evaluated. May not be +nil+
307
- def path_is_UNC? path
313
+ # Evalutes whether the given path is UNC
314
+ #
315
+ # === Signature
316
+ #
317
+ # * *Parameters:*
318
+ # - +path+:: (String) The path to be evaluated. May not be +nil+
319
+ def path_is_UNC? path
308
320
 
309
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
321
+ _Form = Internal_::Windows::Form
310
322
 
311
- return false unless '\\' == path[0]
312
- return false unless '\\' == path[1]
323
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
313
324
 
314
- _, _, frm = Internal_::Windows::Form.get_windows_volume(path)
325
+ return false unless '\\' == path[0]
326
+ return false unless '\\' == path[1]
315
327
 
316
- case frm
317
- when :form_2, :form_3, :form_4, :form_5, :form_6
328
+ _, _, frm = _Form.get_windows_volume(path)
318
329
 
319
- true
320
- else
330
+ case frm
331
+ when :form_2, :form_3, :form_4, :form_5, :form_6
321
332
 
322
- false
333
+ true
334
+ else
335
+
336
+ false
337
+ end
323
338
  end
324
- end
339
+ end # module LibPath_Form_Windows_Methods
325
340
 
326
- end # module LibPath_Form_Windows_Methods
341
+ # @!visibility private
342
+ def self.extended receiver # :nodoc:
327
343
 
328
- # @!visibility private
329
- def self.extended receiver # :nodoc:
344
+ receiver.class_eval do
330
345
 
331
- receiver.class_eval do
346
+ extend LibPath_Form_Windows_Methods
347
+ end
332
348
 
333
- extend LibPath_Form_Windows_Methods
349
+ $stderr.puts "#{receiver} extended by #{LibPath_Form_Windows_Methods}" if $DEBUG
334
350
  end
335
351
 
336
- $stderr.puts "#{receiver} extended by #{LibPath_Form_Windows_Methods}" if $DEBUG
337
- end
352
+ # @!visibility private
353
+ def self.included receiver # :nodoc:
338
354
 
339
- # @!visibility private
340
- def self.included receiver # :nodoc:
355
+ receiver.class_eval do
341
356
 
342
- receiver.class_eval do
357
+ include LibPath_Form_Windows_Methods
358
+ end
343
359
 
344
- include LibPath_Form_Windows_Methods
360
+ $stderr.puts "#{receiver} included #{LibPath_Form_Windows_Methods}" if $DEBUG
345
361
  end
346
362
 
347
- $stderr.puts "#{receiver} included #{LibPath_Form_Windows_Methods}" if $DEBUG
348
- end
349
-
350
- extend LibPath_Form_Windows_Methods
351
- include LibPath_Form_Windows_Methods
363
+ extend LibPath_Form_Windows_Methods
364
+ include LibPath_Form_Windows_Methods
352
365
 
353
366
  end # module Windows
354
367
  end # module Form
data/lib/libpath/form.rb CHANGED
@@ -9,8 +9,8 @@ else
9
9
  require 'libpath/form/unix'
10
10
  end
11
11
 
12
- module LibPath # :nodoc:
13
- module Form # :nodoc:
12
+ module LibPath
13
+ module Form
14
14
 
15
15
  if ::LibPath::Internal_::Platform::Constants::PLATFORM_IS_WINDOWS then
16
16
 
@@ -33,7 +33,6 @@ module Form # :nodoc:
33
33
 
34
34
  $stderr.puts "#{receiver} included #{self}" if $DEBUG
35
35
  end
36
-
37
36
  end # module Form
38
37
  end # module LibPath
39
38
 
@@ -1,94 +1,94 @@
1
1
 
2
2
  # :stopdoc:
3
3
 
4
- module LibPath # :nodoc:
5
- # @!visibility private
6
- module Internal_ # :nodoc: all
7
4
 
5
+ module LibPath
8
6
  # @!visibility private
9
- module Array # :nodoc:
7
+ module Internal_ # :nodoc: all
10
8
 
11
9
  # @!visibility private
12
- def self.index(ar, v, after = nil) # :nodoc:
10
+ module Array # :nodoc:
13
11
 
14
- if after
12
+ # @!visibility private
13
+ def self.index(ar, v, after = nil) # :nodoc:
15
14
 
16
- if after < 0
15
+ if after
17
16
 
18
- after = ar.size + after
17
+ if after < 0
19
18
 
20
- return nil if after < 0
21
- else
19
+ after = ar.size + after
22
20
 
23
- return nil unless after < ar.size
24
- end
21
+ return nil if after < 0
22
+ else
25
23
 
26
- ar.each_with_index do |el, ix|
24
+ return nil unless after < ar.size
25
+ end
27
26
 
28
- if ix >= after
27
+ ar.each_with_index do |el, ix|
29
28
 
30
- if v == el
29
+ if ix >= after
31
30
 
32
- return ix
31
+ if v == el
32
+
33
+ return ix
34
+ end
33
35
  end
34
36
  end
35
- end
36
37
 
37
- nil
38
- else
38
+ nil
39
+ else
39
40
 
40
- ar.index(v)
41
+ ar.index(v)
42
+ end
41
43
  end
42
- end
43
44
 
44
- # @!visibility private
45
- def self.index2(ar, v1, v2, after = nil) # :nodoc:
45
+ # @!visibility private
46
+ def self.index2(ar, v1, v2, after = nil) # :nodoc:
46
47
 
47
- i_1 = self.index(ar, v1, after)
48
- i_2 = self.index(ar, v2, after)
48
+ i_1 = self.index(ar, v1, after)
49
+ i_2 = self.index(ar, v2, after)
49
50
 
50
- if i_1
51
+ if i_1
51
52
 
52
- if i_2
53
+ if i_2
53
54
 
54
- i_1 < i_2 ? i_1 : i_2
55
+ i_1 < i_2 ? i_1 : i_2
56
+ else
57
+
58
+ i_1
59
+ end
55
60
  else
56
61
 
57
- i_1
62
+ i_2
58
63
  end
59
- else
60
-
61
- i_2
62
64
  end
63
- end
64
65
 
65
66
 
66
- # @!visibility private
67
- def self.rindex2(ar, v1, v2) # :nodoc:
67
+ # @!visibility private
68
+ def self.rindex2(ar, v1, v2) # :nodoc:
69
+
70
+ i_1 = ar.rindex(v1)
71
+ i_2 = ar.rindex(v2)
68
72
 
69
- i_1 = ar.rindex(v1)
70
- i_2 = ar.rindex(v2)
73
+ if i_1
71
74
 
72
- if i_1
75
+ if i_2
73
76
 
74
- if i_2
77
+ i_1 < i_2 ? i_2 : i_1
78
+ else
75
79
 
76
- i_1 < i_2 ? i_2 : i_1
80
+ i_1
81
+ end
77
82
  else
78
83
 
79
- i_1
84
+ i_2
80
85
  end
81
- else
82
-
83
- i_2
84
86
  end
85
- end
86
-
87
- end # module Array
88
-
87
+ end # module Array
89
88
  end # module Internal_
90
89
  end # module LibPath
91
90
 
91
+
92
92
  # :startdoc:
93
93
 
94
94