Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have string marshaling methods be value receivers rather than pointer… #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ before_script:
- ./testdata/dectest/generate.bash
- ./testdata/pytables/generate.bash
- GO_FILES=$(find . -type f -iname '*.go')
- go get -u -t ./...
- go mod download

script:
- test -z $(gofmt -s -l $GO_FILES)
Expand Down
30 changes: 12 additions & 18 deletions big.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func (x *Big) Float(z *big.Float) *big.Float {
//
// %+v, %#v, %T, %#p, and %p all honor the formats specified in the fmt
// package's documentation.
func (x *Big) Format(s fmt.State, c rune) {
func (x Big) Format(s fmt.State, c rune) {
if debug {
x.validate()
}
Expand Down Expand Up @@ -606,7 +606,7 @@ func (x *Big) Format(s fmt.State, c rune) {
const noE = 0
switch c {
case 's', 'd':
f.format(x, normal, e)
f.format(&x, normal, e)
case 'q':
// The fmt package's docs specify that the '+' flag
// "guarantee[s] ASCII-only output for %q (%+q)"
Expand All @@ -619,10 +619,10 @@ func (x *Big) Format(s fmt.State, c rune) {
quote = '`'
}
f.WriteByte(quote)
f.format(x, normal, e)
f.format(&x, normal, e)
f.WriteByte(quote)
case 'e', 'E':
f.format(x, sci, byte(c))
f.format(&x, sci, byte(c))
case 'f', 'F':
if !hasPrec {
prec = 0
Expand All @@ -639,16 +639,16 @@ func (x *Big) Format(s fmt.State, c rune) {
}
}

f.format(x, plain, noE)
f.format(&x, plain, noE)
case 'g', 'G':
// %g's precision means "number of significant digits"
f.format(x, plain, noE)
f.format(&x, plain, noE)

// Make sure we return from the following two cases.
case 'v':
// %v == %s
if !hash && !plus {
f.format(x, normal, e)
f.format(&x, normal, e)
break
}

Expand Down Expand Up @@ -676,7 +676,7 @@ func (x *Big) Format(s fmt.State, c rune) {
} else if space {
specs += " "
}
fmt.Fprintf(s, "%"+specs+"v", (*Big)(x))
fmt.Fprintf(s, "%"+specs+"v", Big(x))
return
default:
fmt.Fprintf(s, "%%!%c(*decimal.Big=%s)", c, x.String())
Expand Down Expand Up @@ -871,20 +871,17 @@ func (x *Big) IsInt() bool {
}

// MarshalText implements encoding.TextMarshaler.
func (x *Big) MarshalText() ([]byte, error) {
func (x Big) MarshalText() ([]byte, error) {
if debug {
x.validate()
}
if x == nil {
return []byte("<nil>"), nil
}
var (
b = new(bytes.Buffer)
f = formatter{w: b, prec: x.Precision(), width: noWidth}
e = sciE[x.Context.OperatingMode]
)
b.Grow(x.Precision())
f.format(x, normal, e)
f.format(&x, normal, e)
return b.Bytes(), nil
}

Expand Down Expand Up @@ -1372,17 +1369,14 @@ func (x *Big) Signbit() bool {
// String returns the string representation of x. It's equivalent to the %s verb
// discussed in the Format method's documentation. Special cases depend on the
// OperatingMode.
func (x *Big) String() string {
if x == nil {
return "<nil>"
}
func (x Big) String() string {
var (
b = new(strings.Builder)
f = formatter{w: b, prec: x.Precision(), width: noWidth}
e = sciE[x.Context.OperatingMode]
)
b.Grow(x.Precision())
f.format(x, normal, e)
f.format(&x, normal, e)
return b.String()
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/pytables/tables.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python3

from decimal import *
import gzip
Expand Down