Implement split instead of using heavy regex
This commit is contained in:
parent
1090f03b34
commit
2e4b0432e0
|
|
@ -531,7 +531,6 @@ dependencies = [
|
|||
"log",
|
||||
"multiboot2",
|
||||
"pod",
|
||||
"regex",
|
||||
"spin 0.9.8",
|
||||
"trapframe",
|
||||
"volatile",
|
||||
|
|
@ -980,31 +979,6 @@ dependencies = [
|
|||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575"
|
||||
dependencies = [
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310"
|
||||
dependencies = [
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"
|
||||
|
||||
[[package]]
|
||||
name = "ringbuf"
|
||||
version = "0.3.2"
|
||||
|
|
|
|||
|
|
@ -18,13 +18,12 @@ log = "0.4"
|
|||
lazy_static = { version = "1.0", features = ["spin_no_std"] }
|
||||
trapframe = { git = "https://github.com/sdww0/trapframe-rs", rev = "e886763" }
|
||||
inherit-methods-macro = { git = "https://github.com/jinzhao-dev/inherit-methods-macro", rev = "98f7e3e" }
|
||||
regex = { version = "1.9.1", default-features = false, features = ["unicode"] }
|
||||
|
||||
[target.x86_64-custom.dependencies]
|
||||
x86_64 = "0.14.2"
|
||||
x86 = "0.52.0"
|
||||
acpi = "4.1.1"
|
||||
aml = "0.16.3"
|
||||
multiboot2 = { version = "0.16.0", features = [] }
|
||||
multiboot2 = "0.16.0"
|
||||
|
||||
[features]
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use alloc::{
|
|||
vec::Vec,
|
||||
};
|
||||
use log::debug;
|
||||
use regex::Regex;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct InitprocArg {
|
||||
|
|
@ -55,6 +54,20 @@ impl KCmdlineArg {
|
|||
}
|
||||
}
|
||||
|
||||
// Split the command line string by spaces but preserve
|
||||
// ones that are protected by double quotes(`"`).
|
||||
fn split_arg(input: &str) -> impl Iterator<Item = &str> {
|
||||
let mut inside_quotes = false;
|
||||
|
||||
input.split(move |c: char| {
|
||||
if c == '"' {
|
||||
inside_quotes = !inside_quotes;
|
||||
}
|
||||
|
||||
!inside_quotes && c.is_whitespace()
|
||||
})
|
||||
}
|
||||
|
||||
// Define the way to parse a string to `KCmdlineArg`.
|
||||
impl From<&str> for KCmdlineArg {
|
||||
fn from(cmdline: &str) -> Self {
|
||||
|
|
@ -64,18 +77,12 @@ impl From<&str> for KCmdlineArg {
|
|||
module_args: BTreeMap::new(),
|
||||
};
|
||||
|
||||
// Split the command line string by spaces but preserve
|
||||
// ones that are protected by double quotes(`"`).
|
||||
let re = Regex::new(r#"((\S*"[^"]*"\S*)+|\S+)"#).unwrap();
|
||||
// Every thing after the "--" mark is the initproc arguments.
|
||||
let mut kcmdline_end = false;
|
||||
|
||||
// The main parse loop. The processing steps are arranged (not very strictly)
|
||||
// by the analysis over the Backus–Naur form syntax tree.
|
||||
for arg in re.find_iter(cmdline).map(|m| m.as_str()) {
|
||||
if arg == "" || arg == " " {
|
||||
continue;
|
||||
}
|
||||
for arg in split_arg(cmdline) {
|
||||
// Cmdline => KernelArg "--" InitArg
|
||||
// KernelArg => Arg "\s+" KernelArg | %empty
|
||||
// InitArg => Arg "\s+" InitArg | %empty
|
||||
|
|
|
|||
Loading…
Reference in New Issue