feat(linux): replaces the deprecated function 'split' with the function 'splitScalar'
This commit is contained in:
@@ -26,11 +26,11 @@ pub fn getCpuInfo(allocator: std.mem.Allocator) !CpuInfo {
|
|||||||
// Parsing /proc/cpuinfo
|
// Parsing /proc/cpuinfo
|
||||||
var model_name: ?[]const u8 = null;
|
var model_name: ?[]const u8 = null;
|
||||||
|
|
||||||
var lines = std.mem.split(u8, cpuinfo_data, "\n");
|
var lines = std.mem.splitScalar(u8, cpuinfo_data, '\n');
|
||||||
while (lines.next()) |line| {
|
while (lines.next()) |line| {
|
||||||
const trimmed = std.mem.trim(u8, line, " \t");
|
const trimmed = std.mem.trim(u8, line, " \t");
|
||||||
if (std.mem.startsWith(u8, trimmed, "model name") and model_name == null) {
|
if (std.mem.startsWith(u8, trimmed, "model name") and model_name == null) {
|
||||||
var parts = std.mem.split(u8, trimmed, ":");
|
var parts = std.mem.splitScalar(u8, trimmed, ':');
|
||||||
_ = parts.next(); // discards the key
|
_ = parts.next(); // discards the key
|
||||||
if (parts.next()) |value| {
|
if (parts.next()) |value| {
|
||||||
model_name = std.mem.trim(u8, value, " ");
|
model_name = std.mem.trim(u8, value, " ");
|
||||||
@@ -75,25 +75,25 @@ pub fn getRamInfo(allocator: std.mem.Allocator) !RamInfo {
|
|||||||
var free_mem_str: ?[]const u8 = null;
|
var free_mem_str: ?[]const u8 = null;
|
||||||
var available_mem_str: ?[]const u8 = null;
|
var available_mem_str: ?[]const u8 = null;
|
||||||
|
|
||||||
var lines = std.mem.split(u8, meminfo_data, "\n");
|
var lines = std.mem.splitScalar(u8, meminfo_data, '\n');
|
||||||
while (lines.next()) |line| {
|
while (lines.next()) |line| {
|
||||||
const trimmed = std.mem.trim(u8, line, " \t");
|
const trimmed = std.mem.trim(u8, line, " \t");
|
||||||
if (std.mem.startsWith(u8, trimmed, "MemTotal")) {
|
if (std.mem.startsWith(u8, trimmed, "MemTotal")) {
|
||||||
var parts = std.mem.split(u8, trimmed, ":");
|
var parts = std.mem.splitScalar(u8, trimmed, ':');
|
||||||
_ = parts.next(); // discards the key
|
_ = parts.next(); // discards the key
|
||||||
if (parts.next()) |value| {
|
if (parts.next()) |value| {
|
||||||
total_mem_str = std.mem.trim(u8, value[0..(value.len - 3)], " ");
|
total_mem_str = std.mem.trim(u8, value[0..(value.len - 3)], " ");
|
||||||
total_mem = try std.fmt.parseFloat(f64, total_mem_str.?);
|
total_mem = try std.fmt.parseFloat(f64, total_mem_str.?);
|
||||||
}
|
}
|
||||||
} else if (std.mem.startsWith(u8, trimmed, "MemFree")) {
|
} else if (std.mem.startsWith(u8, trimmed, "MemFree")) {
|
||||||
var parts = std.mem.split(u8, trimmed, ":");
|
var parts = std.mem.splitScalar(u8, trimmed, ':');
|
||||||
_ = parts.next(); // discards the key
|
_ = parts.next(); // discards the key
|
||||||
if (parts.next()) |value| {
|
if (parts.next()) |value| {
|
||||||
free_mem_str = std.mem.trim(u8, value[0..(value.len - 3)], " ");
|
free_mem_str = std.mem.trim(u8, value[0..(value.len - 3)], " ");
|
||||||
free_mem = try std.fmt.parseFloat(f64, free_mem_str.?);
|
free_mem = try std.fmt.parseFloat(f64, free_mem_str.?);
|
||||||
}
|
}
|
||||||
} else if (std.mem.startsWith(u8, trimmed, "MemAvailable")) {
|
} else if (std.mem.startsWith(u8, trimmed, "MemAvailable")) {
|
||||||
var parts = std.mem.split(u8, trimmed, ":");
|
var parts = std.mem.splitScalar(u8, trimmed, ':');
|
||||||
_ = parts.next(); // discards the key
|
_ = parts.next(); // discards the key
|
||||||
if (parts.next()) |value| {
|
if (parts.next()) |value| {
|
||||||
available_mem_str = std.mem.trim(u8, value[0..(value.len - 3)], " ");
|
available_mem_str = std.mem.trim(u8, value[0..(value.len - 3)], " ");
|
||||||
|
|||||||
@@ -76,10 +76,10 @@ pub fn getOsInfo(allocator: std.mem.Allocator) ![]u8 {
|
|||||||
|
|
||||||
var pretty_name: ?[]const u8 = null;
|
var pretty_name: ?[]const u8 = null;
|
||||||
|
|
||||||
var lines = std.mem.split(u8, os_release_data, "\n");
|
var lines = std.mem.splitScalar(u8, os_release_data, '\n');
|
||||||
while (lines.next()) |line| {
|
while (lines.next()) |line| {
|
||||||
if (std.mem.startsWith(u8, line, "PRETTY_NAME")) {
|
if (std.mem.startsWith(u8, line, "PRETTY_NAME")) {
|
||||||
var parts = std.mem.split(u8, line, "=");
|
var parts = std.mem.splitScalar(u8, line, '=');
|
||||||
_ = parts.next(); // discard the key
|
_ = parts.next(); // discard the key
|
||||||
if (parts.next()) |value| {
|
if (parts.next()) |value| {
|
||||||
pretty_name = std.mem.trim(u8, value, "\"");
|
pretty_name = std.mem.trim(u8, value, "\"");
|
||||||
|
|||||||
Reference in New Issue
Block a user