Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mod helpers;
- mod item;
- use item::Item;
- use num::bigint::BigInt;
- use once_cell::sync::OnceCell;
- use regex::Regex;
- use std::cell::RefCell;
- use std::io;
- use std::rc::Rc;
- use std::str::FromStr;
- fn trim_newline(s: &mut String) {
- if s.ends_with('\n') {
- s.pop();
- if s.ends_with('\r') {
- s.pop();
- }
- }
- }
- fn is_valid_string(string: &str) -> bool {
- static VALID_REGEX: OnceCell<Regex> = OnceCell::new();
- let regex = VALID_REGEX.get_or_init(
- || Regex::new("^(0|-?[1-9][0-9]*|[A-Za-z][0-9A-Z_a-z]*)$").unwrap()
- );
- regex.is_match(string)
- }
- fn insert_before(item: &Item<String>, other: &Item<String>) -> bool {
- let (val, oth) = (&item.value, &other.value);
- if let Ok(x) = BigInt::from_str(val) {
- if let Ok(y) = BigInt::from_str(oth) {
- return x <= y
- }
- }
- val <= oth
- }
- fn main() {
- let mut begin = true;
- let mut input;
- let start: Option<Box<Item<String>>> = None;
- loop {
- if !begin {
- println!();
- }
- else {
- begin = false;
- }
- println!("Awaiting input...");
- let mut string = String::new();
- io::stdin().read_line(&mut string).expect("Failed to read line!");
- trim_newline(&mut string);
- input = &string[..];
- if string.is_empty() {
- println!("is_empty!");
- }
- else if string.starts_with('~') {
- println!("starts_with '~'!");
- }
- else if input.eq("l") {
- println!("eq \"l\"!");
- }
- else if input.eq("i") {
- println!("eq \"i\"!");
- }
- else if input.eq("a") {
- println!("eq \"a\"!");
- }
- else if is_valid_string(input) {
- println!("is_valid_string!");
- }
- else {
- println!("else...");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement