Skip to content

Commit

Permalink
Fix: process names can have spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
JosuGZ committed Jan 30, 2021
1 parent b56e39e commit 4f2276a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ voluntary_ctxt_switches: 127195
nonvoluntary_ctxt_switches: 5";

#[cfg(test)]
static STATUS_EXAMPLE_2: &str = "Name: dropbox
static STATUS_EXAMPLE_2: &str = "Name: dropbox 2 3 4
Umask: 0002
State: S (sleeping)
Tgid: 24104
Expand Down Expand Up @@ -126,10 +126,14 @@ fn parse_status(file_content: &str) -> Option<Status> {
fn get_value_str(name: &str, line: &str) -> Option<String> {
if line.contains(name) {
let mut parts = line.split_whitespace();
let value_str = match parts.nth(1) {
Some(value) => value,
let mut value_str = match parts.nth(1) {
Some(value) => value.to_string(),
_ => return None
};
for part in parts.skip(0) {
value_str += " ";
value_str += part;
}
return Some(String::from(value_str));
} else {
return None
Expand Down Expand Up @@ -265,7 +269,7 @@ fn parse_status_1() {
#[test]
fn parse_status_2() {
let expected = Some(Status {
name: "dropbox".to_string(),
name: "dropbox 2 3 4".to_string(),
vm_peack: 3393164 * 1024,
vm_size: 3326428 * 1024,
vm_lck: 0 * 1024,
Expand Down

0 comments on commit 4f2276a

Please sign in to comment.