| ... | ... | @@ -101,6 +101,7 @@ pub const OutStream = struct { |
| 101 | 101 | CloseBrace, |
| 102 | 102 | Integer, |
| 103 | 103 | IntegerWidth, |
| 104 | Character, |
| 104 | 105 | }; |
| 105 | 106 | |
| 106 | 107 | /// Calls print and then flushes the buffer. |
| ... | ... | @@ -155,6 +156,9 @@ pub const OutStream = struct { |
| 155 | 156 | width = 0; |
| 156 | 157 | state = State.Integer; |
| 157 | 158 | }, |
| 159 | 'c' => { |
| 160 | state = State.Character; |
| 161 | }, |
| 158 | 162 | else => @compileError("Unknown format character: " ++ []u8{c}), |
| 159 | 163 | }, |
| 160 | 164 | State.CloseBrace => switch (c) { |
| ... | ... | @@ -188,6 +192,15 @@ pub const OutStream = struct { |
| 188 | 192 | '0' ... '9' => {}, |
| 189 | 193 | else => @compileError("Unexpected character in format string: " ++ []u8{c}), |
| 190 | 194 | }, |
| 195 | State.Character => switch (c) { |
| 196 | '}' => { |
| 197 | self.printAsciiChar(args[next_arg]); |
| 198 | next_arg += 1; |
| 199 | state = State.Start; |
| 200 | start_index = i + 1; |
| 201 | }, |
| 202 | else => @compileError("Unexpected character in format string: " ++ []u8{c}), |
| 203 | }, |
| 191 | 204 | } |
| 192 | 205 | } |
| 193 | 206 | comptime { |
| ... | ... | @@ -228,6 +241,14 @@ pub const OutStream = struct { |
| 228 | 241 | self.index += amt_printed; |
| 229 | 242 | } |
| 230 | 243 | |
| 244 | pub fn printAsciiChar(self: &OutStream, c: u8) -> %void { |
| 245 | if (self.index + 1 >= self.buffer.len) { |
| 246 | %return self.flush(); |
| 247 | } |
| 248 | self.buffer[self.index] = c; |
| 249 | self.index += 1; |
| 250 | } |
| 251 | |
| 231 | 252 | pub fn flush(self: &OutStream) -> %void { |
| 232 | 253 | while (true) { |
| 233 | 254 | const write_ret = system.write(self.fd, &self.buffer[0], self.index); |