From df03765560272c79065dce167c1124a9a3b0865e Mon Sep 17 00:00:00 2001 From: andgrew Date: Tue, 4 Dec 2018 08:56:57 +0300 Subject: [PATCH 1/3] add c variant for old str formatting --- grumpy-runtime-src/runtime/str.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/grumpy-runtime-src/runtime/str.go b/grumpy-runtime-src/runtime/str.go index 9b56ed18..78809b38 100644 --- a/grumpy-runtime-src/runtime/str.go +++ b/grumpy-runtime-src/runtime/str.go @@ -1181,6 +1181,13 @@ func strMod(f *Frame, v, args *Object) (*Object, *BaseException) { val = strLeftPad(val, fieldWidth, fillchar) } buf.WriteString(val) + case "c": + if value.isInstance(IntType) { + val = string(toIntUnsafe(value).Value()) + } else { + val = toStrUnsafe(value).Value() + } + buf.WriteString(val) case "%": val = "%" if fieldWidth > 0 { From 14ae8d50524d5d5c549e08c12c4f44c547a8ac2e Mon Sep 17 00:00:00 2001 From: wind Date: Tue, 4 Dec 2018 23:26:47 +0300 Subject: [PATCH 2/3] fix gofmt for str.go --- grumpy-runtime-src/runtime/str.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/grumpy-runtime-src/runtime/str.go b/grumpy-runtime-src/runtime/str.go index 78809b38..571e708d 100644 --- a/grumpy-runtime-src/runtime/str.go +++ b/grumpy-runtime-src/runtime/str.go @@ -1182,12 +1182,12 @@ func strMod(f *Frame, v, args *Object) (*Object, *BaseException) { } buf.WriteString(val) case "c": - if value.isInstance(IntType) { - val = string(toIntUnsafe(value).Value()) - } else { - val = toStrUnsafe(value).Value() - } - buf.WriteString(val) + if value.isInstance(IntType) { + val = string(toIntUnsafe(value).Value()) + } else { + val = toStrUnsafe(value).Value() + } + buf.WriteString(val) case "%": val = "%" if fieldWidth > 0 { From b97ac546648297b8584c8c2f81ced00f2cc5748f Mon Sep 17 00:00:00 2001 From: wind Date: Wed, 5 Dec 2018 11:56:30 +0300 Subject: [PATCH 3/3] test for c variant --- grumpy-runtime-src/testing/str_test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grumpy-runtime-src/testing/str_test.py b/grumpy-runtime-src/testing/str_test.py index 92e7236f..0d47b032 100644 --- a/grumpy-runtime-src/testing/str_test.py +++ b/grumpy-runtime-src/testing/str_test.py @@ -369,3 +369,6 @@ def __int__(self): assert '%o' % 8 == '10' assert '%o' % -8 == '-10' assert '%o %o' % (8, -8) == '10 -10' + +assert '%c' % 107 == 'k' +assert '%c' % 'k' == 'k'