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

go/constant: stringVal.String truncates final quotation mark #14261

Closed
alandonovan opened this issue Feb 8, 2016 · 1 comment
Closed

go/constant: stringVal.String truncates final quotation mark #14261

alandonovan opened this issue Feb 8, 2016 · 1 comment

Comments

@alandonovan
Copy link
Contributor

% cat a.go
package main

import (
        "fmt"
        "go/token"
        "go/types"
        "log"
)

func main() {
        fset := token.NewFileSet()
        tv, err := types.Eval(fset, nil, 0, `"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"`)
        if err != nil {
                log.Fatal(err)
        }
        fmt.Println(tv.Value.String())
}
% go run a.go
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
@griesemer
Copy link
Contributor

This is working as intended: The output of value.String() may be shortened:

    // String returns a short, human-readable form of the value.
    // For numeric values, the result may be an approximation;
    // for String values the result may be a shortened string.
    // Use ExactString for a string representing a value exactly.
    String() string

The reason we print a shortened string w/o closing quote (e.g.: "xxxxx...) is so we can tell it apart from an actual (not shortened) string (here: "xxxxx...").

Use ExactString() to get the complete string. (i.e., String() is a short form for human readable output).

@golang golang locked and limited conversation to collaborators Feb 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants