libpath-ruby 0.2.2 → 0.2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +33 -0
  3. data/README.md +25 -8
  4. data/examples/path_from_arg0.md +43 -43
  5. data/examples/path_from_arg0.rb +25 -23
  6. data/lib/libpath/constants/unix.rb +74 -74
  7. data/lib/libpath/constants/windows.rb +75 -75
  8. data/lib/libpath/constants.rb +20 -20
  9. data/lib/libpath/diagnostics/parameter_checking.rb +27 -26
  10. data/lib/libpath/diagnostics.rb +1 -1
  11. data/lib/libpath/exceptions/libpath_base_exception.rb +20 -21
  12. data/lib/libpath/exceptions/malformed_name_exception.rb +27 -27
  13. data/lib/libpath/exceptions.rb +1 -1
  14. data/lib/libpath/form/unix.rb +118 -118
  15. data/lib/libpath/form/windows.rb +228 -214
  16. data/lib/libpath/form.rb +20 -21
  17. data/lib/libpath/internal_/array.rb +57 -57
  18. data/lib/libpath/internal_/platform.rb +30 -31
  19. data/lib/libpath/internal_/string.rb +25 -20
  20. data/lib/libpath/internal_/unix/form.rb +124 -119
  21. data/lib/libpath/internal_/windows/drive.rb +80 -75
  22. data/lib/libpath/internal_/windows/form.rb +205 -194
  23. data/lib/libpath/libpath.rb +4 -1
  24. data/lib/libpath/path/unix.rb +120 -118
  25. data/lib/libpath/path/windows.rb +126 -124
  26. data/lib/libpath/path.rb +21 -21
  27. data/lib/libpath/util/unix.rb +261 -261
  28. data/lib/libpath/util/windows.rb +403 -403
  29. data/lib/libpath/util.rb +20 -20
  30. data/lib/libpath/version.rb +25 -26
  31. data/lib/libpath.rb +1 -1
  32. data/test/performance/benchmark_drive_letter.rb +50 -10
  33. data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
  34. data/test/performance/benchmark_rindex2.rb +56 -48
  35. data/test/performance/benchmark_split.rb +16 -10
  36. data/test/unit/compare/ts_all.rb +4 -4
  37. data/test/unit/equate/ts_all.rb +4 -4
  38. data/test/unit/equate/unix/ts_all.rb +4 -4
  39. data/test/unit/equate/windows/ts_all.rb +4 -4
  40. data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
  41. data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
  42. data/test/unit/exceptions/ts_all.rb +4 -4
  43. data/test/unit/form/tc_absolute_functions.rb +242 -240
  44. data/test/unit/form/ts_all.rb +4 -4
  45. data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
  46. data/test/unit/form/unix/ts_all.rb +4 -4
  47. data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
  48. data/test/unit/form/windows/ts_all.rb +4 -4
  49. data/test/unit/internal_/tc_array.rb +36 -32
  50. data/test/unit/internal_/ts_all.rb +4 -4
  51. data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
  52. data/test/unit/internal_/unix/form/ts_all.rb +4 -4
  53. data/test/unit/internal_/unix/tc_split_path.rb +387 -384
  54. data/test/unit/internal_/unix/ts_all.rb +4 -4
  55. data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
  56. data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
  57. data/test/unit/internal_/windows/form/ts_all.rb +4 -4
  58. data/test/unit/internal_/windows/tc_split_path.rb +874 -869
  59. data/test/unit/internal_/windows/ts_all.rb +4 -4
  60. data/test/unit/parse/ts_all.rb +4 -4
  61. data/test/unit/path/tc_path.rb +732 -732
  62. data/test/unit/path/ts_all.rb +4 -4
  63. data/test/unit/path/unix/tc_path.rb +544 -540
  64. data/test/unit/path/unix/ts_all.rb +4 -4
  65. data/test/unit/path/windows/tc_path.rb +608 -603
  66. data/test/unit/path/windows/ts_all.rb +4 -4
  67. data/test/unit/tc_version.rb +25 -22
  68. data/test/unit/ts_all.rb +4 -4
  69. data/test/unit/util/tc_combine_paths.rb +110 -105
  70. data/test/unit/util/tc_derive_relative_path.rb +8 -3
  71. data/test/unit/util/tc_make_path_canonical.rb +142 -138
  72. data/test/unit/util/ts_all.rb +4 -4
  73. data/test/unit/util/unix/tc_combine_paths.rb +38 -34
  74. data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
  75. data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
  76. data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
  77. data/test/unit/util/unix/ts_all.rb +4 -4
  78. data/test/unit/util/windows/tc_combine_paths.rb +82 -77
  79. data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
  80. data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
  81. data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
  82. data/test/unit/util/windows/ts_all.rb +4 -4
  83. metadata +9 -8
@@ -1,16 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: libpath/util/unix.rb
3
+ # File: libpath/util/unix.rb
4
4
  #
5
- # Purpose: LibPath::Util::Unix module
5
+ # Purpose: LibPath::Util::Unix module
6
6
  #
7
- # Created: 14th January 2019
8
- # Updated: 16th April 2019
7
+ # Created: 14th January 2019
8
+ # Updated: 7th April 2024
9
9
  #
10
- # Home: http://github.com/synesissoftware/libpath.Ruby
10
+ # Home: http://github.com/synesissoftware/libpath.Ruby
11
11
  #
12
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
13
13
  #
14
+ # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
14
15
  # Copyright (c) 2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
@@ -44,371 +45,370 @@
44
45
  # ######################################################################## #
45
46
 
46
47
 
47
-
48
48
  =begin
49
49
  =end
50
50
 
51
-
52
51
  require 'libpath/diagnostics'
53
52
  require 'libpath/form/unix'
54
53
  require 'libpath/internal_/array'
55
54
  require 'libpath/internal_/unix/form'
56
55
 
57
- module LibPath # :nodoc:
58
- module Util # :nodoc:
59
- module Unix # :nodoc:
60
56
 
61
- # Module defining instance functions that will be included and extended into
62
- # any class or module including/extending module LibPath::Util::Unix
63
- module LibPath_Util_Unix_Methods
57
+ module LibPath
58
+ module Util
59
+ module Unix
60
+
61
+ # Module defining instance functions that will be included and extended into
62
+ # any class or module including/extending module LibPath::Util::Unix
63
+ module LibPath_Util_Unix_Methods
64
64
 
65
- # Combines a number of path parts into a single path, ignoring any parts
66
- # that are preceded by an absolute part
67
- #
68
- # NOTE: The behaviour of this method is undefined if any of the parts
69
- # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
70
- def combine_paths *args, **options
65
+ # Combines a number of path parts into a single path, ignoring any parts
66
+ # that are preceded by an absolute part
67
+ #
68
+ # NOTE: The behaviour of this method is undefined if any of the parts
69
+ # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
70
+ def combine_paths *args, **options
71
71
 
72
- _Form_Unix = Form::Unix
73
- _Internal_Unix_Form = Internal_::Unix::Form
72
+ _Form_Unix = Form::Unix
73
+ _Internal_Unix_Form = Internal_::Unix::Form
74
74
 
75
- args.each_with_index { |arg, index| Diagnostics.check_string_parameter(arg, "arg#{index}", allow_nil: true) } if $DEBUG
75
+ args.each_with_index { |arg, index| Diagnostics.check_string_parameter(arg, "arg#{index}", allow_nil: true) } if $DEBUG
76
76
 
77
- if options[:elide_single_dots]
77
+ if options[:elide_single_dots]
78
78
 
79
- args = args.map do |arg|
79
+ args = args.map do |arg|
80
80
 
81
- case arg
82
- when '.', './'
81
+ case arg
82
+ when '.', './'
83
83
 
84
- nil
85
- else
84
+ nil
85
+ else
86
86
 
87
- arg
88
- end
89
- end
90
- end
87
+ arg
88
+ end
89
+ end
90
+ end
91
91
 
92
- args = args.reject { |arg| arg.nil? || arg.empty? }
92
+ args = args.reject { |arg| arg.nil? || arg.empty? }
93
93
 
94
- case args.size
95
- when 0
94
+ case args.size
95
+ when 0
96
96
 
97
- ''
98
- when 1
97
+ ''
98
+ when 1
99
99
 
100
- args[0]
101
- else
100
+ args[0]
101
+ else
102
102
 
