Skip to content

Commit 6240095

Browse files
committed
Maintain order of keys for Filter methods
#4
1 parent d5929c6 commit 6240095

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ $ go get -u gopkg.in/check.v1
5353
History
5454
-------
5555

56+
v1.5.3, 02 Jun 2015
57+
-------------------
58+
* [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)
59+
5660
v1.5.2, 10 Apr 2015
5761
-------------------
5862
* [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

properties.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,9 @@ func (p *Properties) Filter(pattern string) (*Properties, error) {
425425
// for which the key matches the regular expression.
426426
func (p *Properties) FilterRegexp(re *regexp.Regexp) *Properties {
427427
pp := NewProperties()
428-
for k, v := range p.m {
428+
for _, k := range p.k {
429429
if re.MatchString(k) {
430-
pp.Set(k, v)
430+
pp.Set(k, p.m[k])
431431
}
432432
}
433433
return pp
@@ -437,9 +437,9 @@ func (p *Properties) FilterRegexp(re *regexp.Regexp) *Properties {
437437
// for which the key starts with the prefix.
438438
func (p *Properties) FilterPrefix(prefix string) *Properties {
439439
pp := NewProperties()
440-
for k, v := range p.m {
440+
for _, k := range p.k {
441441
if strings.HasPrefix(k, prefix) {
442-
pp.Set(k, v)
442+
pp.Set(k, p.m[k])
443443
}
444444
}
445445
return pp

0 commit comments

Comments
 (0)