@@ -136,20 +136,49 @@ BranchConfig BranchConfig::CloneAndMerge(const BranchConfig& attached) const {
136136}
137137
138138template <typename T>
139- std::vector<std::string> VectorConfig<T>::SplitString(const std::string& input) {
140- std::vector<std::string> result;
141- std::vector<int > newlinepositions{-1 };
142- int it{0 };
143- while (it < std::string::npos) {
144- it = input.find (" \n " , it + 1 );
145- newlinepositions.emplace_back (it);
139+ void VectorConfig<T>::Print() const {
140+ if (map_.empty ()) return ;
141+
142+ auto print_row = [](const std::vector<std::pair<std::string, int >>& elements) {
143+ for (const auto & el : elements) {
144+ std::cout << std::left << std::setw (el.second ) << std::setfill (' ' ) << el.first ;
145+ }
146+ std::cout << std::endl;
147+ };
148+
149+ int name_strlen{0 };
150+ for (const auto & entry : map_) {
151+ name_strlen = std::max (name_strlen, (int ) entry.first .length ());
146152 }
147- newlinepositions.back () = input.size ();
148- for (int ip = 0 ; ip < newlinepositions.size () - 1 ; ++ip) {
149- result.emplace_back (input.substr (newlinepositions.at (ip) + 1 , newlinepositions.at (ip + 1 ) - newlinepositions.at (ip) - 1 ));
153+ name_strlen += 4 ;
154+
155+ auto SplitString = [](const std::string& input) {
156+ std::vector<std::string> result;
157+ std::vector<int > newlinepositions{-1 };
158+ int it{0 };
159+ while (it < std::string::npos) {
160+ it = input.find (" \n " , it + 1 );
161+ newlinepositions.emplace_back (it);
162+ }
163+ newlinepositions.back () = input.size ();
164+ for (int ip = 0 ; ip < newlinepositions.size () - 1 ; ++ip) {
165+ result.emplace_back (input.substr (newlinepositions.at (ip) + 1 , newlinepositions.at (ip + 1 ) - newlinepositions.at (ip) - 1 ));
166+ }
167+ return result;
168+ };
169+
170+ print_row ({{" Id" , 10 }, {" Name" , name_strlen}, {" Info" , 50 }});
171+ for (const auto & entry : map_) {
172+ if (entry.second .title_ .find (" \n " ) == std::string::npos) {
173+ print_row ({{std::to_string (entry.second .id_ ), 10 }, {entry.first , name_strlen}, {entry.second .title_ , 50 }});
174+ } else {
175+ auto est = SplitString (entry.second .title_ );
176+ print_row ({{std::to_string (entry.second .id_ ), 10 }, {entry.first , name_strlen}, {est.at (0 ), 50 }});
177+ for (int iest = 1 ; iest < est.size (); ++iest) {
178+ print_row ({{" " , 10 }, {" " , name_strlen}, {est.at (iest), 50 }});
179+ }
180+ }
150181 }
151-
152- return result;
153182}
154183
155184template <typename T>
0 commit comments