103
- rix = args.rindex { |arg| arg && _Form_Unix.path_is_absolute?(arg) }
104
- rix ||= 0
103
+ rix = args.rindex { |arg| arg && _Form_Unix.path_is_absolute?(arg) }
104
+ rix ||= 0
105
105
 
106
- els = args[rix..-1]
106
+ els = args[rix..-1]
107
107
 
108
- File.join(*els)
109
- end
110
- end
108
+ File.join(*els)
109
+ end
110
+ end
111
111
 
112
- # Obtains the form of the given +path+ relative to the given +origin+
113
- #
114
- # NOTE: The behaviour of this method is undefined if any of the parts
115
- # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
116
- #
117
- # === Signature
118
- #
119
- # * *Options:*
120
- # +:home+:: (String)
121
- # +:locator+:: (boolean)
122
- # +:pwd+:: (String)
123
- def derive_relative_path origin, path, **options
112
+ # Obtains the form of the given +path+ relative to the given +origin+
113
+ #
114
+ # NOTE: The behaviour of this method is undefined if any of the parts
115
+ # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
116
+ #
117
+ # === Signature
118
+ #
119
+ # * *Options:*
120
+ # +:home+:: (String)
121
+ # +:locator+:: (boolean)
122
+ # +:pwd+:: (String)
123
+ def derive_relative_path origin, path, **options
124
124
 
125
- return path if origin.nil? || origin.empty?
126
- return path if path.nil? || path.empty?
125
+ return path if origin.nil? || origin.empty?
126
+ return path if path.nil? || path.empty?
127
127
 
128
- _Form_Unix = Form::Unix
129
- _Util_Unix = Util::Unix
130
- _Internal_Unix_Form = Internal_::Unix::Form
128
+ _Form_Unix = Form::Unix
129
+ _Util_Unix = Util::Unix
130
+ _Internal_Unix_Form = Internal_::Unix::Form
131
131
 
132
- _MPA_COMMON_OPTIONS = %i{ home locator pwd }
132
+ _MPA_COMMON_OPTIONS = %i{ home locator pwd }
133
133
 
134
- tr_sl = _Internal_Unix_Form.get_trailing_slash(path)
134
+ tr_sl = _Internal_Unix_Form.get_trailing_slash(path)
135
135
 
136
- origin = _Util_Unix.make_path_canonical(origin)
137
- path = _Util_Unix.make_path_canonical(path)
136
+ origin = _Util_Unix.make_path_canonical(origin)
137
+ path = _Util_Unix.make_path_canonical(path)
138
138
 
139
- return '.' + tr_sl.to_s if origin == path
140
- return path if '.' == origin || './' == origin
139
+ return '.' + tr_sl.to_s if origin == path
140
+ return path if '.' == origin || './' == origin
141
141
 
142
- o_is_abs = _Form_Unix.path_is_absolute?(origin)
143
- p_is_abs = _Form_Unix.path_is_absolute?(path)
142
+ o_is_abs = _Form_Unix.path_is_absolute?(origin)
143
+ p_is_abs = _Form_Unix.path_is_absolute?(path)
144
144
 
145
- if o_is_abs != p_is_abs || './' == path
145
+ if o_is_abs != p_is_abs || './' == path
146
146
 
147
- origin = _Util_Unix.make_path_absolute(origin, make_canonical: true, **options.select { |k| _MPA_COMMON_OPTIONS.include?(k) })
148
- path = _Util_Unix.make_path_absolute(path, make_canonical: true, **options.select { |k| _MPA_COMMON_OPTIONS.include?(k) })
149
- end
147
+ origin = _Util_Unix.make_path_absolute(origin, make_canonical: true, **options.select { |k| _MPA_COMMON_OPTIONS.include?(k) })
148
+ path = _Util_Unix.make_path_absolute(path, make_canonical: true, **options.select { |k| _MPA_COMMON_OPTIONS.include?(k) })
149
+ end
150
150
 
151
- origin = _Internal_Unix_Form.trim_trailing_slash(origin) unless origin.size < 2
152
- path = _Internal_Unix_Form.trim_trailing_slash(path) if tr_sl && path.size > 1
151
+ origin = _Internal_Unix_Form.trim_trailing_slash(origin) unless origin.size < 2
152
+ path = _Internal_Unix_Form.trim_trailing_slash(path) if tr_sl && path.size > 1
153
153
 
154
154
 
