Skip to content

Commit aa194e8

Browse files
authored
remove comments
1 parent 42ff055 commit aa194e8

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

object/strings.go

+1-20
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,12 @@ func (s *String) format(args []Object) Object {
9696
return &String{Value: value}
9797
}
9898

99-
// Format the string like "Hello {0}", jina ...
10099
func formatStr(format string, options []Object) (string, error) {
101100
var str strings.Builder
102101
var val strings.Builder
103102
var check_val bool
104103
var opts_len int = len(options)
105104

106-
// This is to enable escaping the {} braces if you want them included
107105
var escapeChar bool
108106

109107
type optM struct {
@@ -113,13 +111,10 @@ func formatStr(format string, options []Object) (string, error) {
113111

114112
var optionsMap = make(map[int]optM, opts_len)
115113

116-
// convert the options into a map (may not be the most efficient but we are not going fast)
117114
for i, optm := range options {
118115
optionsMap[i] = optM{val: false, obj: optm}
119116
}
120117

121-
// Now go through the format string and do the replacement(s)
122-
// this has approx time complexity of O(n) (bestest case)
123118
for _, opt := range format {
124119

125120
if !escapeChar && opt == '\\' {
@@ -140,12 +135,9 @@ func formatStr(format string, options []Object) (string, error) {
140135
}
141136

142137
if check_val && opt == '}' {
143-
vstr := strings.TrimSpace(val.String()) // remove accidental spaces
144-
145-
// check the value and try to convert to int
138+
vstr := strings.TrimSpace(val.String())
146139
arrv, err := strconv.Atoi(vstr)
147140
if err != nil {
148-
// return non-cryptic go errors
149141
return "", fmt.Errorf(fmt.Sprintf("Ulichopeana si NAMBA, jaribu tena: `%s'", vstr))
150142
}
151143

@@ -156,7 +148,6 @@ func formatStr(format string, options []Object) (string, error) {
156148
}
157149

158150
str.WriteString(oVal.obj.Inspect())
159-
// may be innefficient
160151
optionsMap[arrv] = optM{val: true, obj: oVal.obj}
161152

162153
check_val = false
@@ -172,25 +163,15 @@ func formatStr(format string, options []Object) (string, error) {
172163
str.WriteRune(opt)
173164
}
174165

175-
// A check if they never closed the formatting braces e.g '{0'
176166
if check_val {
177167
return "", fmt.Errorf(fmt.Sprintf("Haukufunga '{', tuliokota kabla ya kufika mwisho `%s'", val.String()))
178168
}
179169

180-
// Another innefficient loop
181170
for _, v := range optionsMap {
182171
if !v.val {
183172
return "", fmt.Errorf(fmt.Sprintf("Ulipeana hili chaguo (%s) {%s} lakini haukutumia", v.obj.Inspect(), v.obj.Type()))
184173
}
185174
}
186175

187-
// !start
188-
// Here we can talk about wtf just happened
189-
// 3 loops to do just formatting, formatting for codes sake.
190-
// it can be done in 2 loops, the last one is just to confirm that you didn't forget anything.
191-
// this is not required but a nice syntatic sugar, we are not here for speed, so ergonomics matter instead of speed
192-
// finally we can say we are slower than python!, what an achievement
193-
// done!
194-
195176
return str.String(), nil
196177
}

0 commit comments

Comments
 (0)