浏览代码

Merge pull request #681 from ralph-the-mighty/stringwidth

Control %s width in fmt.print* functions
gingerBill 5 年之前
父节点
当前提交
a6ff48a5de
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      core/fmt/fmt.odin

+ 5 - 0
core/fmt/fmt.odin

@@ -898,6 +898,11 @@ fmt_string :: proc(fi: ^Info, s: string, verb: rune) {
 	switch verb {
 	case 's', 'v':
 		strings.write_string(fi.buf, s);
+		if fi.width_set && len(s) < fi.width {
+			for i in 0..<fi.width - len(s) {
+				strings.write_byte(fi.buf, ' ');
+			}
+		}
 
 	case 'q': // quoted string
 		strings.write_quoted_string(fi.buf, s, '"');