155
- _, _, _, o3_basename, _, _, o6_parts, _ = _Internal_Unix_Form.split_path(origin)
156
- _, _, _, p3_basename, _, _, p6_parts, _ = _Internal_Unix_Form.split_path(path)
155
+ _, _, _, o3_basename, _, _, o6_parts, _ = _Internal_Unix_Form.split_path(origin)
156
+ _, _, _, p3_basename, _, _, p6_parts, _ = _Internal_Unix_Form.split_path(path)
157
157
 
158
- o_parts = o6_parts
159
- o_parts << o3_basename if o3_basename && '.' != o3_basename
158
+ o_parts = o6_parts
159
+ o_parts << o3_basename if o3_basename && '.' != o3_basename
160
160
 
161
- p_parts = p6_parts
162
- p_parts << p3_basename if p3_basename && '.' != p3_basename
161
+ p_parts = p6_parts
162
+ p_parts << p3_basename if p3_basename && '.' != p3_basename
163
163
 
164
164
 
165
- while true
165
+ while true
166
166
 
167
- break if o_parts.empty?
168
- break if p_parts.empty?
167
+ break if o_parts.empty?
168
+ break if p_parts.empty?
169
169
 
170
- o_part = o_parts[0]
171
- p_part = p_parts[0]
170
+ o_part = o_parts[0]
171
+ p_part = p_parts[0]
172
172
 
173
- if 1 == o_parts.size || 1 == p_parts.size
173
+ if 1 == o_parts.size || 1 == p_parts.size
174
174
 
175
- o_part = _Internal_Unix_Form.append_trailing_slash o_part
176
- p_part = _Internal_Unix_Form.append_trailing_slash p_part
177
- end
175
+ o_part = _Internal_Unix_Form.append_trailing_slash o_part
176
+ p_part = _Internal_Unix_Form.append_trailing_slash p_part
177
+ end
178
178
 
179
- if o_part == p_part
179
+ if o_part == p_part
180
180
 
181
- o_parts.shift
182
- p_parts.shift
183
- else
181
+ o_parts.shift
182
+ p_parts.shift
183
+ else
184
184
 
185
- break
186
- end
187
- end
185
+ break
186
+ end
187
+ end
188
188
 
189
189
 
190
- return '.' + tr_sl.to_s if 0 == (o_parts.size + p_parts.size)
190
+ return '.' + tr_sl.to_s if 0 == (o_parts.size + p_parts.size)
191
191
 
192
- return o_parts.map { |rp| '..' }.join('/') + (tr_sl || (o_parts.size != 0 ? '/' : nil)).to_s if p_parts.empty?
192
+ return o_parts.map { |rp| '..' }.join('/') + (tr_sl || (o_parts.size != 0 ? '/' : nil)).to_s if p_parts.empty?
193
193
 
194
194
 
195
- ar = [ '..' ] * o_parts.size + p_parts
196
- last = ar.pop
197
- ar = ar.map { |el| _Internal_Unix_Form.append_trailing_slash(el) }
195
+ ar = [ '..' ] * o_parts.size + p_parts
196
+ last = ar.pop
197
+ ar = ar.map { |el| _Internal_Unix_Form.append_trailing_slash(el) }
198
198
 
199
- ar.join + last.to_s + tr_sl.to_s
200
- end
199
+ ar.join + last.to_s + tr_sl.to_s
200
+ end
201
201
 
202
- # Returns a "compare path" for the given absolute path
203
- #
204
- # A compare path is one that would refer definitely to a given entry,
205
- # regardless of such operating system-specific issues such as
206
- # case-insensitivity
207
- #
208
- # NOTE: the function does not make +path+ absolute. That is up to the
209
- # caller if required
210
- #
211
- # NOTE: The behaviour of this method is undefined if any of the parts
212
- # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
213
- #
214
- # === Signature
215
- #
216
- # * *Parameters:*
217
- # - +path+:: (String) The path whose definitive equivalent is to be
218
- # obtained
219
- # - +options+:: (Hash) options
220
- #
221
- # * *Options:*
222
- # For reasons of compatibility (with the Windows version) no options
223
- # are currently supported; none are proscribed.
224
- def make_compare_path path, **options
202
+ # Returns a "compare path" for the given absolute path
203
+ #
204
+ # A compare path is one that would refer definitely to a given entry,
205
+ # regardless of such operating system-specific issues such as
206
+ # case-insensitivity
207
+ #
208
+ # NOTE: the function does not make +path+ absolute. That is up to the
209
+ # caller if required
210
+ #
211
+ # NOTE: The behaviour of this method is undefined if any of the parts
212
+ # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
213
+ #
214
+ # === Signature
215
+ #
216
+ # * *Parameters:*
217
+ # - +path+:: (String) The path whose definitive equivalent is to be
218
+ # obtained
219
+ # - +options+:: (Hash) options
220
+ #
221
+ # * *Options:*
222
+ # For reasons of compatibility (with the Windows version) no options
223
+ # are currently supported; none are proscribed.
224
+ def make_compare_path path, **options
225
225
 
