aboutsummaryrefslogtreecommitdiff
path: root/system.old/libraries/string/builder.zig
diff options
context:
space:
mode:
Diffstat (limited to 'system.old/libraries/string/builder.zig')
-rw-r--r--system.old/libraries/string/builder.zig48
1 files changed, 48 insertions, 0 deletions
diff --git a/system.old/libraries/string/builder.zig b/system.old/libraries/string/builder.zig
new file mode 100644
index 0000000..16bd35c
--- /dev/null
+++ b/system.old/libraries/string/builder.zig
@@ -0,0 +1,48 @@
+//! String building
+
+pub fn build(buf: []u8, parts: anytype) []const u8 {
+ var pos: usize = 0;
+ inline for (parts) |part| {
+ for (part) |c| {
+ if (pos >= buf.len) break;
+ buf[pos] = c;
+ pos += 1;
+ }
+ }
+ return buf[0..pos];
+}
+
+pub fn concat(buf: []u8, a: []const u8, b: []const u8) []const u8 {
+ var pos: usize = 0;
+ for (a) |c| {
+ if (pos >= buf.len) break;
+ buf[pos] = c;
+ pos += 1;
+ }
+ for (b) |c| {
+ if (pos >= buf.len) break;
+ buf[pos] = c;
+ pos += 1;
+ }
+ return buf[0..pos];
+}
+
+pub fn concat3(buf: []u8, a: []const u8, b: []const u8, c: []const u8) []const u8 {
+ var pos: usize = 0;
+ for (a) |ch| {
+ if (pos >= buf.len) break;
+ buf[pos] = ch;
+ pos += 1;
+ }
+ for (b) |ch| {
+ if (pos >= buf.len) break;
+ buf[pos] = ch;
+ pos += 1;
+ }
+ for (c) |ch| {
+ if (pos >= buf.len) break;
+ buf[pos] = ch;
+ pos += 1;
+ }
+ return buf[0..pos];
+}