forked from WerWolv/ImHex-Patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.pat
146 lines (106 loc) · 3.04 KB
/
string.pat
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#pragma once
#include <std/io.pat>
namespace std::string {
struct SizedStringBase<SizeType, DataType> {
SizeType size;
DataType data[size];
} [[sealed, format("std::string::impl::format_sized_string"), transform("std::string::impl::format_sized_string")]];
using SizedString<SizeType> = SizedStringBase<SizeType, char>;
using SizedString16<SizeType> = SizedStringBase<SizeType, char16>;
namespace impl {
fn format_sized_string(ref auto string) {
return string.data;
};
}
fn length(str string) {
return builtin::std::string::length(string);
};
fn at(str string, u32 index) {
return builtin::std::string::at(string, index);
};
fn substr(str string, u32 pos, u32 count) {
return builtin::std::string::substr(string, pos, count);
};
fn parse_int(str string, u8 base) {
return builtin::std::string::parse_int(string, base);
};
fn parse_float(str string) {
return builtin::std::string::parse_float(string);
};
fn to_string(auto x) {
return std::format("{}", x);
};
fn starts_with(str string, str part) {
return std::string::substr(string, 0, std::string::length(part)) == part;
};
fn ends_with(str string, str part) {
return std::string::substr(string, std::string::length(string) - std::string::length(part), std::string::length(part)) == part;
};
fn contains(str a, str b) {
s32 a_len = std::string::length(a);
s32 b_len = std::string::length(b);
for (s32 i = 0, i <= (a_len - b_len), i += 1) {
if (std::string::substr(a, i, b_len) == b)
return true;
}
return false;
};
fn reverse(str string) {
str result;
s32 i;
i = std::string::length(string);
while (i > 0) {
i = i - 1;
result = result + std::string::at(string, i);
}
return result;
};
fn to_upper(str string) {
str result;
u32 i;
char c;
while (i < std::string::length(string)) {
c = std::string::at(string, i);
if (c >= 'a' && c <= 'z')
result = result + char(c - 0x20);
else
result = result + c;
i = i + 1;
}
return result;
};
fn to_lower(str string) {
str result;
u32 i;
char c;
while (i < std::string::length(string)) {
c = std::string::at(string, i);
if (c >= 'A' && c <= 'Z')
result = result + char(c + 0x20);
else
result = result + c;
i = i + 1;
}
return result;
};
fn replace(str string, str pattern, str replace) {
u32 string_len, pattern_len, replace_len;
string_len = std::string::length(string);
pattern_len = std::string::length(pattern);
replace_len = std::string::length(replace);
if (pattern_len > string_len)
return string;
str result;
u32 i;
while (i <= (string_len - pattern_len)) {
if (std::string::substr(string, i, pattern_len) == pattern) {
result = result + replace;
i = i + pattern_len;
} else {
result = result + std::string::at(string, i);
i = i + 1;
}
}
return result;
};
}