226
- path
227
- end
226
+ path
227
+ end
228
228
 
229
- #
230
- # NOTE: The behaviour of this method is undefined if any of the parts
231
- # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
232
- #
233
- # === Signature
234
- #
235
- # * *Parameters:*
236
- # - +path+:: (String) The path to be evaluated. May not be +nil+
237
- # - +options+:: (Hash) Options that moderate the behaviour of the
238
- # function
239
- #
240
- # * *Options:*
241
- # - +:home+:: (String) A specific home to assume, which means that the
242
- # +locator+'s +home+ method will not be invoked
243
- # - +:locator+:: (object) An object that provides the methods
244
- # +pwd+ and +home+, as needed. This allows for mocking. If not
245
- # given, then the functions +Dir::pwd+ and +Dir::home+ are used
246
- # - +:make_canonical+:: (boolean) Determines whether canonicalisation
247
- # is conducted on the result
248
- # - +:pwd+:: (String) A specific directory to assume, which means that
249
- # the +locator+'s +pwd+ method will not be invoked
250
- def make_path_absolute path, **options
229
+ #
230
+ # NOTE: The behaviour of this method is undefined if any of the parts
231
+ # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
232
+ #
233
+ # === Signature
234
+ #
235
+ # * *Parameters:*
236
+ # - +path+:: (String) The path to be evaluated. May not be +nil+
237
+ # - +options+:: (Hash) Options that moderate the behaviour of the
238
+ # function
239
+ #
240
+ # * *Options:*
241
+ # - +:home+:: (String) A specific home to assume, which means that the
242
+ # +locator+'s +home+ method will not be invoked
243
+ # - +:locator+:: (object) An object that provides the methods
244
+ # +pwd+ and +home+, as needed. This allows for mocking. If not
245
+ # given, then the functions +Dir::pwd+ and +Dir::home+ are used
246
+ # - +:make_canonical+:: (boolean) Determines whether canonicalisation
247
+ # is conducted on the result
248
+ # - +:pwd+:: (String) A specific directory to assume, which means that
249
+ # the +locator+'s +pwd+ method will not be invoked
250
+ def make_path_absolute path, **options
251
251
 
252
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
253
- Diagnostics.check_options(options, known: %i{ home locator make_canonical pwd }) if $DEBUG
252
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
253
+ Diagnostics.check_options(options, known: %i{ home locator make_canonical pwd }) if $DEBUG
254
254
 
255
- return path if path.nil? || path.empty?
255
+ return path if path.nil? || path.empty?
256
256
 
257
- r = nil
257
+ r = nil
258
258
 
259
- case path[0]
260
- when '/'
259
+ case path[0]
260
+ when '/'
261
261
 
262
- r = path
263
- when '~'
262
+ r = path
263
+ when '~'
264
264
 
265
- case path[1]
266
- when nil, '/'
265
+ case path[1]
266
+ when nil, '/'
267
267
 
268
- home = nil
269
- home ||= options[:home]
270
- home ||= options[:locator].home if options.has_key?(:locator)
271
- home ||= Dir.home
268
+ home = nil
269
+ home ||= options[:home]
270
+ home ||= options[:locator].home if options.has_key?(:locator)
271
+ home ||= Dir.home
272
272
 
273
- r = File.join(home, path[2..-1].to_s)
274
- end
275
- end
273
+ r = File.join(home, path[2..-1].to_s)
274
+ end
275
+ end
276
276
 
277
- unless r
277
+ unless r
278
278
 
