trim white spaces
This commit is contained in:
parent
99d85220f8
commit
30c302d13d
|
@ -3,6 +3,7 @@
|
|||
// $ patchelf --set-rpath /usr/local/lib/gcc13 hakurei
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
@ -18,6 +19,8 @@
|
|||
#include <fstream>
|
||||
#include <ctime>
|
||||
|
||||
|
||||
|
||||
struct Entry {
|
||||
const std::string_view decoded_view;
|
||||
const uint64_t id;
|
||||
|
@ -46,6 +49,19 @@ inline std::pair<std::string, std::string> remove_one_utf8_char(const std::strin
|
|||
return {"", ""};
|
||||
}
|
||||
|
||||
|
||||
std::string trim(const std::string& str) {
|
||||
size_t start = str.find_first_not_of(" \t\n\r\f\v");
|
||||
size_t end = str.find_last_not_of(" \t\n\r\f\v");
|
||||
|
||||
if (start == std::string::npos || end == std::string::npos)
|
||||
return ""; // String contains only whitespace
|
||||
|
||||
return str.substr(start, end - start + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline std::string get_input(const int argc, char* const argv[], const bool goldendict_mode) {
|
||||
std::string search_string;
|
||||
if (!isatty(fileno(stdin))) {
|
||||
|
@ -79,7 +95,8 @@ inline std::string get_input(const int argc, char* const argv[], const bool gold
|
|||
std::cerr << "Search string not provided." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
return search_string;
|
||||
|
||||
return trim(search_string);
|
||||
}
|
||||
|
||||
inline std::filesystem::path find_dic_file() {
|
||||
|
|
Loading…
Reference in a new issue