File tree Expand file tree Collapse file tree 1 file changed +5
-8
lines changed Expand file tree Collapse file tree 1 file changed +5
-8
lines changed Original file line number Diff line number Diff line change 4
4
5
5
#include < algorithm>
6
6
#include < cctype>
7
+ #include < ranges>
7
8
#include < string>
8
9
#include < vector>
9
10
@@ -44,14 +45,10 @@ namespace BetterSongSearch::Util {
44
45
* Removes special characters from a string
45
46
*/
46
47
std::string removeSpecialCharacter (std::string_view const s) {
47
- std::string stringy (s);
48
- for (int i = 0 ; i < stringy.size (); i++) {
49
- if (stringy[i] != ' ' && (stringy[i] < ' A' || stringy[i] > ' Z' ) && (stringy[i] < ' a' || stringy[i] > ' z' ) &&
50
- (stringy[i] < ' 0' || stringy[i] > ' 9' )) {
51
- stringy.erase (i, 1 );
52
- i--;
53
- }
54
- }
48
+ auto filteredView = s | std::views::filter ([](char c) {
49
+ return std::isalnum (c) || c == ' ' ;
50
+ });
51
+ std::string stringy (filteredView.begin (), filteredView.end ());
55
52
return stringy;
56
53
}
57
54
You can’t perform that action at this time.
0 commit comments