279
- pwd = nil
280
- pwd ||= options[:pwd]
281
- pwd ||= options[:locator].pwd if options.has_key?(:locator)
282
- pwd ||= Dir.pwd
279
+ pwd = nil
280
+ pwd ||= options[:pwd]
281
+ pwd ||= options[:locator].pwd if options.has_key?(:locator)
282
+ pwd ||= Dir.pwd
283
283
 
284
- r = File.join(pwd, path)
285
- end
284
+ r = File.join(pwd, path)
285
+ end
286
286
 
287
- r ||= path
287
+ r ||= path
288
288
 
289
- r = make_path_canonical r if options[:make_canonical]
289
+ r = make_path_canonical r if options[:make_canonical]
290
290
 
291
- return r
292
- end
291
+ return r
292
+ end
293
293
 
294
- # Converts a path into canonical form, which is to say that all possible
295
- # dots directory parts are removed:
296
- #
297
- # - single-dot (trailing) parts - '???/.' are converted to '???/' (where
298
- # ??? represents 0+ other characters);
299
- # - single-dot parts - './' - are all removed
300
- # - double-dot parts - '../' - are removed where they follow a non-dots
301
- # directory part, or where they follow the root
302
- #
303
- # NOTE: The behaviour of this method is undefined if any of the parts
304
- # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
305
- #
306
- # === Signature
307
- #
308
- # * *Parameters:*
309
- # - +path+:: (String) The path to be evaluated. May not be +nil+
310
- def make_path_canonical path, **options
294
+ # Converts a path into canonical form, which is to say that all possible
295
+ # dots directory parts are removed:
296
+ #
297
+ # - single-dot (trailing) parts - '???/.' are converted to '???/' (where
298
+ # ??? represents 0+ other characters);
299
+ # - single-dot parts - './' - are all removed
300
+ # - double-dot parts - '../' - are removed where they follow a non-dots
301
+ # directory part, or where they follow the root
302
+ #
303
+ # NOTE: The behaviour of this method is undefined if any of the parts
304
+ # are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
305
+ #
306
+ # === Signature
307
+ #
308
+ # * *Parameters:*
309
+ # - +path+:: (String) The path to be evaluated. May not be +nil+
310
+ def make_path_canonical path, **options
311
311
 
312
- Diagnostics.check_string_parameter(path, "path") if $DEBUG
312
+ Diagnostics.check_string_parameter(path, "path") if $DEBUG
313
313
 
314
- return path unless '.' == path[-1] || path.include?('./') || path.include?('//')
314
+ return path unless '.' == path[-1] || path.include?('./') || path.include?('//')
315
315
 
316
- _Form = ::LibPath::Internal_::Unix::Form
317
- _Array = ::LibPath::Internal_::Array
316
+ _Form = ::LibPath::Internal_::Unix::Form
317
+ _Array = ::LibPath::Internal_::Array
318
318
 
319
- path = path[0...-1] if '.' == path[-1] && '/' == path[-2]
319
+ path = path[0...-1] if '.' == path[-1] && '/' == path[-2]
320
320
 
321
321
 
322
- f0_path, _, f2_dir, f3_basename, _, _, f6_dir_parts, _ = _Form.split_path path
322
+ f0_path, _, f2_dir, f3_basename, _, _, f6_dir_parts, _ = _Form.split_path path
323
323
 
324
- if f6_dir_parts.empty?
324
+ if f6_dir_parts.empty?
325
325
 
326
- case f3_basename
327
- when '.'
326
+ case f3_basename
327
+ when '.'
328
328
 
329
- return './'
330
- when '..'
329
+ return './'
330
+ when '..'
331
331
 
332
- return '../'
333
- else
332
+ return '../'
333
+ else
334
334
 
335
- return f0_path
336
- end
337
- end
335
+ return f0_path
336
+ end
337
+ end
338
338
 
339
- case f3_basename
340
- when '.', '..'
339
+ case f3_basename
340
+ when '.', '..'
341
341
 
342
- f6_dir_parts << f3_basename + '/'
343
- basename = nil
344
- else
342
+ f6_dir_parts << f3_basename + '/'
343
+ basename = nil
344
+ else
345
345
 
346
- basename = f3_basename
347
- end
346
+ basename = f3_basename
347
+ end
348
348
 
