| ... | @@ -46,6 +46,11 @@ pub fn trimPrefix(in: string, prefix: string) string { | ... | @@ -46,6 +46,11 @@ pub fn trimPrefix(in: string, prefix: string) string { |
| 46 | return in; | 46 | return in; |
| 47 | } | 47 | } |
| 48 | | 48 | |
| | 49 | pub fn trimPrefixEnsure(in: string, prefix: string) ?string { |
| | 50 | if (!std.mem.startsWith(u8, in, prefix)) return null; |
| | 51 | return in[prefix.len..]; |
| | 52 | } |
| | 53 | |
| 49 | pub fn trimSuffix(in: string, suffix: string) string { | 54 | pub fn trimSuffix(in: string, suffix: string) string { |
| 50 | if (std.mem.endsWith(u8, in, suffix)) { | 55 | if (std.mem.endsWith(u8, in, suffix)) { |
| 51 | return in[0 .. in.len - suffix.len]; | 56 | return in[0 .. in.len - suffix.len]; |
| ... | @@ -53,6 +58,11 @@ pub fn trimSuffix(in: string, suffix: string) string { | ... | @@ -53,6 +58,11 @@ pub fn trimSuffix(in: string, suffix: string) string { |
| 53 | return in; | 58 | return in; |
| 54 | } | 59 | } |
| 55 | | 60 | |
| | 61 | pub fn trimSuffixEnsure(in: string, suffix: string) ?string { |
| | 62 | if (!std.mem.endsWith(u8, in, suffix)) return null; |
| | 63 | return in[0 .. in.len - suffix.len]; |
| | 64 | } |
| | 65 | |
| 56 | pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string { | 66 | pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string { |
| 57 | const base64 = std.base64.standard.Encoder; | 67 | const base64 = std.base64.standard.Encoder; |
| 58 | var buf = try alloc.alloc(u8, base64.calcSize(input.len)); | 68 | var buf = try alloc.alloc(u8, base64.calcSize(input.len)); |