rodecomp/Source/Utility/Tokenizer.cpp
ragnarok-clanker d54f050f5b Decompile 3 functions in Source/Utility/Tokenizer.cpp, Source/Utility/Tokenizer.h
Batch #988 by ragnarok-clanker: 0 byte-identical, 3 confirmed by peer review.

- fn_07779 CTokenizer::operator[]: logic confirmed by peer review
- fn_18248 CTokenizer::Parse: logic confirmed by peer review
- fn_18261 CTokenizer::Parse: logic confirmed by peer review

Reviewed-by: ragnarok-clanker
Adds to the build: Source/Utility/Tokenizer.cpp
2026-10-27 08:50:11 +00:00

66 lines
1.8 KiB
C++

#include "Utility/Tokenizer.h"
#include "Client/Application/ErrorDialog.h"
#include "Render/DeviceContext/DCSurface.h"
#include <cwctype>
// OFFSET: 0x00746A70
// FUNCTION: fn_07779
std::string& CTokenizer::operator[](int index) {
if (index < 0 || static_cast<unsigned int>(index) >= this->tokens.size()) {
ShowErrorDialog(GetRenderSystemHolder()->system, "Error in CTokenizer :: operator []", 0);
for (unsigned int token = 0; token < this->tokens.size(); ++token) {
ShowErrorDialog(GetRenderSystemHolder()->system, this->tokens[token].c_str(), 0);
}
}
return this->tokens[index];
}
// OFFSET: 0x00AF5970
// FUNCTION: fn_18248
void CTokenizer::Parse(std::istream& input) {
char text[1024];
input.getline(text, sizeof(text));
this->Parse(std::string(text));
}
// OFFSET: 0x00AF7680
// FUNCTION: fn_18261
void CTokenizer::Parse(const std::string& text) {
enum class State { Token = 1, Whitespace = 2 };
char token[1024];
unsigned int length = 0;
State state = State::Token;
const int size = static_cast<int>(text.size());
this->tokens.clear();
int index = 0;
for (; index < size; ++index) {
const char value = text[index];
if (state == State::Token) {
if (value == '/' && text[index + 1] == '/') {
return;
}
if (std::iswspace(static_cast<wchar_t>(value)) && value >= 0) {
if (index != 0) {
token[length] = '\0';
this->tokens.push_back(std::string(token));
length = 0;
}
state = State::Whitespace;
} else {
token[length++] = value;
}
} else if (!std::iswspace(static_cast<wchar_t>(value)) || value < 0) {
--index;
state = State::Token;
}
}
if (state != State::Whitespace && index != 0) {
token[length] = '\0';
this->tokens.push_back(std::string(token));
}
}