mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-15 15:05:27 +08:00
Use move semantics in trim and history_item_t
This commit is contained in:
parent
dd34bf0ba6
commit
99c498d3d7
@ -171,10 +171,8 @@ bool history_item_t::merge(const history_item_t &item) {
|
||||
return result;
|
||||
}
|
||||
|
||||
history_item_t::history_item_t(const wcstring &str, time_t when, history_identifier_t ident)
|
||||
: creation_timestamp(when), identifier(ident) {
|
||||
contents = trim(str);
|
||||
}
|
||||
history_item_t::history_item_t(wcstring str, time_t when, history_identifier_t ident)
|
||||
: contents(trim(std::move(str))), creation_timestamp(when), identifier(ident) {}
|
||||
|
||||
bool history_item_t::matches_search(const wcstring &term, enum history_search_type_t type,
|
||||
bool case_sensitive) const {
|
||||
|
@ -82,7 +82,7 @@ class history_item_t {
|
||||
path_list_t required_paths;
|
||||
|
||||
public:
|
||||
explicit history_item_t(const wcstring &str = wcstring(), time_t when = 0,
|
||||
explicit history_item_t(wcstring str = wcstring(), time_t when = 0,
|
||||
history_identifier_t ident = 0);
|
||||
|
||||
const wcstring &str() const { return contents; }
|
||||
|
@ -49,16 +49,19 @@ wcstring truncate(const wcstring &input, int max_len, ellipsis_type etype) {
|
||||
return output;
|
||||
}
|
||||
|
||||
wcstring trim(const wcstring &input) { return trim(input, L"\t\v \r\n"); }
|
||||
wcstring trim(wcstring input) { return trim(std::move(input), L"\t\v \r\n"); }
|
||||
|
||||
wcstring trim(const wcstring &input, const wchar_t *any_of) {
|
||||
auto begin_offset = input.find_first_not_of(any_of);
|
||||
if (begin_offset == wcstring::npos) {
|
||||
wcstring trim(wcstring input, const wchar_t *any_of) {
|
||||
wcstring result = std::move(input);
|
||||
size_t suffix = result.find_last_not_of(any_of);
|
||||
if (suffix == wcstring::npos) {
|
||||
return wcstring{};
|
||||
}
|
||||
auto end = input.cbegin() + input.find_last_not_of(any_of);
|
||||
result.erase(suffix + 1);
|
||||
|
||||
wcstring result(input.begin() + begin_offset, end + 1);
|
||||
auto prefix = result.find_first_not_of(any_of);
|
||||
assert(prefix != wcstring::npos && "Should have one non-trimmed character");
|
||||
result.erase(0, prefix);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,8 @@ enum class ellipsis_type {
|
||||
|
||||
wcstring truncate(const wcstring &input, int max_len,
|
||||
ellipsis_type etype = ellipsis_type::Prettiest);
|
||||
wcstring trim(const wcstring &input);
|
||||
wcstring trim(const wcstring &input, const wchar_t *any_of);
|
||||
wcstring trim(wcstring input);
|
||||
wcstring trim(wcstring input, const wchar_t *any_of);
|
||||
|
||||
/// Converts a string to lowercase.
|
||||
wcstring wcstolower(wcstring input);
|
||||
|
Loading…
x
Reference in New Issue
Block a user