LeviLamina
Loading...
Searching...
No Matches
Util.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/deps/core/debug/log/LogArea.h"
7#include "mc/deps/core/utility/NumberConversionResult.h"
8#include "mc/deps/core/utility/buffer_span.h"
9#include "mc/platform/brstd/flat_set.h"
10#include "mc/util/BidirectionalUnorderedMap.h"
11
12// auto generated forward declare list
13// clang-format off
14class GameVersion;
15class I18n;
16class ListTag;
17class SemVersion;
18namespace Json { class Value; }
19namespace Util { struct string_hash; }
20// clang-format on
21
22namespace Util {
23// functions
24// NOLINTBEGIN
25MCNAPI_C void _breakIntoWordsAndFindProfanity(
26 ::std::string_view str,
27 ::std::vector<::std::pair<int, int>> const& originalStrIndexes,
28 ::brstd::flat_set<char, ::std::less<char>, ::std::vector<char>> const& escapeChars,
29 ::std::set<::std::pair<int, int>>& profanityLocations,
30 ::std::unordered_map<::std::string, int, ::Util::string_hash, ::std::equal_to<void>> const& exactMap,
31 ::std::unordered_set<::std::string, ::Util::string_hash, ::std::equal_to<void>> const& containsSet
32);
33
34MCNAPI_C void _recordProfanityLocationInWord(
35 ::std::string_view word,
36 ::std::vector<::std::pair<int, int>> const& originalStrIndexes,
37 int start,
38 int end,
39 ::std::set<::std::pair<int, int>>& profanityLocations,
40 ::std::unordered_map<::std::string, int, ::Util::string_hash, ::std::equal_to<void>> const& exactMap,
41 ::std::unordered_set<::std::string, ::Util::string_hash, ::std::equal_to<void>> const& containsSet
42);
43
44MCNAPI ::std::string base64_decode(::std::string const& encoded_string);
45
46MCNAPI ::std::string base64_encode(uchar const* bytes_to_encode, uint64 in_len, bool pad);
47
48MCNAPI ::std::string base64url_decode(::std::string encoded);
49
50MCNAPI ::std::string base64url_encode(::std::string str);
51
52MCNAPI_C ::std::string caseFold(::std::string_view str);
53
54MCNAPI_C bool containsUnicodeChar(::std::string const& str);
55
56MCNAPI_C uint64 createObfuscated64BitIntegerFromXboxLiveID(::std::string const& input);
57
58MCNAPI ::std::string ensureNamespace(::std::string const& id, ::std::string_view defaultNamespace);
59
60MCNAPI bool equalIgnoreCase(::std::string_view lhs, ::std::string_view rhs);
61
62MCNAPI_C ::std::string filterProfanityFromString(
63 ::std::string_view inputStr,
64 ::std::unordered_map<::std::string, int, ::Util::string_hash, ::std::equal_to<void>> const& profanityExactMap,
65 ::std::unordered_set<::std::string, ::Util::string_hash, ::std::equal_to<void>> const& profanityContainsSet
66);
67
68MCNAPI_C ::std::string findLastColorCode(::std::string_view s, bool includeResetCode);
69
70MCNAPI_C ::std::set<::std::pair<int, int>> findProfanityInString(
71 ::std::string_view inputStr,
72 ::std::unordered_map<::std::string, int, ::Util::string_hash, ::std::equal_to<void>> const& exactMap,
73 ::std::unordered_set<::std::string, ::Util::string_hash, ::std::equal_to<void>> const& containsSet
74);
75
76MCNAPI ::std::string formatTickDuration(int ticks);
77
78MCNAPI ::std::string fromHex(::std::string_view input);
79
80MCNAPI ::BidirectionalUnorderedMap<int, uint64> generateHashMapFromListTag(::ListTag const& enumValues);
81
82MCNAPI ::std::string generateRandomId(int modifier);
83
84MCNAPI_C ::std::string getActiveFormattingCodes(::std::string const& str);
85
86MCNAPI_C ::std::string getFilesizeString(uint64 filesize);
87
88MCNAPI_C ::std::string getFilesizeString(uint64 filesize, ::I18n& loc);
89
90MCNAPI ::std::string_view getNameWithoutNamespace(::std::string_view name);
91
92MCNAPI_C ::std::string getPackDataDownloadProgressString(
93 uint64 downloadedDataSize,
94 uint64 totalDownloadDataSize,
95 ::std::string (*getFileSizeString)(uint64)
96);
97
98MCNAPI_C ::std::string getPackDownloadProgressString(uint64 downloadedPacks, uint64 packsToDownload);
99
100MCNAPI_C ::std::string getVirtualCurrencyStringTTS(uint amount);
101
102MCNAPI bool isValidNamespaceFormat(::std::string_view name);
103
104MCNAPI bool isValidUTF8(::std::string_view content);
105
106MCNAPI bool isVanillaNamespace(::std::string const& identifier);
107
108MCNAPI_C void loadGameVersion(::GameVersion& version, ::Json::Value const& versionNode);
109
110MCNAPI void loadGameVersion(::SemVersion& version, ::Json::Value const& versionNode);
111
112MCNAPI void normalizeLineEndings(::std::string& str);
113
114MCNAPI ::std::string removeChars(::std::string str, ::std::string const& characters);
115
116MCNAPI_C ::std::string removeFormattingAndColorCodes(::std::string const& input, bool redactObfuscatedText);
117
118MCNAPI ::std::string removeIllegalChars(::std::string str);
119
120MCNAPI_S ::std::string removeTrailingSpaces(::std::string const& str);
121
122MCNAPI_C void replaceUtf8CharactersWithAscii(
123 ::std::string& target,
124 ::std::vector<::std::pair<::std::string, char>> const& translateMap
125);
126
127MCNAPI ::std::istream& safeGetline(::std::istream& inputStream, ::std::string& outString);
128
129MCNAPI_C ::std::string safeString(char const* text);
130
131MCNAPI_C ::std::string simpleFormat(::std::string const& format, ::std::vector<::std::string> const& parameters);
132
133MCNAPI ::std::vector<::std::string> split(::std::string_view view, char delim);
134
135MCNAPI ::std::vector<::std::string> splitAndDiscardEmpty(::std::string const& str, char delim);
136
137MCNAPI_C ::std::vector<::std::string> splitAndDiscardEmpty(
138 ::std::string const& str,
139 ::std::vector<::std::string> const& delims,
140 bool includeDelimCharsInResult
141);
142
143MCNAPI_C ::std::vector<::std::string>
144splitLines(::std::string const& content, ::std::istream& (*fnGetline)(::std::istream&, ::std::string&));
145
146MCNAPI ::std::vector<::std::string> splitLines(
147 ::std::string const& str,
148 ::std::vector<::std::string> const& delims,
149 bool includeDelimCharsInResult,
150 bool includeEmptyLines,
151 ::std::istream& (*fnGetline)(::std::istream&, ::std::string&)
152);
153
154MCNAPI ::std::vector<::std::string>& splitString(::std::string_view s, char delim, ::std::vector<::std::string>& elems);
155
156MCNAPI ::std::vector<::std::string_view>&
157splitStringAsViews(::std::string_view s, char delim, ::std::vector<::std::string_view>& elems);
158
159MCNAPI ::std::vector<::std::string_view> splitToViews(::std::string_view view, char delim);
160
161MCNAPI_C bool startsWith(::std::string_view str, ::std::string_view starts);
162
163MCNAPI bool stringContains(::std::string const& s, char character);
164
165MCNAPI_C bool stringIsInVector(::std::vector<::std::string> const& stringVector, ::std::string const& searchString);
166
167MCNAPI_C ::std::string
168stringReplace(::std::string str, ::buffer_span<::std::pair<::std::string_view, ::std::string_view>> replacements);
169
170MCNAPI ::std::string& stringReplace(::std::string& s, ::std::string const& src, ::std::string const& dst, int maxCount);
171
172MCNAPI ::std::string
173stringReplaceCopy(::std::string const& s, ::std::string const& src, ::std::string const& dst, int maxCount);
174
175MCNAPI ::std::string stringTrim(::std::string const& s);
176
177MCNAPI ::std::string stringTrim(::std::string const& s, ::std::string const& chars);
178
179MCNAPI_C ::std::string stringUTF16ToUTF8(::std::basic_string_view<wchar_t, ::std::char_traits<wchar_t>> inputStr);
180
181MCNAPI bool toBool(::std::string const& input, bool& destination);
182
183MCNAPI ::std::string toCamelCase(::std::string const& src, char delimiter);
184
185MCNAPI_C ::std::string toHex(::std::string_view input);
186
187MCNAPI ::Util::NumberConversionResult toIntWithMinMax(::std::string_view inputStr, int& destination, int min, int max);
188
189MCNAPI_C ::std::string toLocalizedString(float f, int precision);
190
191MCNAPI_C ::std::string toLocalizedString(
192 float f,
193 int precision,
194 ::std::string const& digitGroupSeparator,
195 ::std::string const& decimalSeparator
196);
197
198MCNAPI_C ::std::string toLower(char const* inString);
199
200MCNAPI ::std::string toLower(::std::string_view inString);
201
202MCNAPI_C bool toSafeNumber(::std::string const& str, uint& output);
203
204MCNAPI ::std::string toString(::std::basic_string_view<wchar_t, ::std::char_traits<wchar_t>> inputStr);
205
206MCNAPI ::std::string toStringWithPaddedZeroes(uint number, uchar digitCount);
207
208MCNAPI int utf8len(::std::string_view str);
209
210MCNAPI_C int utf8lenNoColorCodes(::std::string const& str);
211
212MCNAPI ::std::string utf8substring(::std::string const& str, int startIndex, int endIndex);
213
214MCNAPI_C ::std::vector<::std::string> utf8substringCharacters(::std::string const& str, int startIndex, int endIndex);
215
216MCNAPI bool validateIdentifier(
217 ::std::string const& id,
218 ::LogArea logArea,
219 bool allowMinecraftNamespace,
220 ::std::pair<::std::string, ::std::string>* idNameOut
221);
222
223MCNAPI bool validateIdentifierChunk(::std::string const& chunk, ::LogArea logArea);
224// NOLINTEND
225
226// static variables
227// NOLINTBEGIN
228MCNAPI ::std::string const& EMPTY_GUID();
229
230MCNAPI ::std::string const& EMPTY_STRING();
231
232MCNAPI ::std::string const& HEX_CHARS();
233
234MCNAPI ::std::string const& NEW_LINE();
235// NOLINTEND
236
237} // namespace Util
Definition GameVersion.h:10
Definition I18n.h:19
Definition Value.h:16
Definition ListTag.h:20
Definition SemVersion.h:15
Definition string_hash.h:7