|
1 | | -/* |
2 | | - * Part of SMITHLAB software |
| 1 | +/* Part of SMITHLAB software |
3 | 2 | * |
4 | | - * Copyright (C) 2008 Cold Spring Harbor Laboratory, |
5 | | - * University of Southern California and |
6 | | - * Andrew D. Smith |
| 3 | + * Copyright (C) 2008-2024 Cold Spring Harbor Laboratory, |
| 4 | + * University of Southern California and |
| 5 | + * Andrew D. Smith |
7 | 6 | * |
8 | | - * Authors: Andrew D. Smith |
| 7 | + * Authors: Andrew D. Smith |
9 | 8 | * |
10 | | - * This program is free software: you can redistribute it and/or modify |
11 | | - * it under the terms of the GNU General Public License as published by |
12 | | - * the Free Software Foundation, either version 3 of the License, or |
13 | | - * (at your option) any later version. |
| 9 | + * This program is free software: you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License as |
| 11 | + * published by the Free Software Foundation, either version 3 of the |
| 12 | + * License, or (at your option) any later version. |
14 | 13 | * |
15 | | - * This program is distributed in the hope that it will be useful, |
16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | | - * GNU General Public License for more details. |
| 14 | + * This program is distributed in the hope that it will be useful, but |
| 15 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | + * General Public License for more details. |
19 | 18 | * |
20 | | - * You should have received a copy of the GNU General Public License |
21 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program. If not, see |
| 21 | + * <http://www.gnu.org/licenses/>. |
22 | 22 | */ |
23 | 23 |
|
24 | 24 | #include "OptionParser.hpp" |
|
32 | 32 | #include <functional> |
33 | 33 | #include <iomanip> |
34 | 34 | #include <iterator> |
| 35 | +#include <regex> |
35 | 36 | #include <sstream> |
36 | 37 |
|
37 | 38 | #include "smithlab_utils.hpp" |
@@ -211,7 +212,7 @@ string Option::format_option_description(const size_t offset, |
211 | 212 |
|
212 | 213 | size_t line_len = 0; |
213 | 214 | for (size_t i = 0; i < parts.size(); ++i) { |
214 | | - if (offset + line_len + parts[i].size() >= MAX_LINE_LENGTH && i > 0) { |
| 215 | + if (offset + line_len + parts[i].size() > MAX_LINE_LENGTH && i > 0) { |
215 | 216 | line_len = 0; |
216 | 217 | ss << endl; |
217 | 218 | } |
@@ -530,16 +531,24 @@ string OptionParser::help_message() const { |
530 | 531 |
|
531 | 532 | string OptionParser::about_message() const { |
532 | 533 | static const char *PROGRAM_NAME_TAG = "PROGRAM: "; |
| 534 | + static const std::regex whitespace_re(R"([\s]+)"); |
| 535 | + |
| 536 | + // remove newlines |
| 537 | + string tmp_descr{prog_descr}; |
| 538 | + regex_replace(begin(tmp_descr), cbegin(tmp_descr), cend(tmp_descr), |
| 539 | + whitespace_re, " "); |
| 540 | + tmp_descr.erase(tmp_descr.find_last_not_of(' ') + 1); |
| 541 | + tmp_descr.erase(0, tmp_descr.find_first_not_of(' ')); |
533 | 542 |
|
534 | 543 | vector<string> parts; |
535 | | - smithlab::split_whitespace(prog_descr, parts); |
| 544 | + smithlab::split_whitespace(tmp_descr, parts); |
536 | 545 |
|
537 | 546 | std::ostringstream ss; |
538 | 547 | ss << PROGRAM_NAME_TAG << prog_name << endl; |
539 | 548 | ss << parts.front(); |
540 | 549 | size_t line_len = parts.front().length(); |
541 | 550 | for (size_t i = 1; i < parts.size(); ++i) { |
542 | | - if (line_len + parts[i].size() >= MAX_LINE_LENGTH) { |
| 551 | + if (line_len + parts[i].size() > MAX_LINE_LENGTH) { |
543 | 552 | line_len = 0; |
544 | 553 | ss << endl; |
545 | 554 | } |
|
0 commit comments