MCPcopy Create free account
hub / github.com/davidblewett/rure-python / parse

Method parse

regex/build.rs:49–88  ·  view source on GitHub ↗
(mut s: &str)

Source from the content-addressed store, hash-verified

47 }
48
49 fn parse(mut s: &str) -> Result<Version, String> {
50 if !s.starts_with("rustc ") {
51 return Err(format!("unrecognized version string: {}", s));
52 }
53 s = &s["rustc ".len()..];
54
55 let parts: Vec<&str> = s.split(".").collect();
56 if parts.len() < 3 {
57 return Err(format!("not enough version parts: {:?}", parts));
58 }
59
60 let mut num = String::new();
61 for c in parts[0].chars() {
62 if !c.is_digit(10) {
63 break;
64 }
65 num.push(c);
66 }
67 let major = num.parse::<u32>().map_err(|e| e.to_string())?;
68
69 num.clear();
70 for c in parts[1].chars() {
71 if !c.is_digit(10) {
72 break;
73 }
74 num.push(c);
75 }
76 let minor = num.parse::<u32>().map_err(|e| e.to_string())?;
77
78 num.clear();
79 for c in parts[2].chars() {
80 if !c.is_digit(10) {
81 break;
82 }
83 num.push(c);
84 }
85 let patch = num.parse::<u32>().map_err(|e| e.to_string())?;
86
87 Ok(Version { major, minor, patch })
88 }
89}

Callers

nothing calls this directly

Calls 4

lenMethod · 0.45
splitMethod · 0.45
pushMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected