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.
- checksums.yaml +4 -4
- data/LICENSE +33 -0
- data/README.md +25 -8
- data/examples/path_from_arg0.md +43 -43
- data/examples/path_from_arg0.rb +25 -23
- data/lib/libpath/constants/unix.rb +74 -74
- data/lib/libpath/constants/windows.rb +75 -75
- data/lib/libpath/constants.rb +20 -20
- data/lib/libpath/diagnostics/parameter_checking.rb +27 -26
- data/lib/libpath/diagnostics.rb +1 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +20 -21
- data/lib/libpath/exceptions/malformed_name_exception.rb +27 -27
- data/lib/libpath/exceptions.rb +1 -1
- data/lib/libpath/form/unix.rb +118 -118
- data/lib/libpath/form/windows.rb +228 -214
- data/lib/libpath/form.rb +20 -21
- data/lib/libpath/internal_/array.rb +57 -57
- data/lib/libpath/internal_/platform.rb +30 -31
- data/lib/libpath/internal_/string.rb +25 -20
- data/lib/libpath/internal_/unix/form.rb +124 -119
- data/lib/libpath/internal_/windows/drive.rb +80 -75
- data/lib/libpath/internal_/windows/form.rb +205 -194
- data/lib/libpath/libpath.rb +4 -1
- data/lib/libpath/path/unix.rb +120 -118
- data/lib/libpath/path/windows.rb +126 -124
- data/lib/libpath/path.rb +21 -21
- data/lib/libpath/util/unix.rb +261 -261
- data/lib/libpath/util/windows.rb +403 -403
- data/lib/libpath/util.rb +20 -20
- data/lib/libpath/version.rb +25 -26
- data/lib/libpath.rb +1 -1
- data/test/performance/benchmark_drive_letter.rb +50 -10
- data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
- data/test/performance/benchmark_rindex2.rb +56 -48
- data/test/performance/benchmark_split.rb +16 -10
- data/test/unit/compare/ts_all.rb +4 -4
- data/test/unit/equate/ts_all.rb +4 -4
- data/test/unit/equate/unix/ts_all.rb +4 -4
- data/test/unit/equate/windows/ts_all.rb +4 -4
- data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
- data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
- data/test/unit/exceptions/ts_all.rb +4 -4
- data/test/unit/form/tc_absolute_functions.rb +242 -240
- data/test/unit/form/ts_all.rb +4 -4
- data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
- data/test/unit/form/unix/ts_all.rb +4 -4
- data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
- data/test/unit/form/windows/ts_all.rb +4 -4
- data/test/unit/internal_/tc_array.rb +36 -32
- data/test/unit/internal_/ts_all.rb +4 -4
- data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
- data/test/unit/internal_/unix/form/ts_all.rb +4 -4
- data/test/unit/internal_/unix/tc_split_path.rb +387 -384
- data/test/unit/internal_/unix/ts_all.rb +4 -4
- data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
- data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
- data/test/unit/internal_/windows/form/ts_all.rb +4 -4
- data/test/unit/internal_/windows/tc_split_path.rb +874 -869
- data/test/unit/internal_/windows/ts_all.rb +4 -4
- data/test/unit/parse/ts_all.rb +4 -4
- data/test/unit/path/tc_path.rb +732 -732
- data/test/unit/path/ts_all.rb +4 -4
- data/test/unit/path/unix/tc_path.rb +544 -540
- data/test/unit/path/unix/ts_all.rb +4 -4
- data/test/unit/path/windows/tc_path.rb +608 -603
- data/test/unit/path/windows/ts_all.rb +4 -4
- data/test/unit/tc_version.rb +25 -22
- data/test/unit/ts_all.rb +4 -4
- data/test/unit/util/tc_combine_paths.rb +110 -105
- data/test/unit/util/tc_derive_relative_path.rb +8 -3
- data/test/unit/util/tc_make_path_canonical.rb +142 -138
- data/test/unit/util/ts_all.rb +4 -4
- data/test/unit/util/unix/tc_combine_paths.rb +38 -34
- data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
- data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
- data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
- data/test/unit/util/unix/ts_all.rb +4 -4
- data/test/unit/util/windows/tc_combine_paths.rb +82 -77
- data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
- data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
- data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
- data/test/unit/util/windows/ts_all.rb +4 -4
- metadata +9 -8
@@ -1,96 +1,96 @@
|
|
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
|
7
|
+
module Internal_ # :nodoc: all
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
# @!visibility private
|
10
|
+
module Array # :nodoc:
|
13
11
|
|
14
|
-
|
12
|
+
# @!visibility private
|
13
|
+
def self.index(ar, v, after = nil) # :nodoc:
|
15
14
|
|
16
|
-
|
15
|
+
if after
|
17
16
|
|
18
|
-
|
17
|
+
if after < 0
|
19
18
|
|
20
|
-
|
21
|
-
else
|
19
|
+
after = ar.size + after
|
22
20
|
|
23
|
-
|
24
|
-
|
21
|
+
return nil if after < 0
|
22
|
+
else
|
25
23
|
|
26
|
-
|
24
|
+
return nil unless after < ar.size
|
25
|
+
end
|
27
26
|
|
28
|
-
|
27
|
+
ar.each_with_index do |el, ix|
|
29
28
|
|
30
|
-
|
29
|
+
if ix >= after
|
31
30
|
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
31
|
+
if v == el
|
36
32
|
|
37
|
-
|
38
|
-
|
33
|
+
return ix
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
38
|
+
nil
|
39
|
+
else
|
43
40
|
|
44
|
-
|
45
|
-
|
41
|
+
ar.index(v)
|
42
|
+
end
|
43
|
+
end
|
46
44
|
|
47
|
-
|
48
|
-
|
45
|
+
# @!visibility private
|
46
|
+
def self.index2(ar, v1, v2, after = nil) # :nodoc:
|
49
47
|
|
50
|
-
|
48
|
+
i_1 = self.index(ar, v1, after)
|
49
|
+
i_2 = self.index(ar, v2, after)
|
51
50
|
|
52
|
-
|
51
|
+
if i_1
|
53
52
|
|
54
|
-
|
55
|
-
else
|
53
|
+
if i_2
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
else
|
55
|
+
i_1 < i_2 ? i_1 : i_2
|
56
|
+
else
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
i_1
|
59
|
+
end
|
60
|
+
else
|
64
61
|
|
62
|
+
i_2
|
63
|
+
end
|
64
|
+
end
|
65
65
|
|
66
|
-
# @!visibility private
|
67
|
-
def self.rindex2(ar, v1, v2) # :nodoc:
|
68
66
|
|
69
|
-
|
70
|
-
|
67
|
+
# @!visibility private
|
68
|
+
def self.rindex2(ar, v1, v2) # :nodoc:
|
71
69
|
|
72
|
-
|
70
|
+
i_1 = ar.rindex(v1)
|
71
|
+
i_2 = ar.rindex(v2)
|
73
72
|
|
74
|
-
|
73
|
+
if i_1
|
75
74
|
|
76
|
-
|
77
|
-
else
|
75
|
+
if i_2
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
else
|
77
|
+
i_1 < i_2 ? i_2 : i_1
|
78
|
+
else
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
i_1
|
81
|
+
end
|
82
|
+
else
|
86
83
|
|
87
|
-
|
84
|
+
i_2
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end # module Array
|
88
|
+
end # module Internal_
|
89
|
+
end # module LibPath
|
88
90
|
|
89
|
-
end
|
90
|
-
end
|
91
91
|
|
92
92
|
# :startdoc:
|
93
93
|
|
94
|
-
# ############################## end of file ############################# #
|
95
94
|
|
95
|
+
# ############################## end of file ############################# #
|
96
96
|
|
@@ -1,53 +1,52 @@
|
|
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
|
10
|
-
|
11
|
-
# @!visibility private
|
12
|
-
module OS_Internal_ # :nodoc: all
|
13
|
-
|
14
|
-
# @!visibility private
|
15
|
-
def self.win_platform_? # :nodoc:
|
7
|
+
module Internal_ # :nodoc: all
|
16
8
|
|
17
|
-
|
9
|
+
# @!visibility private
|
10
|
+
module Platform # :nodoc: all
|
18
11
|
|
19
|
-
|
20
|
-
|
21
|
-
'cygwin',
|
22
|
-
'djgpp',
|
23
|
-
'mingw',
|
24
|
-
'mswin',
|
25
|
-
'wince',
|
26
|
-
].each do |os_name|
|
12
|
+
# @!visibility private
|
13
|
+
module OS_Internal_ # :nodoc: all
|
27
14
|
|
28
|
-
|
29
|
-
|
15
|
+
# @!visibility private
|
16
|
+
def self.win_platform_? # :nodoc:
|
30
17
|
|
31
|
-
|
32
|
-
end
|
18
|
+
return true if 'Windows_NT' == ENV['OS']
|
33
19
|
|
34
|
-
|
20
|
+
[
|
21
|
+
'bccwin',
|
22
|
+
'cygwin',
|
23
|
+
'djgpp',
|
24
|
+
'mingw',
|
25
|
+
'mswin',
|
26
|
+
'wince',
|
27
|
+
].each do |os_name|
|
35
28
|
|
36
|
-
|
37
|
-
|
29
|
+
return true if /#{os_name}/i =~ RUBY_PLATFORM
|
30
|
+
end
|
38
31
|
|
39
|
-
|
40
|
-
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end # module OS_Internal_
|
41
35
|
|
42
|
-
|
36
|
+
# @!visibility private
|
37
|
+
module Constants # :nodoc: all
|
43
38
|
|
44
|
-
|
39
|
+
# @!visibility private
|
40
|
+
PLATFORM_IS_WINDOWS = OS_Internal_.win_platform_? # :nodoc:
|
45
41
|
|
42
|
+
end # module Constants
|
43
|
+
end # module Platform
|
46
44
|
end # module Internal_
|
47
45
|
end # module LibPath
|
48
46
|
|
47
|
+
|
49
48
|
# :startdoc:
|
50
49
|
|
51
|
-
# ############################## end of file ############################# #
|
52
50
|
|
51
|
+
# ############################## end of file ############################# #
|
53
52
|
|
@@ -1,36 +1,41 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
# :stopdoc:
|
3
|
+
|
4
|
+
|
5
|
+
module LibPath
|
3
6
|
# @!visibility private
|
4
7
|
module Internal_ # :nodoc: all
|
5
8
|
|
6
|
-
|
9
|
+
# @!visibility private
|
10
|
+
module String # :nodoc:
|
7
11
|
|
8
|
-
|
9
|
-
|
12
|
+
# @!visibility private
|
13
|
+
def self.rindex2(s, c1, c2) # :nodoc:
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
ri_1 = s.rindex(c1)
|
16
|
+
ri_2 = s.rindex(c2)
|
13
17
|
|
14
|
-
|
18
|
+
if ri_1
|
15
19
|
|
16
|
-
|
20
|
+
if ri_2
|
17
21
|
|
18
|
-
|
19
|
-
|
22
|
+
ri_1 < ri_2 ? ri_2 : ri_1
|
23
|
+
else
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
ri_1
|
26
|
+
end
|
27
|
+
else
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
ri_2
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end # module String
|
33
|
+
end # module Internal_
|
34
|
+
end # module LibPath
|
28
35
|
|
29
|
-
end
|
30
36
|
|
31
|
-
|
32
|
-
end
|
37
|
+
# :startdoc:
|
33
38
|
|
34
|
-
# ############################## end of file ############################# #
|
35
39
|
|
40
|
+
# ############################## end of file ############################# #
|
36
41
|
|
@@ -1,165 +1,170 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
# :stopdoc:
|
3
|
+
|
4
|
+
|
5
|
+
module LibPath
|
3
6
|
# @!visibility private
|
4
7
|
module Internal_ # :nodoc: all
|
5
8
|
# @!visibility private
|
6
9
|
module Unix # :nodoc:
|
7
10
|
|
8
|
-
# @!visibility private
|
9
|
-
module Form # :nodoc:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
11
|
+
# @!visibility private
|
12
|
+
module Form # :nodoc:
|
13
|
+
|
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:
|
19
|
+
|
20
|
+
'/' == c
|
21
|
+
end
|
22
|
+
|
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:
|
28
|
+
|
29
|
+
return s if '/' == s[-1]
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
s + '/'
|
32
|
+
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
'/' == s[-1] ? '/' : nil
|
38
|
-
end
|
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:
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
#
|
43
|
-
# @!visibility private
|
44
|
-
def self.has_trailing_slash? s # :nodoc:
|
40
|
+
'/' == s[-1] ? '/' : nil
|
41
|
+
end
|
45
42
|
|
46
|
-
|
47
|
-
|
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:
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
#
|
52
|
-
# @!visibility private
|
53
|
-
def self.trim_trailing_slash s # :nodoc:
|
49
|
+
'/' == s[-1]
|
50
|
+
end
|
54
51
|
|
55
|
-
|
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:
|
56
57
|
|
57
|
-
|
58
|
-
end
|
58
|
+
return s unless '/' == s[-1]
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
# @!visibility private
|
64
|
-
def self.elide_redundant_path_name_separators s # :nodoc:
|
60
|
+
s.chop
|
61
|
+
end
|
65
62
|
|
66
|
-
|
67
|
-
|
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:
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
#
|
72
|
-
# @!visibility private
|
73
|
-
def self.elide_redundant_path_name_separators! s # :nodoc:
|
69
|
+
s.gsub(/\/\/+/, '/')
|
70
|
+
end
|
74
71
|
|
75
|
-
|
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:
|
76
77
|
|
77
|
-
|
78
|
-
end
|
78
|
+
s.gsub!(/\/\/+/, '/')
|
79
79
|
|
80
|
+
s
|
81
|
+
end
|
80
82
|
|
81
|
-
# [INTERNAL] This function is undocumented, and subject to change at any
|
82
|
-
# time
|
83
|
-
#
|
84
|
-
# Returns tuple of:
|
85
|
-
#
|
86
|
-
# 0. source path (with redundant path name separators elided)
|
87
|
-
# 1. Windows volume (which is always nil)
|
88
|
-
# 2. Directory
|
89
|
-
# 3. Basename
|
90
|
-
# 4. Stem
|
91
|
-
# 5. Extension
|
92
|
-
# 6. Directory parts
|
93
|
-
# 7. Directory path parts
|
94
|
-
#
|
95
|
-
# @!visibility private
|
96
|
-
def self.split_path s, **options # :nodoc:
|
97
83
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
84
|
+
# [INTERNAL] This function is undocumented, and subject to change at any
|
85
|
+
# time
|
86
|
+
#
|
87
|
+
# Returns tuple of:
|
88
|
+
#
|
89
|
+
# 0. source path (with redundant path name separators elided)
|
90
|
+
# 1. Windows volume (which is always nil)
|
91
|
+
# 2. Directory
|
92
|
+
# 3. Basename
|
93
|
+
# 4. Stem
|
94
|
+
# 5. Extension
|
95
|
+
# 6. Directory parts
|
96
|
+
# 7. Directory path parts
|
97
|
+
#
|
98
|
+
# @!visibility private
|
99
|
+
def self.split_path s, **options # :nodoc:
|
103
100
|
|
104
|
-
|
101
|
+
f2_directory = nil
|
102
|
+
f3_basename = nil
|
103
|
+
f4_stem = nil
|
104
|
+
f5_extension = nil
|
105
|
+
f6_dir_parts = []
|
105
106
|
|
106
|
-
|
107
|
+
s = self.elide_redundant_path_name_separators s
|
107
108
|
|
108
|
-
|
109
|
+
ri_slash = s.rindex('/')
|
109
110
|
|
110
|
-
|
111
|
-
f3_basename = s[(1 + ri_slash)..-1]
|
112
|
-
else
|
111
|
+
if ri_slash
|
113
112
|
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
f2_directory = s[0..ri_slash]
|
114
|
+
f3_basename = s[(1 + ri_slash)..-1]
|
115
|
+
else
|
117
116
|
|
118
|
-
|
119
|
-
|
117
|
+
f2_directory = nil
|
118
|
+
f3_basename = s
|
119
|
+
end
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
else
|
121
|
+
case f3_basename
|
122
|
+
when '.', '..'
|
124
123
|
|
125
|
-
|
124
|
+
f4_stem = f3_basename
|
125
|
+
f5_extension = nil
|
126
|
+
else
|
126
127
|
|
127
|
-
|
128
|
+
ri_dot = f3_basename.rindex('.')
|
128
129
|
|
129
|
-
|
130
|
-
f5_extension = f3_basename[ri_dot..-1]
|
131
|
-
else
|
130
|
+
if ri_dot
|
132
131
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
132
|
+
f4_stem = f3_basename[0...ri_dot]
|
133
|
+
f5_extension = f3_basename[ri_dot..-1]
|
134
|
+
else
|
137
135
|
|
138
|
-
|
136
|
+
f4_stem = f3_basename
|
137
|
+
f5_extension = nil
|
138
|
+
end
|
139
|
+
end
|
139
140
|
|
140
|
-
|
141
|
-
when nil
|
141
|
+
unless options[:suppress_parts]
|
142
142
|
|
143
|
-
|
144
|
-
|
143
|
+
case f2_directory
|
144
|
+
when nil
|
145
145
|
|
146
|
-
|
147
|
-
|
146
|
+
;
|
147
|
+
when '/'
|
148
148
|
|
149
|
-
|
150
|
-
|
151
|
-
end
|
152
|
-
end
|
149
|
+
f6_dir_parts = [ '/' ]
|
150
|
+
else
|
153
151
|
|
152
|
+
f6_dir_parts = f2_directory.split('/').reject { |v| v.empty? }.map { |v| v + '/' }
|
153
|
+
f6_dir_parts.unshift('/') if '/' == f2_directory[0]
|
154
|
+
end
|
155
|
+
end
|
154
156
|
|
155
|
-
[ s, nil, f2_directory, f3_basename, f4_stem, f5_extension, f6_dir_parts, f6_dir_parts ].map { |v| ::String === v && v.empty? ? nil : v }
|
156
|
-
end
|
157
|
-
end # module Form
|
158
157
|
|
158
|
+
[ s, nil, f2_directory, f3_basename, f4_stem, f5_extension, f6_dir_parts, f6_dir_parts ].map { |v| ::String === v && v.empty? ? nil : v }
|
159
|
+
end
|
160
|
+
end # module Form
|
159
161
|
end # module Unix
|
160
162
|
end # module Internal_
|
161
163
|
end # module LibPath
|
162
164
|
|
163
|
-
# ############################## end of file ############################# #
|
164
165
|
|
166
|
+
# :startdoc:
|
167
|
+
|
168
|
+
|
169
|
+
# ############################## end of file ############################# #
|
165
170
|
|