"errors"
"fmt"
"html/template"
- "math"
_strings "strings"
"unicode/utf8"
}
// Repeat returns a new string consisting of count copies of the string s.
-// The count is limited to an in16 value (up to 32767).
func (ns *Namespace) Repeat(n, s interface{}) (string, error) {
ss, err := cast.ToStringE(s)
if err != nil {
return "", err
}
- if sn > math.MaxInt16 {
- return "", fmt.Errorf("Cannot repeat string more than %d times", math.MaxInt16)
+ if sn < 0 {
+ return "", errors.New("strings: negative Repeat count")
+ } else if sn > 0 && len(ss)*sn/sn != len(ss) {
+ return "", errors.New("strings: Repeat count causes overflow")
}
return _strings.Repeat(ss, sn), nil
// errors
{"", tstNoStringer{}, false},
{tstNoStringer{}, "", false},
- {"hi", math.MaxInt16 + 1, false},
+ {"ab", math.MaxInt64, false},
} {
errMsg := fmt.Sprintf("[%d] %v", i, test)