Skip to content

Commit

Permalink
use rune for separator instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ryotafuwa-dev committed Jul 23, 2024
1 parent 0ff4033 commit 4fd9161
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions hcledit.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (h *HCLEditor) Create(queryStr string, value interface{}, opts ...Option) e
defer h.reload()

opt := &option{
querySeparator: ".",
querySeparator: '.',
}
for _, optFunc := range opts {
optFunc(opt)
Expand Down Expand Up @@ -81,7 +81,7 @@ func (h *HCLEditor) Read(queryStr string, opts ...Option) (map[string]interface{
defer h.reload()

opt := &option{
querySeparator: ".",
querySeparator: '.',
}
for _, optFunc := range opts {
optFunc(opt)
Expand Down Expand Up @@ -127,7 +127,7 @@ func (h *HCLEditor) Update(queryStr string, value interface{}, opts ...Option) e
defer h.reload()

opt := &option{
querySeparator: ".",
querySeparator: '.',
}
for _, optFunc := range opts {
optFunc(opt)
Expand Down Expand Up @@ -170,7 +170,7 @@ func (h *HCLEditor) Delete(queryStr string, opts ...Option) error {
defer h.reload()

opt := &option{
querySeparator: ".",
querySeparator: '.',
}
for _, optFunc := range opts {
optFunc(opt)
Expand Down
2 changes: 1 addition & 1 deletion hcledit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ object = {
}
`,
query: "object|attribute3.value",
opts: []hcledit.Option{hcledit.WithQuerySeparator("|")},
opts: []hcledit.Option{hcledit.WithQuerySeparator('|')},
value: "D",
want: `
object = {
Expand Down
4 changes: 2 additions & 2 deletions internal/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func (c *queryWildcard) Key() string {
return "*"
}

func Build(src, querySeparator string) ([]Query, error) {
func Build(src string, querySeparator rune) ([]Query, error) {
var queries []Query
for _, q := range strings.Split(src, querySeparator) {
for _, q := range strings.Split(src, string([]rune{querySeparator})) {
if q == "*" {
queries = append(queries, &queryWildcard{})
} else {
Expand Down
6 changes: 3 additions & 3 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type option struct {
afterKey string
beforeNewline bool
readFallbackToRawString bool
querySeparator string
querySeparator rune
}

// Option configures specific behavior for specific HCLEditor operations.
Expand Down Expand Up @@ -43,8 +43,8 @@ func WithReadFallbackToRawString() Option {
}

// This sets a separator for queryStr in HCLEditor funcs. The default separator is ".".
func WithQuerySeparator(chr string) Option {
func WithQuerySeparator(r rune) Option {
return func(opt *option) {
opt.querySeparator = chr
opt.querySeparator = r
}
}
2 changes: 1 addition & 1 deletion option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ object = {
}
`,
exec: func(editor *hcledit.HCLEditor) error {
return editor.Create("object/attribute", "str", hcledit.WithQuerySeparator("/"))
return editor.Create("object/attribute", "str", hcledit.WithQuerySeparator('/'))
},
want: `
object = {
Expand Down

0 comments on commit 4fd9161

Please sign in to comment.