diff options
author | Haibo Huang <hhb@google.com> | 2021-02-09 18:07:31 -0800 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2021-02-09 18:07:31 -0800 |
commit | 0b2c7a442db3877bd1616293fdbcacd9d4d264b3 (patch) | |
tree | 733837e66077fcb5f4d6030fac8542d90e3b962a | |
parent | 01f6394dc65f719c33e9043bbd9cbbdc67e35ea8 (diff) | |
download | shlex-0b2c7a442db3877bd1616293fdbcacd9d4d264b3.tar.gz |
Upgrade rust/crates/shlex to 1.0.0
Test: make
Change-Id: I55b9e542f82d8187ad779646d6fdd29d15bdcebe
-rw-r--r-- | .Cargo.toml.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | .cargo_vcs_info.json | 5 | ||||
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Android.bp | 3 | ||||
-rw-r--r-- | Cargo.toml | 22 | ||||
-rw-r--r-- | Cargo.toml.orig | 16 | ||||
-rw-r--r-- | LICENSE-APACHE | 13 | ||||
-rw-r--r-- | LICENSE-MIT | 21 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | README.md | 25 | ||||
-rw-r--r-- | TEST_MAPPING | 9 | ||||
-rw-r--r-- | src/.lib.rs.swp | bin | 28672 -> 0 bytes | |||
-rw-r--r-- | src/lib.rs | 32 |
13 files changed, 129 insertions, 30 deletions
diff --git a/.Cargo.toml.swp b/.Cargo.toml.swp Binary files differdeleted file mode 100644 index 48d9460..0000000 --- a/.Cargo.toml.swp +++ /dev/null diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json new file mode 100644 index 0000000..2a7bde4 --- /dev/null +++ b/.cargo_vcs_info.json @@ -0,0 +1,5 @@ +{ + "git": { + "sha1": "618ad7a8bcbfbac1fdf1c473637a75e7f3055b2d" + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd23ebe --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target/ +Cargo.lock +**/*.rs.bk @@ -13,5 +13,8 @@ rust_test_host { srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, + test_options: { + unit_test: true, + }, edition: "2015", } @@ -1,9 +1,19 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + [package] name = "shlex" -version = "0.1.1" -authors = ["comex <comexk@gmail.com>"] -license = "MIT/Apache-2.0" +version = "1.0.0" +authors = ["comex <comexk@gmail.com>", "Fenhl <fenhl@fenhl.net>"] +description = "Split a string into shell words, like Python's shlex.\n" +license = "MIT OR Apache-2.0" repository = "https://github.com/comex/rust-shlex" -description = """ -Split a string into shell words, like Python's shlex. -""" diff --git a/Cargo.toml.orig b/Cargo.toml.orig new file mode 100644 index 0000000..0ca21e8 --- /dev/null +++ b/Cargo.toml.orig @@ -0,0 +1,16 @@ +[package] +name = "shlex" +version = "1.0.0" +authors = [ + "comex <comexk@gmail.com>", + "Fenhl <fenhl@fenhl.net>" +] +license = "MIT OR Apache-2.0" +repository = "https://github.com/comex/rust-shlex" +description = """ +Split a string into shell words, like Python's shlex. +""" +caegories = [ + "command-line-interface", + "parser-implementations" +] diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..3746504 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,13 @@ +Copyright 2015 Nicholas Allegra (comex). + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..5ec1fe1 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Nicholas Allegra (comex). + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/shlex/shlex-0.1.1.crate" + value: "https://static.crates.io/crates/shlex/shlex-1.0.0.crate" } - version: "0.1.1" + version: "1.0.0" license_type: NOTICE last_upgrade_date { - year: 2020 - month: 3 - day: 31 + year: 2021 + month: 2 + day: 9 } } diff --git a/README.md b/README.md new file mode 100644 index 0000000..dad0ae1 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ + +Same idea as (but implementation not directly based on) the Python shlex +module. However, this implementation does not support any of the Python +module's customization because it makes parsing slower and is fairly useless. +You only get the default settings of shlex.split, which mimic the POSIX shell: +http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html + +This implementation also deviates from the Python version in not treating \r +specially, which I believe is more compliant. + +The algorithms in this crate are oblivious to UTF-8 high bytes, so they iterate +over the bytes directly as a micro-optimization. + +# LICENSE +The source code in this repository is Licensed under either of +- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or + http://opensource.org/licenses/MIT) + +at your option. + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall +be dual licensed as above, without any additional terms or conditions. diff --git a/TEST_MAPPING b/TEST_MAPPING index 092edf5..58584f2 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,13 +1,8 @@ -// Generated by cargo2android.py for tests in Android.bp +// Generated by update_crate_tests.py for tests that depend on this crate. { "presubmit": [ { - "host": true, - "name": "shlex_host_test_src_lib" - }, - { - "host": true, - "name": "libsqlite3-sys_host_test_src_lib" + "name": "keystore2_test" }, { "name": "libsqlite3-sys_device_test_src_lib" diff --git a/src/.lib.rs.swp b/src/.lib.rs.swp Binary files differdeleted file mode 100644 index cced600..0000000 --- a/src/.lib.rs.swp +++ /dev/null @@ -96,17 +96,6 @@ impl<'a> Shlex<'a> { loop { if let Some(ch2) = self.next_char() { match ch2 as char { - '\\' => { - if let Some(ch3) = self.next_char() { - match ch3 as char { - // for single quotes, only these can be escaped - '\'' | '\\' => { result.push(ch3); }, - _ => { result.push('\\' as u8); result.push(ch3); } - } - } else { - return Err(()); - } - }, '\'' => { return Ok(()); }, _ => { result.push(ch2); }, } @@ -181,6 +170,15 @@ pub fn quote(in_str: &str) -> Cow<str> { } } +/// Convenience function that consumes an iterable of words and turns it into a single string, +/// quoting words when necessary. Consecutive words will be separated by a single space. +pub fn join<'a, I: IntoIterator<Item = &'a str>>(words: I) -> String { + words.into_iter() + .map(quote) + .collect::<Vec<_>>() + .join(" ") +} + #[cfg(test)] static SPLIT_TEST_ITEMS: &'static [(&'static str, Option<&'static [&'static str]>)] = &[ ("foo$baz", Some(&["foo$baz"])), @@ -191,7 +189,7 @@ static SPLIT_TEST_ITEMS: &'static [(&'static str, Option<&'static [&'static str] ("foo\\\nbar", Some(&["foobar"])), ("\"foo\\\nbar\"", Some(&["foobar"])), ("'baz\\$b'", Some(&["baz\\$b"])), - ("'baz\\\''", Some(&["baz\'"])), + ("'baz\\\''", None), ("\\", None), ("\"\\", None), ("'\\", None), @@ -201,6 +199,8 @@ static SPLIT_TEST_ITEMS: &'static [(&'static str, Option<&'static [&'static str] ("foo #bar", Some(&["foo"])), ("foo#bar", Some(&["foo#bar"])), ("foo\"#bar", None), + ("'\\n'", Some(&["\\n"])), + ("'\\\\n'", Some(&["\\\\n"])), ]; #[test] @@ -227,3 +227,11 @@ fn test_quote() { assert_eq!(quote("\""), "\"\\\"\""); assert_eq!(quote(""), "\"\""); } + +#[test] +fn test_join() { + assert_eq!(join(vec![]), ""); + assert_eq!(join(vec![""]), "\"\""); + assert_eq!(join(vec!["a", "b"]), "a b"); + assert_eq!(join(vec!["foo bar", "baz"]), "\"foo bar\" baz"); +} |