Skip to content

Commit 47ebc1e

Browse files
committed
Initial commit
0 parents  commit 47ebc1e

File tree

10 files changed

+3665
-0
lines changed

10 files changed

+3665
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
*~

COPYING

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License
2+
3+
Copyright (c) 2024 sfparse-rs contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "sfparse"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]

README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See README.rst

README.rst

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
sfparse-rs
2+
==========
3+
4+
sfparse-rs is `RFC 9651
5+
<https://datatracker.ietf.org/doc/html/rfc9651>`_ Structured Field
6+
Values parser written in Rust. It is the port of `sfparse
7+
<https://github.com/ngtcp2/sfparse>`_ written in C.
8+
9+
It is designed not to do any extra allocation, like allocating maps,
10+
lists, and Strings, and do the minimal stuff to parse the input data.
11+
12+
.. code-block:: rust
13+
14+
use sfparse::{Parser, Value};
15+
16+
let mut urgency :i32 = 3;
17+
let mut incremental = false;
18+
let mut p = Parser::new("u=2, i".as_bytes());
19+
20+
loop {
21+
match p.parse_dict().unwrap() {
22+
None => break,
23+
Some(("u", Value::Integer(v))) if (0i64..=7i64).contains(&v) => urgency = v as i32,
24+
Some(("i", Value::Bool(v))) => incremental = v,
25+
_ => (),
26+
}
27+
}
28+
29+
println!("urgency={urgency} incremental={incremental}");
30+
31+
License
32+
-------
33+
34+
The MIT License
35+
36+
Copyright (c) 2024 sfparse-rs contributors

src/lib.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! [RFC 9651](https://datatracker.ietf.org/doc/html/rfc9651)
2+
//! Structured Field Values parser.
3+
//!
4+
//! Provides Structured Field Values parser that is designed not to do
5+
//! any extra allocation, like allocating maps, lists, and Strings,
6+
//! and do the minimal stuff to parse the input data.
7+
//!
8+
//! This is an example of parsing [RFC
9+
//! 9218](https://datatracker.ietf.org/doc/html/rfc9218) Priority
10+
//! header field:
11+
//!
12+
//! ```
13+
//! use sfparse::{Parser, Value};
14+
//!
15+
//! let mut urgency :i32 = 3;
16+
//! let mut incremental = false;
17+
//! let mut p = Parser::new("u=2, i".as_bytes());
18+
//!
19+
//! loop {
20+
//! match p.parse_dict().unwrap() {
21+
//! None => break,
22+
//! Some(("u", Value::Integer(v))) if (0i64..=7i64).contains(&v) => urgency = v as i32,
23+
//! Some(("i", Value::Bool(v))) => incremental = v,
24+
//! _ => (),
25+
//! }
26+
//! }
27+
//!
28+
//! println!("urgency={urgency} incremental={incremental}");
29+
//! ```
30+
mod parser;
31+
mod utf8;
32+
mod value;
33+
34+
pub use crate::parser::{Parser, Error};
35+
pub use crate::value::Value;

0 commit comments

Comments
 (0)