Move tokenize to new file
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parent 13986b1 · Browse files · 4 files·+64 added−63 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+64 added−63 removed
- other:+64 added−63 removed
Provenance
- Commit
eb31e0f- Tree
213a1a2- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
13986b1
4 files changed+64 added−63 removed
modified:src/benchmark.rs+1 added-1 removed
7 unmodified lines8 use crate::benchmark_result::BenchmarkResult;9 use crate::command::Command;10 use crate::format::{format_duration, format_duration_unit};11 use crate::internal::{max, min, MIN_EXECUTION_TIME};12-use crate::progress_bar::get_progress_bar;12 use crate::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};13 use crate::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};14+use crate::progress_bar::get_progress_bar;15 use crate::shell::execute_and_time;16 use crate::timer::wallclocktimer::WallClockTimer;17 use crate::timer::{TimerStart, TimerStop};18 use crate::units::Second;467 unmodified linesmodified:src/internal.rs-61 removed
162 unmodified lines163 let annotated_results = compute_relative_speed(&results);164 165 assert!(annotated_results.is_none());166 }167-168-pub fn tokenize(values: &str) -> Vec<String> {169- let mut tokens = vec![];170- let mut buf = String::new();171-172- let mut iter = values.chars();173- while let Some(c) = iter.next() {174- match c {175- '\\' => match iter.next() {176- Some(c2 @ ',') | Some(c2 @ '\\') => {177- buf.push(c2);178- }179- Some(c2) => {180- buf.push('\\');181- buf.push(c2);182- }183- None => buf.push('\\'),184- },185- ',' => {186- tokens.push(buf);187- buf = String::new();188- }189- _ => {190- buf.push(c);191- }192- };193- }194-195- tokens.push(buf);196-197- tokens198-}199-200-#[test]201-fn test_tokenize_single_value() {202- assert_eq!(tokenize(r""), vec![""]);203- assert_eq!(tokenize(r"foo"), vec!["foo"]);204- assert_eq!(tokenize(r" "), vec![" "]);205- assert_eq!(tokenize(r"hello\, world!"), vec!["hello, world!"]);206- assert_eq!(tokenize(r"\,"), vec![","]);207- assert_eq!(tokenize(r"\,\,\,"), vec![",,,"]);208- assert_eq!(tokenize(r"\n"), vec![r"\n"]);209- assert_eq!(tokenize(r"\\"), vec![r"\"]);210- assert_eq!(tokenize(r"\\\,"), vec![r"\,"]);211-}212-213-#[test]214-fn test_tokenize_multiple_values() {215- assert_eq!(tokenize(r"foo,bar,baz"), vec!["foo", "bar", "baz"]);216- assert_eq!(tokenize(r"hello world,foo"), vec!["hello world", "foo"]);217-218- assert_eq!(tokenize(r"hello\,world!,baz"), vec!["hello,world!", "baz"]);219-}220-221-#[test]222-fn test_tokenize_empty_values() {223- assert_eq!(tokenize(r"foo,,bar"), vec!["foo", "", "bar"]);224- assert_eq!(tokenize(r",bar"), vec!["", "bar"]);225- assert_eq!(tokenize(r"bar,"), vec!["bar", ""]);226- assert_eq!(tokenize(r",,"), vec!["", "", ""]);227-}modified:src/main.rs+3 added-1 removed
19 unmodified lines20 pub mod parameter_range;21 pub mod progress_bar;22 pub mod shell;23 pub mod timer;24+pub mod tokenize;25 pub mod types;26 pub mod units;27 pub mod warnings;28 1 unmodified line30 use benchmark::{mean_shell_spawning_time, run_benchmark};31 use command::Command;32 use error::OptionsError;33 use export::{ExportManager, ExportType};33-use internal::{tokenize, write_benchmark_comparison};34+use internal::write_benchmark_comparison;35 use options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};36 use parameter_range::get_parameterized_commands;37+use tokenize::tokenize;38 use types::ParameterValue;39 use units::Unit;40 41 /// Print error message to stderr and terminate384 unmodified linesadded:src/tokenize.rs+60 added
1+pub fn tokenize(values: &str) -> Vec<String> {2+ let mut tokens = vec![];3+ let mut buf = String::new();4+5+ let mut iter = values.chars();6+ while let Some(c) = iter.next() {7+ match c {8+ '\\' => match iter.next() {9+ Some(c2 @ ',') | Some(c2 @ '\\') => {10+ buf.push(c2);11+ }12+ Some(c2) => {13+ buf.push('\\');14+ buf.push(c2);15+ }16+ None => buf.push('\\'),17+ },18+ ',' => {19+ tokens.push(buf);20+ buf = String::new();21+ }22+ _ => {23+ buf.push(c);24+ }25+ };26+ }27+28+ tokens.push(buf);29+30+ tokens31+}32+33+#[test]34+fn test_tokenize_single_value() {35+ assert_eq!(tokenize(r""), vec![""]);36+ assert_eq!(tokenize(r"foo"), vec!["foo"]);37+ assert_eq!(tokenize(r" "), vec![" "]);38+ assert_eq!(tokenize(r"hello\, world!"), vec!["hello, world!"]);39+ assert_eq!(tokenize(r"\,"), vec![","]);40+ assert_eq!(tokenize(r"\,\,\,"), vec![",,,"]);41+ assert_eq!(tokenize(r"\n"), vec![r"\n"]);42+ assert_eq!(tokenize(r"\\"), vec![r"\"]);43+ assert_eq!(tokenize(r"\\\,"), vec![r"\,"]);44+}45+46+#[test]47+fn test_tokenize_multiple_values() {48+ assert_eq!(tokenize(r"foo,bar,baz"), vec!["foo", "bar", "baz"]);49+ assert_eq!(tokenize(r"hello world,foo"), vec!["hello world", "foo"]);50+51+ assert_eq!(tokenize(r"hello\,world!,baz"), vec!["hello,world!", "baz"]);52+}53+54+#[test]55+fn test_tokenize_empty_values() {56+ assert_eq!(tokenize(r"foo,,bar"), vec!["foo", "", "bar"]);57+ assert_eq!(tokenize(r",bar"), vec!["", "bar"]);58+ assert_eq!(tokenize(r"bar,"), vec!["bar", ""]);59+ assert_eq!(tokenize(r",,"), vec!["", "", ""]);60+}