349
- is_rooted = '/' == f2_dir[0]
349
+ is_rooted = '/' == f2_dir[0]
350
350
 
351
- new_parts = f6_dir_parts.dup
352
- new_parts.reject! { |p| './' == p }
353
- ix_nodots = new_parts.index { |p| '../' != p } || new_parts.size
354
- ix_2dots = _Array.index(new_parts, '../', ix_nodots)
351
+ new_parts = f6_dir_parts.dup
352
+ new_parts.reject! { |p| './' == p }
353
+ ix_nodots = new_parts.index { |p| '../' != p } || new_parts.size
354
+ ix_2dots = _Array.index(new_parts, '../', ix_nodots)
355
355
 
356
- return "#{new_parts.join}#{basename}" unless new_parts.size != f6_dir_parts.size || ix_2dots
356
+ return "#{new_parts.join}#{basename}" unless new_parts.size != f6_dir_parts.size || ix_2dots
357
357
 
358
- while (ix_2dots || 0) > 0
358
+ while (ix_2dots || 0) > 0
359
359
 
360
- new_parts.delete_at(ix_2dots - 0)
361
- new_parts.delete_at(ix_2dots - 1) if ix_2dots != 1 || !is_rooted
360
+ new_parts.delete_at(ix_2dots - 0)
361
+ new_parts.delete_at(ix_2dots - 1) if ix_2dots != 1 || !is_rooted
362
362
 
363
- ix_nodots = new_parts.index { |p| '../' != p } or break
364
- ix_2dots = _Array.index(new_parts, '../', ix_nodots)
365
- end
363
+ ix_nodots = new_parts.index { |p| '../' != p } or break
364
+ ix_2dots = _Array.index(new_parts, '../', ix_nodots)
365
+ end
366
366
 
367
- if new_parts.empty? && (basename || '').empty?
367
+ if new_parts.empty? && (basename || '').empty?
368
368
 
369
- case f3_basename
370
- when nil, '.', '..'
369
+ case f3_basename
370
+ when nil, '.', '..'
371
371
 
372
- return './'
373
- else
372
+ return './'
373
+ else
374
374
 
375
- return '.'
376
- end
377
- end
375
+ return '.'
376
+ end
377
+ end
378
378
 
379
- return new_parts.join('') + basename.to_s
380
- end
381
- end # module LibPath_Util_Unix_Methods
379
+ return new_parts.join('') + basename.to_s
380
+ end
381
+ end # module LibPath_Util_Unix_Methods
382
382
 
383
- # @!visibility private
384
- def self.extended receiver # :nodoc:
383
+ # @!visibility private
384
+ def self.extended receiver # :nodoc:
385
385
 
386
- receiver.class_eval do
386
+ receiver.class_eval do
387
387
 
388
- extend LibPath_Util_Unix_Methods
389
- end
388
+ extend LibPath_Util_Unix_Methods
389
+ end
390
390
 
391
- $stderr.puts "#{receiver} extended by #{LibPath_Util_Unix_Methods}" if $DEBUG
392
- end
391
+ $stderr.puts "#{receiver} extended by #{LibPath_Util_Unix_Methods}" if $DEBUG
392
+ end
393
393
 
394
- # @!visibility private
395
- def self.included receiver # :nodoc:
394
+ # @!visibility private
395
+ def self.included receiver # :nodoc:
396
396
 
397
- receiver.class_eval do
397
+ receiver.class_eval do
398
398
 
399
- include LibPath_Util_Unix_Methods
400
- end
399
+ include LibPath_Util_Unix_Methods
400
+ end
401
401
 
402
- $stderr.puts "#{receiver} included #{LibPath_Util_Unix_Methods}" if $DEBUG
403
- end
402
+ $stderr.puts "#{receiver} included #{LibPath_Util_Unix_Methods}" if $DEBUG
403
+ end
404
404
 
405
- extend LibPath_Util_Unix_Methods
406
- include LibPath_Util_Unix_Methods
405
+ extend LibPath_Util_Unix_Methods
406
+ include LibPath_Util_Unix_Methods
407
407
 
408
408
  end # module Unix
409
409
  end # module Util
410
410
  end # module LibPath
411
411
 
412
- # ############################## end of file ############################# #
413
412
 
413
+ # ############################## end of file ############################# #
414
414