aboutsummaryrefslogtreecommitdiffstats
path: root/src/common.rs
blob: b3cb65666e8a1cf3d2df741cc1221245d66911be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//! Common code used between the various puzzles

use std::io;

/// Reads from stdin until an empty line is encountered
///
/// Returns the read data as a string
pub fn read_stdin_to_string() -> String {
    let mut input = String::new();
    let mut line = String::new();

    println!("Enter puzzle input followed by an empty line:");
    loop {
        io::stdin().read_line(&mut line).unwrap();
        if line.trim() == "" {
            break;
        }
        input.push_str(&line);
        line.clear();
    }

    input
}