libpath-ruby 0.2.1 → 0.2.2.1

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