tiny.smg.text
Defined in tiny.smg.
API (15)
Actions
Public operations.
basenamecontainsIgnoreCaseeqlIgnoreCasekeyValueparseIntreadFilereadFileZreplaceSeparatorsshellQuotestartsWordtrimwithoutExtensionwriteFile
Types and contracts
Public types and contracts.
Namespaces
Public namespaces.
Source
Source: tools/smg/src/text/pair.zig:3
zig
pub const Error = error{ InvalidArgument,};Source: tools/smg/src/text/case.zig:3
zig
pub fn containsIgnoreCase(haystack: []const u8, needle: []const u8) bool { if (needle.len == 0) return true; if (needle.len > haystack.len) return false; var i: usize = 0; while (i + needle.len <= haystack.len) : (i += 1) { var ok = true; for (needle, 0..) |byte, j| { if (std.ascii.toLower(haystack[i + j]) != std.ascii.toLower(byte)) { ok = false; break; } } if (ok) return true; } return false;}Source: tools/smg/src/text/case.zig:20
zig
pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool { return std.ascii.eqlIgnoreCase(a, b);}Source: tools/smg/src/text/file.zig:8
zig
pub fn readFile(allocator: std.mem.Allocator, path: []const u8, limit: usize) ![]const u8 { return try std.Io.Dir.cwd().readFileAlloc(std.Options.debug_io, path, allocator, .limited(limit));}Source: tools/smg/src/text/file.zig:12
zig
pub fn readFileZ(allocator: std.mem.Allocator, path: []const u8, limit: usize) ![:0]const u8 { return try std.Io.Dir.cwd().readFileAllocOptions(std.Options.debug_io, path, allocator, .limited(limit), .of(u8), 0);}Source: tools/smg/src/text/file.zig:3
zig
pub fn writeFile(path: []const u8, data: []const u8) !void { if (std.fs.path.dirname(path)) |dir| try std.Io.Dir.cwd().createDirPath(std.Options.debug_io, dir); try std.Io.Dir.cwd().writeFile(std.Options.debug_io, .{ .sub_path = path, .data = data, .flags = .{ .truncate = true } });}Source: tools/smg/src/text/number.zig:3
zig
pub fn parseInt(value: []const u8, default: i64) i64 { return std.fmt.parseInt(i64, value, 10) catch default;}Source: tools/smg/src/text/pair.zig:7
zig
pub fn keyValue(allocator: std.mem.Allocator, raw: []const u8) !struct { key: []const u8, value: []const u8 } { const eq = std.mem.indexOfScalar(u8, raw, '=') orelse return Error.InvalidArgument; const key = try allocator.dupe(u8, raw[0..eq]); errdefer allocator.free(key); const value = try allocator.dupe(u8, raw[eq + 1 ..]); return .{ .key = key, .value = value, };}Source: tools/smg/src/text/path.zig:3
zig
pub fn basename(path: []const u8) []const u8 { var end = path.len; while (end > 0 and (path[end - 1] == '/' or path[end - 1] == '\\')) end -= 1; var start = end; while (start > 0 and path[start - 1] != '/' and path[start - 1] != '\\') start -= 1; return path[start..end];}Source: tools/smg/src/text/path.zig:17
zig
pub fn replaceSeparators(allocator: std.mem.Allocator, value: []const u8, replacement: u8) ![]const u8 { const out = try allocator.dupe(u8, value); for (out) |*byte| { if (byte.* == '/' or byte.* == '\\') byte.* = replacement; } return out;}Source: tools/smg/src/text/path.zig:11
zig
pub fn withoutExtension(path: []const u8) []const u8 { const base = basename(path); if (std.mem.lastIndexOfScalar(u8, base, '.')) |dot| return base[0..dot]; return base;}Source: tools/smg/src/text/shell.zig:3
zig
pub fn shellQuote(allocator: std.mem.Allocator, value: []const u8) ![]const u8 { var out: std.Io.Writer.Allocating = .init(allocator); errdefer out.deinit(); try out.writer.writeByte('\''); for (value) |byte| { if (byte == '\'') { try out.writer.writeAll("'\\''"); } else { try out.writer.writeByte(byte); } } try out.writer.writeByte('\''); return try out.toOwnedSlice();}Source: tools/smg/src/text/space.zig:7
zig
pub fn startsWord(value: []const u8, prefix: []const u8) bool { if (!std.mem.startsWith(u8, value, prefix)) return false; if (value.len == prefix.len) return true; const byte = value[prefix.len]; return byte == ' ' or byte == '\t';}Source: tools/smg/src/text/space.zig:3
zig
pub fn trim(value: []const u8) []const u8 { return std.mem.trim(u8, value, " \t\r\n");}Source: tools/smg/src/root.zig:34
zig
pub const text = @import("text/root.zig");Source: tools/smg/src/text/root.zig
zig
const case = @import("case.zig");const file = @import("file.zig");const number = @import("number.zig");const pair = @import("pair.zig");const path = @import("path.zig");const shell = @import("shell.zig");const space = @import("space.zig");pub const list = @import("list.zig");pub const Error = pair.Error;pub const basename = path.basename;pub const containsIgnoreCase = case.containsIgnoreCase;pub const eqlIgnoreCase = case.eqlIgnoreCase;pub const keyValue = pair.keyValue;pub const parseInt = number.parseInt;pub const readFile = file.readFile;pub const readFileZ = file.readFileZ;pub const replaceSeparators = path.replaceSeparators;pub const shellQuote = shell.shellQuote;pub const startsWord = space.startsWord;pub const trim = space.trim;pub const withoutExtension = path.withoutExtension;pub const writeFile = file.writeFile;Audit
| Definitions | 15 |
|---|---|
| Public names | 15 |
| Members | 1 |
| Version | 26.7.0 |
| Revision | daab053ee433 |