@@ -91,33 +91,21 @@ bool SearchHistoryObject::empty() const {
9191
9292void SearchHistory::add (GJSearchObject* search, time_t time, int type) {
9393 std::vector<int > difficulties;
94- std::string_view difficulty = search->m_difficulty ;
95- if (difficulty != " -" ) {
96- auto start = difficulty.begin ();
97- auto end = difficulty.end ();
98- for (auto it = start; it <= end; ++it) {
99- if (it >= end || *it == ' ,' ) {
100- int num;
101- if (auto res = std::from_chars (start, it, num); res.ec == std::errc ()) {
102- difficulties.push_back (num);
103- }
104- start = it + 1 ;
94+ if (search->m_difficulty != " -" ) {
95+ for (auto & diff : string::split (search->m_difficulty , " ," )) {
96+ int num;
97+ if (auto res = std::from_chars (diff.data (), diff.data () + diff.size (), num); res.ec == std::errc ()) {
98+ difficulties.push_back (num);
10599 }
106100 }
107101 }
108102
109103 std::vector<int > lengths;
110- std::string_view length = search->m_length ;
111- if (length != " -" ) {
112- auto start = length.begin ();
113- auto end = length.end ();
114- for (auto it = start; it <= end; ++it) {
115- if (it >= end || *it == ' ,' ) {
116- int num;
117- if (auto res = std::from_chars (start, it, num); res.ec == std::errc ()) {
118- lengths.push_back (num);
119- }
120- start = it + 1 ;
104+ if (search->m_length != " -" ) {
105+ for (auto & len : string::split (search->m_length , " ," )) {
106+ int num;
107+ if (auto res = std::from_chars (len.data (), len.data () + len.size (), num); res.ec == std::errc ()) {
108+ lengths.push_back (num);
121109 }
122110 }
123111 }
@@ -126,8 +114,8 @@ void SearchHistory::add(GJSearchObject* search, time_t time, int type) {
126114 obj.time = time;
127115 obj.type = type;
128116 obj.query = search->m_searchQuery ;
129- obj.difficulties = difficulties;
130- obj.lengths = lengths;
117+ obj.difficulties = std::move ( difficulties) ;
118+ obj.lengths = std::move ( lengths) ;
131119 obj.uncompleted = search->m_uncompletedFilter ;
132120 obj.completed = search->m_completedFilter ;
133121 obj.featured = search->m_featuredFilter ;
0 commit comments