Repository navigation
Expand file tree
/
Copy pathStrUtil.cpp
More file actions
101 lines (88 loc) · 3.04 KB
/
Copy pathStrUtil.cpp
File metadata and controls
101 lines (88 loc) · 3.04 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<iostream>
#include<string>
#include"StrUtil.h"
using namespace std;
string StrUtil::lowerParserText(string text) {
for (int i = 0; i < text.length(); i++) {
if (text[i] >= 'A' && text[i] <= 'Z') {
text[i] = text[i] - 'A' + 'a';
}
}
return text;
}
string StrUtil::toLowerText(string text) {
// 명령어는 대소문자 구분 없이 받기 위해서 소문자로 맞춤
for (int i = 0; i < text.length(); i++) {
if (text[i] >= 'A' && text[i] <= 'Z') {
text[i] = text[i] - 'A' + 'a';
}
}
return text;
}
bool StrUtil::isAccessText(const string& text) {
string access = toLowerText(text);
return access == "getter" || access == "setter" || access == "deleter" || access == "owner";
}
int StrUtil::readNumberOption(const string& text) {
// log -3 같은 형식에서 뒤 숫자만 뽑음
if (text.length() < 2 || text[0] != '-') {
return -1;
}
int number = 0;
for (int i = 1; i < text.length(); i++) {
if (text[i] < '0' || text[i] > '9') {
return -1;
}
number = number * 10 + (text[i] - '0');
}
return number;
}
string StrUtil::makeTextFromArgs(const vector<string>& args, int startIndex) {
string text;
// parser가 공백 기준으로 나눠서 write 뒤 텍스트를 다시 붙임
for (int i = startIndex; i < args.size(); i++) {
if (i != startIndex) {
text += " ";
}
text += args[i];
}
return text;
}
string StrUtil::restoreNewLineText(string text) {
string result;
for (int i = 0; i < text.length(); i++) {
// nano에서 넘긴 \n 표시를 실제 줄바꿈으로 바꿈
if (text[i] == '\\' && i + 1 < text.length() && text[i + 1] == 'n') {
result += '\n';
i++;
}
else {
result += text[i];
}
}
return result;
}
string StrUtil::makeHelpText() {
string text;
text += "command form description\n";
text += "---------------------------------------------------------------\n";
text += "login login id password login\n";
text += "signin signin id password create user\n";
text += "logout logout logout\n";
text += "touch touch pageName create page\n";
text += "rm rm pageName delete page\n";
text += "cat cat pageName print page text\n";
text += "nano nano pageName open page for writing\n";
text += "ls ls . / ls access print page list\n";
text += "chmod chmod userId pageName access change page permission\n";
text += "save save . / save pageName save page data\n";
text += "pull pull pageName load page data\n";
text += "undo undo undo command\n";
text += "redo redo redo command\n";
text += "sudo sudo id password / sudo .. admin mode\n";
text += "log log -f / log -number print command logs\n";
text += "debuglog debuglog -f / debuglog -num print debug logs\n";
text += "help help print command help\n";
text += "exit exit exit program";
return text;
}