-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringMethods.cpp
More file actions
67 lines (50 loc) · 1.48 KB
/
Copy pathstringMethods.cpp
File metadata and controls
67 lines (50 loc) · 1.48 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
//
// Created by WhoIM on 2/12/26.
//
#include "stringMethods.h"
#include <string>
namespace stringMethods {
std::size_t getLineSize(const std::string* const str, std::size_t pos) {
std::size_t nextY = str -> find('\n', pos);
if (nextY == std::string_view::npos) {
return str -> length() - pos;
}
return nextY - pos;
}
std::size_t getMaxX(const std::string* const str) {
std::size_t maxX = 0;
std::size_t i = 0;
std::size_t newX = str -> find('\n', i);
while (newX != std::string_view::npos) {
if (newX - i > maxX) {
maxX = newX - i;
}
i = newX + 1;
newX = str -> find('\n', i);
}
if (str -> length() - i > maxX) {
maxX = str -> length() - i;
}
return maxX;
}
std::size_t getCountY(const std::string* const str) {
std::size_t count = 0;
std::size_t i = 0;
while (str -> find('\n', i) != std::string_view::npos) {
count++;
i = str -> find('\n', i) + 1;
}
return count + 1;
}
bool startwith(std::string_view str, std::string_view prefix) {
if (prefix.length() > str.length()) {
return false;
}
for (std::size_t i = 0; i < prefix.length(); i++) {
if (prefix[i] != str[i]) {
return false;
}
}
return true;
}
} // stringMethods