@@ -188,72 +188,14 @@ void trip::interpolate() {
188188 }
189189}
190190
191- std::string trip::display_name (timetable const & tt) const {
192- auto const is_digit = [](char const x) { return x >= ' 0' && x <= ' 9' ; };
193-
194- // Depending on the class, there are different expectations from users
195- // if the special case doesn't work based on available data, fall back to
196- // generic code afterwards
197- switch (route_->clasz_ ) {
198- // For subway / metro, only the line matters since it's frequent enough.
199- case clasz::kSubway :
200- case clasz::kMetro :
201- if (!route_->short_name_ .empty ()) {
202- return route_->short_name_ ;
203- }
204- break ;
205- // Deutsche Bahn heuristics to classify ICEs and ICs
206- case clasz::kHighSpeed :
207- case clasz::kLongDistance : {
208- auto const trip_name_is_number =
209- !short_name_.empty () && utl::all_of (short_name_, is_digit);
210- if (!route_->short_name_ .starts_with (" IC" ) &&
211- route_->agency_ != provider_idx_t::invalid () &&
212- tt.providers_ [route_->agency_ ].long_name_ == " DB Fernverkehr AG" ) {
213- if (route_->clasz_ == clasz::kHighSpeed ) {
214- return trip_name_is_number
215- ? fmt::format (" ICE {}" , utl::parse<int >(short_name_))
216- : fmt::format (" ICE {}" , route_->short_name_ );
217- } else if (route_->clasz_ == clasz::kLongDistance ) {
218- return trip_name_is_number
219- ? fmt::format (" IC {}" , utl::parse<int >(short_name_))
220- : fmt::format (" IC {}" , route_->short_name_ );
221- }
222- }
223-
224- break ;
225- }
226- default : {
227- }
228- }
229-
230- // route name looks like product name, trip name is number
231- auto const is_product_name = [=](std::string_view route) {
232- return utl::all_of (route, [=](char const c) { return !is_digit (c); });
233- };
234-
235- auto const is_trip_number = [=](std::string_view trip_name) {
236- return utl::all_of (trip_name, is_digit);
237- };
238-
239- if (!route_->short_name_ .empty () && is_product_name (route_->short_name_ ) &&
240- !short_name_.empty () && is_trip_number (short_name_)) {
241- return fmt::format (" {} {}" , route_->short_name_ ,
242- utl::parse<int >(short_name_));
243- }
244-
245- auto precedence = std::array{std::string_view{route_->short_name_ },
246- std::string_view{route_->long_name_ },
247- std::string_view{short_name_}};
248-
249- // prefer route short name over route long name,
250- // prefer route long name over trip short name
251- for (auto const candidate : precedence) {
252- if (!candidate.empty ()) {
253- return std::string (candidate);
191+ std::string trip::display_name () const {
192+ for (auto const str :
193+ {std::string_view{route_->short_name_ },
194+ std::string_view{route_->long_name_ }, std::string_view{short_name_}}) {
195+ if (!str.empty ()) {
196+ return std::string{str};
254197 }
255198 }
256-
257199 return {};
258200}
259201
0 commit comments