Skip to content

Commit 06785ea

Browse files
authored
Merge pull request #10 from u1f408/no-std
Add no_std support
2 parents 8c5a36d + e4b0a70 commit 06785ea

File tree

5 files changed

+70
-10
lines changed

5 files changed

+70
-10
lines changed

.github/workflows/test.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Rust
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
check:
9+
name: Check
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: ATiltedTree/setup-rust@v1
14+
with:
15+
rust-version: stable
16+
- run: cargo check
17+
18+
test:
19+
name: Test
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: ATiltedTree/setup-rust@v1
24+
with:
25+
rust-version: stable
26+
- run: cargo test
27+
28+
test_no_default_features:
29+
name: Test (no default features)
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v2
33+
- uses: ATiltedTree/setup-rust@v1
34+
with:
35+
rust-version: stable
36+
- run: cargo test --no-default-features

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# [unreleased]
2+
3+
* Adds the `std` feature (enabled by default)
4+
* Disabling the `std` feature makes the crate work in `#![no_std]` mode, assuming presence of the `alloc` crate
5+
16
# 1.0.0
27

38
* Adds the `join` convenience function.

Cargo.toml

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ authors = [
77
]
88
license = "MIT OR Apache-2.0"
99
repository = "https://github.com/comex/rust-shlex"
10-
description = """
11-
Split a string into shell words, like Python's shlex.
12-
"""
13-
caegories = [
10+
description = "Split a string into shell words, like Python's shlex."
11+
categories = [
1412
"command-line-interface",
1513
"parser-implementations"
1614
]
15+
16+
[features]
17+
std = []
18+
default = ["std"]

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ Same idea as (but implementation not directly based on) the Python shlex
33
module. However, this implementation does not support any of the Python
44
module's customization because it makes parsing slower and is fairly useless.
55
You only get the default settings of shlex.split, which mimic the POSIX shell:
6-
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
6+
<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html>
77

88
This implementation also deviates from the Python version in not treating \r
99
specially, which I believe is more compliant.
1010

1111
The algorithms in this crate are oblivious to UTF-8 high bytes, so they iterate
1212
over the bytes directly as a micro-optimization.
1313

14+
Disabling the `std` feature (which is enabled by default) will allow the crate
15+
to work in `no_std` environments, where the `alloc` crate, and a global
16+
allocator, are available.
17+
1418
# LICENSE
19+
1520
The source code in this repository is Licensed under either of
1621
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
1722
https://www.apache.org/licenses/LICENSE-2.0)

src/lib.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,32 @@
77
//! implementation does not support any of the Python module's customization because it makes
88
//! parsing slower and is fairly useless. You only get the default settings of shlex.split, which
99
//! mimic the POSIX shell:
10-
//! https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
10+
//! <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html>
1111
//!
12-
//! This implementation also deviates from the Python version in not treating \r specially, which I
13-
//! believe is more compliant.
12+
//! This implementation also deviates from the Python version in not treating `\r` specially, which
13+
//! I believe is more compliant.
1414
//!
1515
//! The algorithms in this crate are oblivious to UTF-8 high bytes, so they iterate over the bytes
1616
//! directly as a micro-optimization.
17+
//!
18+
//! Disabling the `std` feature (which is enabled by default) will allow the crate to work in
19+
//! `no_std` environments, where the `alloc` crate, and a global allocator, are available.
20+
21+
#![cfg_attr(not(feature = "std"), no_std)]
1722

18-
use std::borrow::Cow;
23+
extern crate alloc;
24+
use alloc::vec::Vec;
25+
use alloc::borrow::Cow;
26+
use alloc::string::String;
27+
#[cfg(test)]
28+
use alloc::vec;
29+
#[cfg(test)]
30+
use alloc::borrow::ToOwned;
1931

2032
/// An iterator that takes an input string and splits it into the words using the same syntax as
2133
/// the POSIX shell.
2234
pub struct Shlex<'a> {
23-
in_iter: std::str::Bytes<'a>,
35+
in_iter: core::str::Bytes<'a>,
2436
/// The number of newlines read so far, plus one.
2537
pub line_no: usize,
2638
/// An input string is erroneous if it ends while inside a quotation or right after an

0 commit comments

Comments
 (0)