faster_path 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afefb5a6536b8fe153a66b6788725d3905582e88
4
- data.tar.gz: 4b95f1bd231189b8223df2d4cfd7f778b114d734
3
+ metadata.gz: a7663e3cebaf52e71d0445b29c541e31ad1b6f87
4
+ data.tar.gz: 67071c8d8d399baf4d64705d1e7a5c147f56bc39
5
5
  SHA512:
6
- metadata.gz: 058d9bf0ad593e4c4a63df7ce544a8903dd29f1b9cecb58965137def1c56e9248555dc2d1942b870809a5e277edb13b1bd384325549314c40838966e11451c11
7
- data.tar.gz: 72af47b03e1e01e9787dec3ff8b58cdf1927a0ceef447cd5e142812ac2a2a53a25b78cd812f6120f2d2c81984efe6c144afcebf007d1611106a836d4c097306f
6
+ metadata.gz: 1607471e1395c8fc7c583fb936e5bfe618dd5066eda0d59613040b3499565ff6d7fe106a55447dcec7a8dc705fb7af96c011e535ec165b2f06b5f7e4fc983ccf
7
+ data.tar.gz: 312ba0423e39dce09031e7d2b1f29bfc5562865c89b15854713a771047b89be668e2ca35c254f4471398836999f44037a2539012a0dcdd6935160cdcc6d36105
data/README.md CHANGED
@@ -131,6 +131,7 @@ Current methods implemented:
131
131
  | `FasterPath.relative?` | `Pathname#relative?` | 1262.3% |
132
132
  | `FasterPath.blank?` | | |
133
133
  | `FasterPath.directory?` | `Pathname#directory?` | 20% |
134
+ | `FasterPath.add_trailing_separator` | `Pathname#add_trailing_separator` | 63.8% |
134
135
 
135
136
  You may choose to use the methods directly, or scope change to rewrite behavior on the
136
137
  standard library with the included refinements, or even call a method to monkeypatch
@@ -23,6 +23,11 @@ module FasterPath
23
23
  def relative?
24
24
  FasterPath.relative?(@path)
25
25
  end
26
+
27
+ def add_trailing_separator(pth)
28
+ FasterPath.add_trailing_separator(pth)
29
+ end
30
+ private :add_trailing_separator
26
31
  end
27
32
  end
28
33
  end
@@ -25,6 +25,11 @@ module FasterPath
25
25
  def relative?
26
26
  FasterPath.relative?(@path)
27
27
  end
28
+
29
+ def add_trailing_separator(pth)
30
+ FasterPath.add_trailing_separator(pth)
31
+ end
32
+ private :add_trailing_separator
28
33
  end
29
34
  end
30
35
  end
@@ -1,3 +1,3 @@
1
1
  module FasterPath
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/faster_path.rb CHANGED
@@ -35,6 +35,10 @@ module FasterPath
35
35
  Rust.basename(pth, ext)
36
36
  end
37
37
 
38
+ def self.add_trailing_separator(pth)
39
+ Rust.add_trailing_separator(pth)
40
+ end
41
+
38
42
  # EXAMPLE
39
43
  #def self.one_and_two
40
44
  # Rust.one_and_two.to_a
@@ -66,6 +70,7 @@ module FasterPath
66
70
  attach_function :dirname, [ :string ], :string
67
71
  attach_function :basename_for_chop, [ :string ], :string # decoupling behavior
68
72
  attach_function :dirname_for_chop, [ :string ], :string # decoupling behavior
73
+ attach_function :add_trailing_separator, [ :string ], :string
69
74
 
70
75
  # EXAMPLE
71
76
  #attach_function :one_and_two, [], FromRustArray.by_value
@@ -0,0 +1,28 @@
1
+ use std::path::{Path, MAIN_SEPARATOR};
2
+ use libc::c_char;
3
+ use std::ffi::{CStr, CString};
4
+ use std::str;
5
+
6
+ #[no_mangle]
7
+ pub extern "C" fn add_trailing_separator(string: *const c_char) -> *const c_char {
8
+ let c_str = unsafe {
9
+ assert!(!string.is_null());
10
+
11
+ CStr::from_ptr(string)
12
+ };
13
+ let r_str = str::from_utf8(c_str.to_bytes()).unwrap_or("");
14
+
15
+ if r_str.is_empty() {
16
+ return string;
17
+ }
18
+
19
+ let path = Path::new(r_str);
20
+ let out_str = if !(path.to_str().unwrap().chars().last().unwrap() == '/') {
21
+ format!("{}{}", path.to_str().unwrap(), MAIN_SEPARATOR)
22
+ } else {
23
+ path.to_str().unwrap().to_string()
24
+ };
25
+
26
+ let output = CString::new(out_str).unwrap();
27
+ output.into_raw()
28
+ }
data/src/lib.rs CHANGED
@@ -17,6 +17,7 @@ pub mod basename;
17
17
  pub mod dirname;
18
18
  pub mod basename_for_chop;
19
19
  pub mod dirname_for_chop;
20
+ pub mod add_trailing_separator;
20
21
 
21
22
  // EXAMPLE
22
23
  //
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faster_path
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark
@@ -132,6 +132,7 @@ files:
132
132
  - lib/faster_path/optional/monkeypatches.rb
133
133
  - lib/faster_path/optional/refinements.rb
134
134
  - lib/faster_path/version.rb
135
+ - src/add_trailing_separator.rs
135
136
  - src/basename.rs
136
137
  - src/basename_for_chop.rs
137
138
  - src/both_are_blank.rs