use std::borrow::Borrow;
+use std::cmp::max;
use std::collections::{BTreeSet, VecDeque};
use std::slice;
fn parse_command(line: &str, bot_user: &str) -> Option<Command> {
let lower_line = line.to_lowercase();
if lower_line == format!("/u/{} reset", bot_user) {
- return Some(Command::Reset);
- } else if lower_line == "sidebar count" || lower_line == "current count" {
- return Some(Command::Report);
+ Some(Command::Reset)
} else {
- return None;
+ match lower_line.as_str() {
+ "sidebar count" | "current count" => Some(Command::Report),
+ _ => None,
+ }
}
}
bot_user: &str
) -> Result<ParsedUpdate, ParseError> {
- // TextNode is HtmlElementImpl::Node containing HtmlNode::Text
+ // TextNode is type(body)::Node containing HtmlNode::Text
enum Text<TextNode> {
FromTree(TextNode),
Other(String),
}
- // Node is HtmlElementImpl::Node
+ // Node is type(body)::Node
enum WorklistEntry<Node> {
Space,
NewLine,
deletable = lone;
} else {
let mut groups_okay = all_parts_valid;
- let mut use_parts = &parts;
+ let mut use_parts = &parts[..];
if let Some(count_val) = curr_count {
if sep_opt.is_some() && sep_opt.unwrap().chars().all(char::is_whitespace) {
// Presume that the intended count consists of as many valid digit groups as
// necessary to match the number of digits in the expected count, if
// possible.
let digit_count = format!("{}", count_val.abs()).len();
- let mut use_parts = vec![];
- let mut accum = 0;
+ let mut total_len = 0;
+ let mut part_count = 0;
for (i, part) in parts.iter().cloned().enumerate() {
let part_valid = if i == 0 { part.len() <= 3 } else { part.len() == 3 };
- if part_valid && accum < digit_count {
- use_parts.push(part);
- accum += part.len();
+ if part_valid && total_len < digit_count {
+ total_len += part.len();
+ part_count += 1;
} else {
break;
}
// Could still be a no-separator count with some extra digit groups on the
// same line.
- if use_parts.is_empty() {
- use_parts = vec![parts[0]];
- }
+ part_count = max(part_count, 1);
+ use_parts = &parts[..part_count];
lone = lone && use_parts.len() == parts.len();
// Validated by regex as only ASCII digits, leading zeros stripped.
count_attempt = True
deletable = lone
else:
- groups_okay = True
if curr_count is not None and sep and sep.isspace():
# Presume that the intended count consists of as many valid digit groups as
# necessary to match the number of digits in the expected count, if possible.
use_parts = [parts[0]]
lone = lone and len(use_parts) == len(parts)
+
+ # Validated by regex as only ASCII digits, leading zeros stripped.
+ groups_okay = True
else:
# current count is unknown, or any detected separator unambiguously delineates
# the number