Skip to content

Commit

Permalink
Merge pull request #10 from u1f408/no-std
Browse files Browse the repository at this point in the history
Add no_std support
  • Loading branch information
fenhl committed Aug 27, 2021
2 parents 8c5a36d + e4b0a70 commit 06785ea
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 10 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ 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"
]

[features]
std = []
default = ["std"]
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ 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
<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.

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 the `alloc` crate, and a global
allocator, are available.

# 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)
Expand Down
22 changes: 17 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,32 @@
//! 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
//! <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.
//!
//! Disabling the `std` feature (which is enabled by default) will allow the crate to work in
//! `no_std` environments, where 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
Expand Down

0 comments on commit 06785ea

Please sign in to comment.