From 466e16f3139f434fd4d6c2aed4748b4e43a3445c Mon Sep 17 00:00:00 2001 From: Iris System Date: Fri, 27 Aug 2021 06:55:36 +1200 Subject: [PATCH 1/7] Fix Cargo manifest slightly - `categories` was misspelled - `description` does not need to be a multi-line string --- Cargo.toml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0ca21e8..5489d30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,10 +7,8 @@ authors = [ ] 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 = [ +description = "Split a string into shell words, like Python's shlex." +categories = [ "command-line-interface", "parser-implementations" ] From 89fa2d151b7db0926254ca600ab4551fad4f552f Mon Sep 17 00:00:00 2001 From: Iris System Date: Fri, 27 Aug 2021 07:00:28 +1200 Subject: [PATCH 2/7] Slight crate documentation changes - Explicitly linkifies the `pubs.opengroup.org` URL - Surround `\r` with backticks so that it renders nicer --- README.md | 3 ++- src/lib.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 31b9168..92ad1c2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ 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: -https://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. @@ -12,6 +12,7 @@ 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 https://www.apache.org/licenses/LICENSE-2.0) diff --git a/src/lib.rs b/src/lib.rs index fa4a605..261aa1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,10 +7,10 @@ //! 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: -//! https://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. +//! 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. From 458d8616a073f65c461c952e64450ce6acc233d8 Mon Sep 17 00:00:00 2001 From: Iris System Date: Fri, 27 Aug 2021 07:01:08 +1200 Subject: [PATCH 3/7] Add `std` feature, allow crate to work in #![no_std] mode Disabling the `std` feature (by setting `default-features = false` for this crate in the Cargo.toml of something requiring it) will enable the crate to work without the standard library, assuming the presence of the `alloc` crate and a working global allocator. We've explicitly imported the individual `alloc` items required by this crate, rather than using `#![feature(alloc_prelude)]` as `alloc_prelude` requires Rust nightly, and doing it that way would be a breaking change to the MSRV. Tested with Cargo/rustc 1.53.0 --- Cargo.toml | 4 ++++ README.md | 4 ++++ src/lib.rs | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5489d30..870d5d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,7 @@ categories = [ "command-line-interface", "parser-implementations" ] + +[features] +std = [] +default = ["std"] diff --git a/README.md b/README.md index 92ad1c2..d1b956c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ 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. +Disabling the `std` feature (which is enabled by default) will allow the crate +to work in `no_std` environments, where a the `alloc` crate, and a global +allocator, are available. + # LICENSE The source code in this repository is Licensed under either of diff --git a/src/lib.rs b/src/lib.rs index 261aa1a..bf5d633 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,13 +14,25 @@ //! //! The algorithms in this crate are oblivious to UTF-8 high bytes, so they iterate over the bytes //! directly as a micro-optimization. +//! +//! Disabling the `std` feature (which is enabled by default) will allow the crate to work in +//! `no_std` environments, where a the `alloc` crate, and a global allocator, are available. + +#![cfg_attr(not(feature = "std"), no_std)] -use std::borrow::Cow; +extern crate alloc; +use alloc::vec::Vec; +use alloc::borrow::Cow; +use alloc::string::String; +#[cfg(test)] +use alloc::vec; +#[cfg(test)] +use alloc::borrow::ToOwned; /// An iterator that takes an input string and splits it into the words using the same syntax as /// the POSIX shell. pub struct Shlex<'a> { - in_iter: std::str::Bytes<'a>, + in_iter: core::str::Bytes<'a>, /// The number of newlines read so far, plus one. pub line_no: usize, /// An input string is erroneous if it ends while inside a quotation or right after an From 93908700c670e9fde164641610a8cdf87ddc9407 Mon Sep 17 00:00:00 2001 From: Iris System Date: Fri, 27 Aug 2021 07:15:31 +1200 Subject: [PATCH 4/7] Add GitHub Actions to run tests for default and #![no_std] modes --- .github/workflows/test.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7f29991 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Rust + +on: + pull_request: + push: + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ATiltedTree/setup-rust@v1 + with: + rust-version: stable + - run: cargo check + + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ATiltedTree/setup-rust@v1 + with: + rust-version: stable + - run: cargo test + + test_no_default_features: + name: Test (no default features) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ATiltedTree/setup-rust@v1 + with: + rust-version: stable + - run: cargo test --no-default-features From d900c9ee51d82a1c86d189552db220066919eb94 Mon Sep 17 00:00:00 2001 From: Iris System Date: Fri, 27 Aug 2021 07:24:03 +1200 Subject: [PATCH 5/7] Add mention of #![no_std] mode to CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ba79c1..2bcde1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# [unreleased] + +* Adds the `std` feature (enabled by default) +* Disabling the `std` feature makes the crate work in `#![no_std]` mode, assuming presence of the `alloc` crate + # 1.0.0 * Adds the `join` convenience function. From 48c81e1a630dd4e1781c79babd9c4a81aee79556 Mon Sep 17 00:00:00 2001 From: Fenhl Date: Fri, 27 Aug 2021 20:50:38 +0000 Subject: [PATCH 6/7] Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d1b956c..6778828 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The algorithms in this crate are oblivious to UTF-8 high bytes, so they iterate over the bytes directly as a micro-optimization. Disabling the `std` feature (which is enabled by default) will allow the crate -to work in `no_std` environments, where a the `alloc` crate, and a global +to work in `no_std` environments, where the `alloc` crate, and a global allocator, are available. # LICENSE From e4b0a70d256012caaaeb7e5f093ab83431978898 Mon Sep 17 00:00:00 2001 From: Fenhl Date: Fri, 27 Aug 2021 20:51:37 +0000 Subject: [PATCH 7/7] Typo --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bf5d633..31b54bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ //! directly as a micro-optimization. //! //! Disabling the `std` feature (which is enabled by default) will allow the crate to work in -//! `no_std` environments, where a the `alloc` crate, and a global allocator, are available. +//! `no_std` environments, where the `alloc` crate, and a global allocator, are available. #![cfg_attr(not(feature = "std"), no_std)]