Skip to content

Commit 49bcc8f

Browse files
committed
Rudimentary string % operator
1 parent b686bb2 commit 49bcc8f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

py/string.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package py
1010

1111
import (
12+
"fmt"
1213
"unicode/utf8"
1314
)
1415

@@ -137,8 +138,37 @@ func (a String) M__ge__(other Object) Object {
137138
return NotImplemented
138139
}
139140

141+
// % operator
142+
143+
func (a String) M__mod__(other Object) Object {
144+
var values Tuple
145+
switch b := other.(type) {
146+
case Tuple:
147+
values = b
148+
default:
149+
values = Tuple{other}
150+
}
151+
// FIXME not a full implementation ;-)
152+
return String(fmt.Sprintf("%s %#v", a, values))
153+
}
154+
155+
func (a String) M__rmod__(other Object) Object {
156+
switch b := other.(type) {
157+
case String:
158+
return b.M__mod__(a)
159+
}
160+
return NotImplemented
161+
}
162+
163+
func (a String) M__imod__(other Object) Object {
164+
return a.M__mod__(other)
165+
}
166+
140167
// Check stringerface is satisfied
141168
var _ richComparison = String("")
142169
var _ sequenceArithmetic = String("")
170+
var _ I__mod__ = String("")
171+
var _ I__rmod__ = String("")
172+
var _ I__imod__ = String("")
143173
var _ I__len__ = String("")
144174
var _ I__bool__ = String("")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy