Merge pull request #10 from u1f408/no-std

Add no_std support
This commit is contained in:
Fenhl
2021-08-27 22:32:13 +00:00
committed by GitHub
5 changed files with 70 additions and 10 deletions
+36
View File
@@ -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
View File
@@ -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.
+6 -4
View File
@@ -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"]
+6 -1
View File
@@ -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
<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.
@@ -11,7 +11,12 @@ 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)
+17 -5
View File
@@ -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.
use std::borrow::Cow;
#![cfg_attr(not(feature = "std"), no_std)]
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