1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#[macro_export]
macro_rules! separated_uint_with_output {
    ($string:expr, $output:expr) => {{
        let mut place = $string.len();
        let mut later_loop = false;

        for ch in $string.chars() {
            if later_loop && place % 3 == 0 {
                $output.push(',');
            }

            $output.push(ch);
            later_loop = true;
            place -= 1;
        };

        $output
    }};
}

#[macro_export]
macro_rules! separated_uint {
    ($string:expr) => {{
        let mut output = String::new();
        separated_uint_with_output!($string, output)
    }}
}

#[macro_export]
macro_rules! separated_int {
    ($string:expr) => {{
        let mut output = String::new();
        let magnitude = if $string.starts_with('-') {
            output.push('-');
            (&$string)[1..].to_owned()
        } else {
            $string
        };

        separated_uint_with_output!(magnitude, output)
    }};
}

#[macro_export]
macro_rules! separated_float {
    ($string:expr) => {{
        let idx = match $string.find('.') {
            Some(i) => i,
            None => $string.len()
        };

        let int_part = (&$string[..idx]).to_owned();
        let fract_part = &$string[idx..];
        let output = separated_int!(int_part);
        output + fract_part
    }};
}