MCPcopy Create free account
hub / github.com/LibertyOS-Development/kernel / parse_csv

Function parse_csv

src/graphics/vga/pal.rs:80–122  ·  view source on GitHub ↗

Parse/interpret palettes from CSV files:

(s: &str)

Source from the content-addressed store, hash-verified

78
79// Parse/interpret palettes from CSV files:
80pub fn parse_csv(s: &str) -> Result<Palette, ()>
81{
82 let color: Vec<_> = s.split('\n').filter_map(|line|
83 {
84 // Remove any comments:
85 let ln = line.split('#').next().unwrap();
86 let color: Vec<u8> = ln.split(',').filter_map(|value|
87 {
88 let radix = if value.contains("0x")
89 {
90 16
91 }
92 else
93 {
94 10
95 };
96 let value = value.trim().trim_start_matches("0x");
97 u8::from_str_radix(value, radix).ok()
98 }).collect();
99
100 // RGB
101 if color.len() == 3
102 {
103 Some((color[0], color[1], color[2]))
104 }
105 else
106 {
107 None
108 }}).collect();
109
110 // 16 COLOR ARRAY
111 if let Ok(color) = color.try_into()
112 {
113 Ok(Palette
114 {
115 color
116 })
117 }
118 else
119 {
120 Err(())
121 }
122}

Callers

nothing calls this directly

Calls 4

containsMethod · 0.80
ErrEnum · 0.50
nextMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected