Skip to content

Commit 2e0b575

Browse files
committed
patch: csv parsing
1 parent 1ed7777 commit 2e0b575

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Resources/CPU.vala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,18 @@ public class Monitor.CPU : Object {
213213
dis = new DataInputStream (csv_file.read ());
214214
string flag_data;
215215
while ((flag_data = dis.read_line ()) != null) {
216-
var splitted = flag_data.split (",");
217-
all_flags.set (splitted[0], splitted[1].replace ("\r", ""));
216+
217+
int comma_position = flag_data.index_of_char (',');
218+
219+
if (comma_position == -1) break; // quick exit if no commas are in the line
220+
221+
string key = flag_data.substring (0, comma_position);
222+
string value = flag_data.substring (comma_position + 1)
223+
.replace ("\"", "")
224+
.replace (" ", " ")
225+
.strip ();
226+
227+
all_flags.set (key, value.replace ("\r", ""));
218228
}
219229
debug ("Parsed file %s", csv_file.get_path ());
220230

0 commit comments

Comments
 (0)