Skip to content

Commit e6e6ead

Browse files
authored
Merge pull request #130 from andgrew/master
add c variant for old str formatting
2 parents 5d6673c + b97ac54 commit e6e6ead

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

grumpy-runtime-src/runtime/str.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,13 @@ func strMod(f *Frame, v, args *Object) (*Object, *BaseException) {
11811181
val = strLeftPad(val, fieldWidth, fillchar)
11821182
}
11831183
buf.WriteString(val)
1184+
case "c":
1185+
if value.isInstance(IntType) {
1186+
val = string(toIntUnsafe(value).Value())
1187+
} else {
1188+
val = toStrUnsafe(value).Value()
1189+
}
1190+
buf.WriteString(val)
11841191
case "%":
11851192
val = "%"
11861193
if fieldWidth > 0 {

grumpy-runtime-src/testing/str_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,6 @@ def __int__(self):
369369
assert '%o' % 8 == '10'
370370
assert '%o' % -8 == '-10'
371371
assert '%o %o' % (8, -8) == '10 -10'
372+
373+
assert '%c' % 107 == 'k'
374+
assert '%c' % 'k' == 'k'

0 commit comments

Comments
 (0)