Skip to content

Commit

Permalink
note in the readme and flag that trimprefix accepts lists
Browse files Browse the repository at this point in the history
  • Loading branch information
samiam2013 committed Oct 3, 2024
1 parent 870b5b9 commit 0712904
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ Possible transform values are listed above in the [transformers](#transformers)
The default value for `transform` flag is `noop` which means no transformation will be performed.

If a prefix is provided via the `trimprefix` flag, it will be trimmed from the start of each name (before
it is transformed). If a name doesn't have the prefix it will be passed unchanged.
it is transformed). You can trim multiple prefixes by passing a comma separated list.
If a name doesn't have the prefix it will be passed unchanged.

If a prefix is provided via the `addprefix` flag, it will be added to the start of each name (after trimming and after transforming).

Expand Down
16 changes: 8 additions & 8 deletions stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var (
altValuesFunc = flag.Bool("values", false, "if true, alternative string values method will be generated. Default: false")
output = flag.String("output", "", "output file name; default srcdir/<type>_string.go")
transformMethod = flag.String("transform", "noop", "enum item name transformation method. Default: noop")
trimPrefix = flag.String("trimprefix", "", "transform each item name by removing a prefix. Default: \"\"")
trimPrefix = flag.String("trimprefix", "", "transform each item name by removing a prefix or comma separated list. Default: \"\"")
addPrefix = flag.String("addprefix", "", "transform each item name by adding a prefix. Default: \"\"")
linecomment = flag.Bool("linecomment", false, "use line comment text as printed text when present")
)
Expand Down Expand Up @@ -774,9 +774,9 @@ func (g *Generator) buildOneRun(runs [][]Value, typeName string) {
}

// Arguments to format are:
// [1]: type name
// [2]: size of index element (8 for uint8 etc.)
// [3]: less than zero check (for signed types)
// [1]: type name
// [2]: size of index element (8 for uint8 etc.)
// [3]: less than zero check (for signed types)
const stringOneRun = `func (i %[1]s) String() string {
if %[3]si >= %[1]s(len(_%[1]sIndex)-1) {
return fmt.Sprintf("%[1]s(%%d)", i)
Expand All @@ -786,10 +786,10 @@ const stringOneRun = `func (i %[1]s) String() string {
`

// Arguments to format are:
// [1]: type name
// [2]: lowest defined value for type, as a string
// [3]: size of index element (8 for uint8 etc.)
// [4]: less than zero check (for signed types)
// [1]: type name
// [2]: lowest defined value for type, as a string
// [3]: size of index element (8 for uint8 etc.)
// [4]: less than zero check (for signed types)
const stringOneRunWithOffset = `func (i %[1]s) String() string {
i -= %[2]s
if %[4]si >= %[1]s(len(_%[1]sIndex)-1) {
Expand Down

0 comments on commit 0712904

Please sign in to comment.