Ignore:
Timestamp:
May 11, 2007, 10:13:00 PM (14 years ago)
Author:
Peter Johansson
Message:

Sorting authors in copyright statement in same order as stated in config file. fixes #172

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Configuration.cc

    r289 r303  
    3131#include <string>
    3232#include <sstream>
     33#include <stdexcept>
    3334#include <utility>
    3435
     
    4142  Configuration::Configuration(void)
    4243  {
     44  }
     45
     46
     47  const std::map<std::string,Alias>& Configuration::copyright_alias(void) const
     48  {
     49    return copyright_alias_;
    4350  }
    4451
     
    7279        getline(ss, tmp);
    7380        std::string name = trim(tmp);
    74         copyright_alias_[key] = name;
     81        std::map<std::string,Alias>::iterator iter =
     82          copyright_alias_.lower_bound(key);
     83        if (iter!=copyright_alias_.end() && iter->first==key){
     84          std::stringstream mess;
     85          mess << "svndigest: invalid config file: "
     86               << "in copright-alias section" << key + "defined twice.";
     87          throw std::runtime_error(mess.str());
     88        }
     89       
     90        // insert alias
     91        copyright_alias_.insert(iter,std::make_pair(key, Alias(name,copyright_alias_.size())));
    7592      }
    7693      else if (section == "trac"){
     
    126143       << "[copyright-alias]\n"
    127144       << "# jdoe = John Doe\n";
    128    
    129     typedef std::map<std::string, std::string> map;
    130     for (map::const_iterator i=conf.copyright_alias().begin();
    131          i!=conf.copyright_alias().end(); ++i) {
    132       os << i->first << " = " << i->second << " \n";
     145
     146    typedef std::vector<std::pair<std::string, Alias> > vector;
     147    vector vec;
     148    std::back_insert_iterator<vector> back_insert_iterator(vec);
     149    vec.reserve(conf.copyright_alias().size());
     150    std::copy(conf.copyright_alias().begin(), conf.copyright_alias().end(),
     151              back_insert_iterator);
     152    // sort with respect to Alias.id
     153    IdCompare id;
     154    PairSecondCompare<const std::string, Alias, IdCompare> comp(id);
     155    std::sort(vec.begin(),vec.end(), comp);
     156             
     157
     158    for (vector::const_iterator i(vec.begin()); i!=vec.end(); ++i) {
     159      os << i->first << " = " << i->second.name() << " \n";
    133160    }
    134161
Note: See TracChangeset for help on using the changeset viewer.