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

Maintain order of key with FilterXXX #4

Closed
dotwilbert opened this issue May 11, 2015 · 1 comment
Closed

Maintain order of key with FilterXXX #4

dotwilbert opened this issue May 11, 2015 · 1 comment
Milestone

Comments

@dotwilbert
Copy link

Hi all,

Thanks for sharing your work. I find your package very useful. My properties files must also be edited by administrators. In my program I remove program generated properties and rewrite the properties file. Maintaining the order of the keys and the comments enables a friendlier file for administrators. The comments are transferred using GetComments. I could not find another way to keep the unexpanded property values, except by filtering them.

Currently the order of the keys is not maintained when any of the Filter, FilterRegexp or FilterPrefix is called. A small set of changes in properties.go will enable this.

  // FilterRegexp returns a new properties object which contains all properties
  // 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
  }

  // FilterPrefix returns a new properties object which contains all 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
  }

Thanks,

Wilbert

@magiconair
Copy link
Owner

Thanks Wilbert for finding this. I've added your change and tagged version v1.5.3 with it.

@magiconair magiconair added this to the 1.5.3 milestone Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants