-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlighter.cpp
More file actions
43 lines (35 loc) · 934 Bytes
/
Copy pathhighlighter.cpp
File metadata and controls
43 lines (35 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* just like google
-- that they highlight the text findings,
this is still string version */
#include <iostream>
#include <string>
#include "defines.hpp"
using namespace std;
#define COLOR(f, b) (cout << "\033[1;3" << (f) << ";4" << (b) << 'm' << flush)
#define WHITE 7
#define BLUE 4
#define GREEN 2
int main(){
win();
/* search
& high lighting the find */
string s;
puts("enter the string: ");
getline(cin, s);
puts("tofind: ");
string tofind;
getline(cin, tofind);
size_t pos = s.find(tofind);
/* while (pos != std::string::npos){
cout << "_at index" << pos << endl;
pos = s.find(tofind, pos + tofind.length());
}
*/
s.insert(pos, "");
cout << s.substr(0, pos);
COLOR(WHITE, BLUE);
cout << tofind;
COLOR(2, 0); /* reset color */
cout << s.substr(pos + tofind.length()) << endl; /* to print the rest */
return 0;
}