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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/libpath/constants/unix.rb +66 -66
- data/lib/libpath/constants/windows.rb +67 -67
- data/lib/libpath/constants.rb +3 -2
- data/lib/libpath/diagnostics/parameter_checking.rb +2 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +12 -13
- data/lib/libpath/exceptions/malformed_name_exception.rb +20 -21
- data/lib/libpath/form/unix.rb +107 -108
- data/lib/libpath/form/windows.rb +206 -193
- data/lib/libpath/form.rb +2 -3
- data/lib/libpath/internal_/array.rb +48 -48
- data/lib/libpath/internal_/platform.rb +26 -27
- data/lib/libpath/internal_/string.rb +22 -17
- data/lib/libpath/internal_/unix/form.rb +118 -113
- data/lib/libpath/internal_/windows/drive.rb +76 -71
- data/lib/libpath/internal_/windows/form.rb +206 -195
- data/lib/libpath/libpath.rb +1 -1
- data/lib/libpath/path/unix.rb +104 -104
- data/lib/libpath/path/windows.rb +98 -98
- data/lib/libpath/path.rb +3 -1
- data/lib/libpath/util/unix.rb +4 -4
- data/lib/libpath/util/windows.rb +4 -4
- data/lib/libpath/util.rb +3 -2
- data/lib/libpath/version.rb +9 -9
- data/test/performance/benchmark_rindex2.rb +7 -7
- metadata +2 -2
@@ -1,51 +1,50 @@
|
|
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
9
|
# @!visibility private
|
12
|
-
module
|
10
|
+
module Platform # :nodoc: all
|
13
11
|
|
14
12
|
# @!visibility private
|
15
|
-
|
13
|
+
module OS_Internal_ # :nodoc: all
|
16
14
|
|
17
|
-
|
15
|
+
# @!visibility private
|
16
|
+
def self.win_platform_? # :nodoc:
|
18
17
|
|
19
|
-
|
20
|
-
'bccwin',
|
21
|
-
'cygwin',
|
22
|
-
'djgpp',
|
23
|
-
'mingw',
|
24
|
-
'mswin',
|
25
|
-
'wince',
|
26
|
-
].each do |os_name|
|
27
|
-
|
28
|
-
return true if /#{os_name}/i =~ RUBY_PLATFORM
|
29
|
-
end
|
18
|
+
return true if 'Windows_NT' == ENV['OS']
|
30
19
|
|
31
|
-
|
32
|
-
|
20
|
+
[
|
21
|
+
'bccwin',
|
22
|
+
'cygwin',
|
23
|
+
'djgpp',
|
24
|
+
'mingw',
|
25
|
+
'mswin',
|
26
|
+
'wince',
|
27
|
+
].each do |os_name|
|
33
28
|
|
34
|
-
|
29
|
+
return true if /#{os_name}/i =~ RUBY_PLATFORM
|
30
|
+
end
|
35
31
|
|
36
|
-
|
37
|
-
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end # module OS_Internal_
|
38
35
|
|
39
36
|
# @!visibility private
|
40
|
-
|
37
|
+
module Constants # :nodoc: all
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
end # module Platform
|
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
50
|
|
@@ -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
|
-
module String # :nodoc:
|
7
|
-
|
8
9
|
# @!visibility private
|
9
|
-
|
10
|
+
module String # :nodoc:
|
11
|
+
|
12
|
+
# @!visibility private
|
13
|
+
def self.rindex2(s, c1, c2) # :nodoc:
|
14
|
+
|
15
|
+
ri_1 = s.rindex(c1)
|
16
|
+
ri_2 = s.rindex(c2)
|
10
17
|
|
11
|
-
|
12
|
-
ri_2 = s.rindex(c2)
|
18
|
+
if ri_1
|
13
19
|
|
14
|
-
|
20
|
+
if ri_2
|
15
21
|
|
16
|
-
|
22
|
+
ri_1 < ri_2 ? ri_2 : ri_1
|
23
|
+
else
|
17
24
|
|
18
|
-
|
25
|
+
ri_1
|
26
|
+
end
|
19
27
|
else
|
20
28
|
|
21
|
-
|
29
|
+
ri_2
|
22
30
|
end
|
23
|
-
else
|
24
|
-
|
25
|
-
ri_2
|
26
31
|
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end # module String
|
30
|
-
|
32
|
+
end # module String
|
31
33
|
end # module Internal_
|
32
34
|
end # module LibPath
|
33
35
|
|
34
36
|
|
37
|
+
# :startdoc:
|
38
|
+
|
39
|
+
|
35
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
|
-
# [INTERNAL] This function is undocumented, and subject to change at any
|
12
|
-
# time
|
13
|
-
#
|
14
11
|
# @!visibility private
|
15
|
-
|
12
|
+
module Form # :nodoc:
|
16
13
|
|
17
|
-
|
18
|
-
|
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
19
|
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
# @!visibility private
|
24
|
-
def self.append_trailing_slash s # :nodoc:
|
20
|
+
'/' == c
|
21
|
+
end
|
25
22
|
|
26
|
-
|
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:
|
27
28
|
|
28
|
-
|
29
|
-
end
|
29
|
+
return s if '/' == s[-1]
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
# @!visibility private
|
35
|
-
def self.get_trailing_slash s # :nodoc:
|
31
|
+
s + '/'
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
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:
|
74
|
-
|
75
|
-
s.gsub!(/\/\/+/, '/')
|
76
|
-
|
77
|
-
s
|
78
|
-
end
|
79
|
-
|
80
|
-
|
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:
|
69
|
+
s.gsub(/\/\/+/, '/')
|
70
|
+
end
|
97
71
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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:
|
103
77
|
|
104
|
-
|
78
|
+
s.gsub!(/\/\/+/, '/')
|
105
79
|
|
106
|
-
|
80
|
+
s
|
81
|
+
end
|
107
82
|
|
108
|
-
if ri_slash
|
109
83
|
|
110
|
-
|
111
|
-
|
112
|
-
|
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:
|
113
100
|
|
114
101
|
f2_directory = nil
|
115
|
-
f3_basename =
|
116
|
-
|
117
|
-
|
118
|
-
case f3_basename
|
119
|
-
when '.', '..'
|
120
|
-
|
121
|
-
f4_stem = f3_basename
|
102
|
+
f3_basename = nil
|
103
|
+
f4_stem = nil
|
122
104
|
f5_extension = nil
|
123
|
-
|
105
|
+
f6_dir_parts = []
|
106
|
+
|
107
|
+
s = self.elide_redundant_path_name_separators s
|
124
108
|
|
125
|
-
|
109
|
+
ri_slash = s.rindex('/')
|
126
110
|
|
127
|
-
if
|
111
|
+
if ri_slash
|
128
112
|
|
129
|
-
|
130
|
-
|
113
|
+
f2_directory = s[0..ri_slash]
|
114
|
+
f3_basename = s[(1 + ri_slash)..-1]
|
131
115
|
else
|
132
116
|
|
117
|
+
f2_directory = nil
|
118
|
+
f3_basename = s
|
119
|
+
end
|
120
|
+
|
121
|
+
case f3_basename
|
122
|
+
when '.', '..'
|
123
|
+
|
133
124
|
f4_stem = f3_basename
|
134
125
|
f5_extension = nil
|
126
|
+
else
|
127
|
+
|
128
|
+
ri_dot = f3_basename.rindex('.')
|
129
|
+
|
130
|
+
if ri_dot
|
131
|
+
|
132
|
+
f4_stem = f3_basename[0...ri_dot]
|
133
|
+
f5_extension = f3_basename[ri_dot..-1]
|
134
|
+
else
|
135
|
+
|
136
|
+
f4_stem = f3_basename
|
137
|
+
f5_extension = nil
|
138
|
+
end
|
135
139
|
end
|
136
|
-
end
|
137
140
|
|
138
|
-
|
141
|
+
unless options[:suppress_parts]
|
139
142
|
|
140
|
-
|
141
|
-
|
143
|
+
case f2_directory
|
144
|
+
when nil
|
142
145
|
|
143
|
-
|
144
|
-
|
146
|
+
;
|
147
|
+
when '/'
|
145
148
|
|
146
|
-
|
147
|
-
|
149
|
+
f6_dir_parts = [ '/' ]
|
150
|
+
else
|
148
151
|
|
149
|
-
|
150
|
-
|
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
|
151
155
|
end
|
152
|
-
end
|
153
156
|
|
154
157
|
|
155
|
-
|
156
|
-
|
157
|
-
end # module Form
|
158
|
-
|
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
165
|
|
166
|
+
# :startdoc:
|
167
|
+
|
168
|
+
|
164
169
|
# ############################## end of file ############################# #
|
165
170
|
|
@@ -1,87 +1,92 @@
|
|
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 Windows # :nodoc:
|
7
|
-
# @!visibility private
|
8
|
-
module Drive # :nodoc:
|
9
|
-
|
10
|
-
# @!visibility private
|
11
|
-
module Constants # :nodoc:
|
12
|
-
|
13
|
-
DRIVE_LETTERS = [
|
14
|
-
|
15
|
-
'C',
|
16
|
-
'D',
|
17
|
-
'E',
|
18
|
-
'F',
|
19
|
-
'G',
|
20
|
-
'H',
|
21
|
-
'I',
|
22
|
-
'J',
|
23
|
-
'K',
|
24
|
-
'L',
|
25
|
-
'M',
|
26
|
-
'N',
|
27
|
-
'P',
|
28
|
-
'Q',
|
29
|
-
'R',
|
30
|
-
'S',
|
31
|
-
'T',
|
32
|
-
'U',
|
33
|
-
'V',
|
34
|
-
'W',
|
35
|
-
'I',
|
36
|
-
'X',
|
37
|
-
'Y',
|
38
|
-
'Z',
|
39
|
-
|
40
|
-
'c',
|
41
|
-
'd',
|
42
|
-
'e',
|
43
|
-
'f',
|
44
|
-
'g',
|
45
|
-
'h',
|
46
|
-
'i',
|
47
|
-
'j',
|
48
|
-
'k',
|
49
|
-
'l',
|
50
|
-
'm',
|
51
|
-
'n',
|
52
|
-
'p',
|
53
|
-
'q',
|
54
|
-
'r',
|
55
|
-
's',
|
56
|
-
't',
|
57
|
-
'u',
|
58
|
-
'v',
|
59
|
-
'w',
|
60
|
-
'i',
|
61
|
-
'x',
|
62
|
-
'y',
|
63
|
-
'z',
|
64
|
-
|
65
|
-
'A',
|
66
|
-
'B',
|
67
|
-
|
68
|
-
'a',
|
69
|
-
'b',
|
70
|
-
|
71
|
-
]
|
72
|
-
end # module Constants
|
73
10
|
|
74
11
|
# @!visibility private
|
75
|
-
|
12
|
+
module Drive # :nodoc:
|
13
|
+
|
14
|
+
# @!visibility private
|
15
|
+
module Constants # :nodoc:
|
16
|
+
|
17
|
+
DRIVE_LETTERS = [
|
76
18
|
|
77
|
-
|
78
|
-
|
19
|
+
'C',
|
20
|
+
'D',
|
21
|
+
'E',
|
22
|
+
'F',
|
23
|
+
'G',
|
24
|
+
'H',
|
25
|
+
'I',
|
26
|
+
'J',
|
27
|
+
'K',
|
28
|
+
'L',
|
29
|
+
'M',
|
30
|
+
'N',
|
31
|
+
'P',
|
32
|
+
'Q',
|
33
|
+
'R',
|
34
|
+
'S',
|
35
|
+
'T',
|
36
|
+
'U',
|
37
|
+
'V',
|
38
|
+
'W',
|
39
|
+
'I',
|
40
|
+
'X',
|
41
|
+
'Y',
|
42
|
+
'Z',
|
79
43
|
|
80
|
-
|
44
|
+
'c',
|
45
|
+
'd',
|
46
|
+
'e',
|
47
|
+
'f',
|
48
|
+
'g',
|
49
|
+
'h',
|
50
|
+
'i',
|
51
|
+
'j',
|
52
|
+
'k',
|
53
|
+
'l',
|
54
|
+
'm',
|
55
|
+
'n',
|
56
|
+
'p',
|
57
|
+
'q',
|
58
|
+
'r',
|
59
|
+
's',
|
60
|
+
't',
|
61
|
+
'u',
|
62
|
+
'v',
|
63
|
+
'w',
|
64
|
+
'i',
|
65
|
+
'x',
|
66
|
+
'y',
|
67
|
+
'z',
|
68
|
+
|
69
|
+
'A',
|
70
|
+
'B',
|
71
|
+
|
72
|
+
'a',
|
73
|
+
'b',
|
74
|
+
]
|
75
|
+
end # module Constants
|
76
|
+
|
77
|
+
# @!visibility private
|
78
|
+
def self.character_is_drive_letter? ch # :nodoc:
|
79
|
+
|
80
|
+
::LibPath::Internal_::Windows::Drive::Constants::DRIVE_LETTERS.include? ch
|
81
|
+
end
|
82
|
+
end # module Drive
|
81
83
|
end # module Windows
|
82
84
|
end # module Internal_
|
83
85
|
end # module LibPath
|
84
86
|
|
85
87
|
|
88
|
+
# :startdoc:
|
89
|
+
|
90
|
+
|
86
91
|
# ############################## end of file ############################# #
|
87
92
|
|