Skip to content

Commit

Permalink
Maintain order of keys for Filter methods
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Jun 1, 2015
1 parent d5929c6 commit 6240095
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ $ go get -u gopkg.in/check.v1
History
-------

v1.5.3, 02 Jun 2015
-------------------
* [Issue #4](https://github.com/magiconair/properties/issues/4): Maintain key order in [Filter()](http://godoc.org/github.com/magiconair/properties#Properties.Filter), [FilterPrefix()](http://godoc.org/github.com/magiconair/properties#Properties.FilterPrefix) and [FilterRegexp()](http://godoc.org/github.com/magiconair/properties#Properties.FilterRegexp)

v1.5.2, 10 Apr 2015
-------------------
* [Issue #3](https://github.com/magiconair/properties/issues/3): Don't print comments in [WriteComment()](http://godoc.org/github.com/magiconair/properties#Properties.WriteComment) if they are all empty
Expand Down
8 changes: 4 additions & 4 deletions properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ func (p *Properties) Filter(pattern string) (*Properties, error) {
// for which the key matches the regular expression.
func (p *Properties) FilterRegexp(re *regexp.Regexp) *Properties {
pp := NewProperties()
for k, v := range p.m {
for _, k := range p.k {
if re.MatchString(k) {
pp.Set(k, v)
pp.Set(k, p.m[k])
}
}
return pp
Expand All @@ -437,9 +437,9 @@ func (p *Properties) FilterRegexp(re *regexp.Regexp) *Properties {
// for which the key starts with the prefix.
func (p *Properties) FilterPrefix(prefix string) *Properties {
pp := NewProperties()
for k, v := range p.m {
for _, k := range p.k {
if strings.HasPrefix(k, prefix) {
pp.Set(k, v)
pp.Set(k, p.m[k])
}
}
return pp
Expand Down

0 comments on commit 6240095

Please sign in to comment.