-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
70 lines (63 loc) · 1.45 KB
/
util.cpp
File metadata and controls
70 lines (63 loc) · 1.45 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include "header.hpp"
using namespace std;
string strToAst(string S) {
string res;
res.resize(S.size());
for(int i=0;i<(int)S.size();i++)res[i]='*';
return res;
}
string questionForm(string question) {
cout << question << " ";
string answer;
getline(cin,answer);
if ( cin.eof()==1 ) exit(0);
return answer;
}
string hiddenQuestionForm(string question) {
cout << question << " ";
string answer;
system("stty -echo");
getline(cin,answer);
system("stty echo");
cout << "\n";
if ( cin.eof()==1 ) exit(0);
return answer;
}
bool decisionForm(string question){
while ( 1 ) {
string answer=questionForm(question+" (yes or no)");
if( answer == "yes" ) return true;
else if( answer == "no") return false;
else {
cout << "You have to answer yes or no.\n";
}
}
}
vector <string> splitString(string S, string P) {
vector <string> res;
int pp=0;
while( 1 ) {
int px=S.find(P,pp);
if( px==-1 ){
res.push_back( S.substr(pp,S.size()-pp) );
break;
}
res.push_back( S.substr(pp,px-pp) );
//~ cout << res.back() << endl;
pp=px+P.size();
}
return res;
}
string homePath, mainFolderPath, privateKeyHashPath, passwordListPath;
void initPath() {
homePath=getenv("HOME");
mainFolderPath=homePath+"/.passwordKeeper";
privateKeyHashPath=mainFolderPath+"/.privateKeyHash.txt";
passwordListPath=mainFolderPath+"/.passwordList.txt";
}