| ... | @@ -101,6 +101,7 @@ pub const OutStream = struct { | ... | @@ -101,6 +101,7 @@ pub const OutStream = struct { |
| 101 | CloseBrace, | 101 | CloseBrace, |
| 102 | Integer, | 102 | Integer, |
| 103 | IntegerWidth, | 103 | IntegerWidth, |
| | 104 | Character, |
| 104 | }; | 105 | }; |
| 105 | | 106 | |
| 106 | /// Calls print and then flushes the buffer. | 107 | /// Calls print and then flushes the buffer. |
| ... | @@ -155,6 +156,9 @@ pub const OutStream = struct { | ... | @@ -155,6 +156,9 @@ pub const OutStream = struct { |
| 155 | width = 0; | 156 | width = 0; |
| 156 | state = State.Integer; | 157 | state = State.Integer; |
| 157 | }, | 158 | }, |
| | 159 | 'c' => { |
| | 160 | state = State.Character; |
| | 161 | }, |
| 158 | else => @compileError("Unknown format character: " ++ []u8{c}), | 162 | else => @compileError("Unknown format character: " ++ []u8{c}), |
| 159 | }, | 163 | }, |
| 160 | State.CloseBrace => switch (c) { | 164 | State.CloseBrace => switch (c) { |
| ... | @@ -188,6 +192,15 @@ pub const OutStream = struct { | ... | @@ -188,6 +192,15 @@ pub const OutStream = struct { |
| 188 | '0' ... '9' => {}, | 192 | '0' ... '9' => {}, |
| 189 | else => @compileError("Unexpected character in format string: " ++ []u8{c}), | 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 | comptime { | 206 | comptime { |
| ... | @@ -228,6 +241,14 @@ pub const OutStream = struct { | ... | @@ -228,6 +241,14 @@ pub const OutStream = struct { |
| 228 | self.index += amt_printed; | 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 | pub fn flush(self: &OutStream) -> %void { | 252 | pub fn flush(self: &OutStream) -> %void { |
| 232 | while (true) { | 253 | while (true) { |
| 233 | const write_ret = system.write(self.fd, &self.buffer[0], self.index); | 254 | const write_ret = system.write(self.fd, &self.buffer[0], self.index); |