mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-05-30 04:55:42 +00:00
refactor: nuke all widestrings and widechars everywhere
This commit is contained in:
@@ -12,21 +12,21 @@
|
||||
#include "platform/fs/fs.h"
|
||||
#include "java/FileFilter.h"
|
||||
|
||||
const wchar_t File::pathSeparator = L'/';
|
||||
const char File::pathSeparator = '/';
|
||||
|
||||
const std::wstring File::pathRoot =
|
||||
L""; // Path root after pathSeparator has been removed
|
||||
const std::string File::pathRoot =
|
||||
""; // Path root after pathSeparator has been removed
|
||||
|
||||
namespace {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
fs::path ToFilesystemPath(const std::wstring& path) {
|
||||
fs::path ToFilesystemPath(const std::string& path) {
|
||||
return fs::path(path);
|
||||
}
|
||||
|
||||
std::wstring ToFilename(const fs::path& path) {
|
||||
std::string ToFilename(const fs::path& path) {
|
||||
const std::string filename = path.filename().string();
|
||||
return filenametowstring(filename.c_str());
|
||||
return filename;
|
||||
}
|
||||
|
||||
int64_t ToEpochMilliseconds(const fs::file_time_type& fileTime) {
|
||||
@@ -40,27 +40,27 @@ int64_t ToEpochMilliseconds(const fs::file_time_type& fileTime) {
|
||||
|
||||
// Creates a new File instance from a parent abstract pathname and a child
|
||||
// pathname string.
|
||||
File::File(const File& parent, const std::wstring& child) {
|
||||
File::File(const File& parent, const std::string& child) {
|
||||
m_abstractPathName = parent.getPath() + pathSeparator + child;
|
||||
}
|
||||
|
||||
// Creates a new File instance by converting the given pathname string into an
|
||||
// abstract pathname.
|
||||
|
||||
File::File(const std::wstring& pathname) {
|
||||
File::File(const std::string& pathname) {
|
||||
if (pathname.empty()) {
|
||||
m_abstractPathName = L"";
|
||||
m_abstractPathName = "";
|
||||
return;
|
||||
}
|
||||
|
||||
std::wstring fixedPath = pathname;
|
||||
std::string fixedPath = pathname;
|
||||
for (size_t i = 0; i < fixedPath.length(); ++i) {
|
||||
if (fixedPath[i] == L'\\') fixedPath[i] = L'/';
|
||||
if (fixedPath[i] == '\\') fixedPath[i] = '/';
|
||||
}
|
||||
size_t dpos;
|
||||
while ((dpos = fixedPath.find(L"//")) != std::wstring::npos)
|
||||
while ((dpos = fixedPath.find("//")) != std::string::npos)
|
||||
fixedPath.erase(dpos, 1);
|
||||
if (fixedPath.find(L"GAME:/") == 0) fixedPath = fixedPath.substr(6);
|
||||
if (fixedPath.find("GAME:/") == 0) fixedPath = fixedPath.substr(6);
|
||||
m_abstractPathName = fixedPath;
|
||||
|
||||
#if defined(__linux__)
|
||||
@@ -85,11 +85,11 @@ File::File(const std::wstring& pathname) {
|
||||
std::string tryFull = exeDir + base + request;
|
||||
std::string tryFile = exeDir + base + fileName;
|
||||
if (PlatformFilesystem.exists(tryFull)) {
|
||||
m_abstractPathName = convStringToWstring(tryFull);
|
||||
m_abstractPathName = tryFull;
|
||||
return;
|
||||
}
|
||||
if (PlatformFilesystem.exists(tryFile)) {
|
||||
m_abstractPathName = convStringToWstring(tryFile);
|
||||
m_abstractPathName = tryFile;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -99,15 +99,15 @@ File::File(const std::wstring& pathname) {
|
||||
std::string path = std::filesystem::path(m_abstractPathName).string();
|
||||
std::string finalPath = PlatformStorage.GetMountedPath(path.c_str());
|
||||
if (finalPath.size() == 0) finalPath = path;
|
||||
m_abstractPathName = convStringToWstring(finalPath);
|
||||
m_abstractPathName = finalPath;
|
||||
#endif
|
||||
/*
|
||||
std::vector<std::wstring> path = stringSplit( pathname, pathSeparator );
|
||||
std::vector<std::string> path = stringSplit( pathname, pathSeparator );
|
||||
|
||||
if( path.back().compare( pathRoot ) != 0 )
|
||||
m_abstractPathName = path.back();
|
||||
else
|
||||
m_abstractPathName = L"";
|
||||
m_abstractPathName = "";
|
||||
|
||||
path.pop_back();
|
||||
|
||||
@@ -122,8 +122,8 @@ File::File(const std::wstring& pathname) {
|
||||
*/
|
||||
}
|
||||
|
||||
File::File(const std::wstring& parent,
|
||||
const std::wstring& child) //: m_abstractPathName( child )
|
||||
File::File(const std::string& parent,
|
||||
const std::string& child) //: m_abstractPathName( child )
|
||||
{
|
||||
m_abstractPathName =
|
||||
pathRoot + pathSeparator + parent + pathSeparator + child;
|
||||
@@ -133,7 +133,7 @@ File::File(const std::wstring& parent,
|
||||
// Creates a new File instance by converting the given path vector into an
|
||||
// abstract pathname.
|
||||
/*
|
||||
File::File( std::vector<std::wstring> *path ) : parent( nullptr )
|
||||
File::File( std::vector<std::string> *path ) : parent( nullptr )
|
||||
{
|
||||
m_abstractPathName = path->back();
|
||||
path->pop_back();
|
||||
@@ -363,13 +363,13 @@ int64_t File::lastModified() {
|
||||
return 0l;
|
||||
}
|
||||
|
||||
const std::wstring File::getPath() const {
|
||||
const std::string File::getPath() const {
|
||||
/*
|
||||
std::wstring path;
|
||||
std::string path;
|
||||
if ( parent != nullptr)
|
||||
path = parent->getPath();
|
||||
else
|
||||
path = std::wstring(pathRoot);
|
||||
path = std::string(pathRoot);
|
||||
|
||||
path.push_back( pathSeparator );
|
||||
path.append(m_abstractPathName);
|
||||
@@ -377,7 +377,7 @@ const std::wstring File::getPath() const {
|
||||
return m_abstractPathName;
|
||||
}
|
||||
|
||||
std::wstring File::getName() const {
|
||||
std::string File::getName() const {
|
||||
unsigned int sep =
|
||||
(unsigned int)(m_abstractPathName.find_last_of(this->pathSeparator));
|
||||
return m_abstractPathName.substr(sep + 1, m_abstractPathName.length());
|
||||
@@ -394,7 +394,7 @@ int File::hash_fnct(const File& k) {
|
||||
// if (k->parent != nullptr)
|
||||
// hashCode = hash_fnct(k->getParent());
|
||||
|
||||
wchar_t* ref = (wchar_t*)k.m_abstractPathName.c_str();
|
||||
char* ref = (char*)k.m_abstractPathName.c_str();
|
||||
|
||||
for (unsigned int i = 0; i < k.m_abstractPathName.length(); i++) {
|
||||
hashCode += ((hashCode * 33) + ref[i]) % 149;
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
BufferedReader::BufferedReader(Reader* in)
|
||||
: reader(in), readMark(0), bufferedMark(0), eofReached(false) {
|
||||
bufferSize = 64;
|
||||
buffer = new wchar_t[bufferSize];
|
||||
memset(buffer, 0, sizeof(wchar_t) * bufferSize);
|
||||
buffer = new char[bufferSize];
|
||||
memset(buffer, 0, sizeof(char) * bufferSize);
|
||||
bufferMore();
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ void BufferedReader::bufferMore() {
|
||||
|
||||
if (bufferSize < (bufferedMark + BUFFER_MORE_AMOUNT)) {
|
||||
// Enlarge the buffer
|
||||
wchar_t* temp = new wchar_t[bufferSize * 2];
|
||||
memset(temp, 0, sizeof(wchar_t) * bufferSize * 2);
|
||||
char* temp = new char[bufferSize * 2];
|
||||
memset(temp, 0, sizeof(char) * bufferSize * 2);
|
||||
std::copy(buffer, buffer + bufferSize, temp);
|
||||
|
||||
delete[] buffer;
|
||||
@@ -99,11 +99,11 @@ int BufferedReader::read() {
|
||||
// Returns:
|
||||
// The number of characters read, or -1 if the end of the stream has been
|
||||
// reached
|
||||
int BufferedReader::read(wchar_t cbuf[], unsigned int off, unsigned int len) {
|
||||
int BufferedReader::read(char cbuf[], unsigned int off, unsigned int len) {
|
||||
if (bufferSize < (bufferedMark + len)) {
|
||||
// Enlarge the buffer
|
||||
wchar_t* temp = new wchar_t[bufferSize * 2];
|
||||
memset(temp, 0, sizeof(wchar_t) * bufferSize * 2);
|
||||
char* temp = new char[bufferSize * 2];
|
||||
memset(temp, 0, sizeof(char) * bufferSize * 2);
|
||||
std::copy(buffer, buffer + bufferSize, temp);
|
||||
|
||||
delete[] buffer;
|
||||
@@ -135,12 +135,12 @@ int BufferedReader::read(wchar_t cbuf[], unsigned int off, unsigned int len) {
|
||||
// immediately by a linefeed. Returns: A String containing the contents of the
|
||||
// line, not including any line-termination characters, or null if the end of
|
||||
// the stream has been reached
|
||||
std::wstring BufferedReader::readLine() {
|
||||
std::wstring output = L"";
|
||||
std::string BufferedReader::readLine() {
|
||||
std::string output = "";
|
||||
bool newLineCharFound = false;
|
||||
|
||||
while (readMark < bufferedMark) {
|
||||
wchar_t value = buffer[readMark++];
|
||||
char value = buffer[readMark++];
|
||||
|
||||
if (!newLineCharFound) {
|
||||
if ((value == '\n') || (value == '\r')) {
|
||||
|
||||
@@ -162,7 +162,7 @@ unsigned char DataInputStream::readUnsignedByte() {
|
||||
//
|
||||
// This method is suitable for reading bytes written by the writeChar method of
|
||||
// interface DataOutput. Returns: the char value read.
|
||||
wchar_t DataInputStream::readChar() {
|
||||
char DataInputStream::readChar() {
|
||||
if (stream == nullptr) {
|
||||
fprintf(
|
||||
stderr,
|
||||
@@ -171,7 +171,7 @@ wchar_t DataInputStream::readChar() {
|
||||
}
|
||||
int a = stream->read();
|
||||
int b = stream->read();
|
||||
return (wchar_t)((a << 8) | (b & 0xff));
|
||||
return (char)((a << 8) | (b & 0xff));
|
||||
}
|
||||
|
||||
// Reads some bytes from an input stream and stores them into the buffer array
|
||||
@@ -399,8 +399,8 @@ unsigned short DataInputStream::readUnsignedShort() {
|
||||
//
|
||||
// Returns:
|
||||
// a Unicode string.
|
||||
std::wstring DataInputStream::readUTF() {
|
||||
std::wstring outputString;
|
||||
std::string DataInputStream::readUTF() {
|
||||
std::string outputString;
|
||||
if (stream == nullptr) {
|
||||
fprintf(
|
||||
stderr,
|
||||
@@ -413,11 +413,11 @@ std::wstring DataInputStream::readUTF() {
|
||||
|
||||
//// 4J Stu - I decided while writing DataOutputStream that we didn't need
|
||||
/// to bother using the UTF8 format / used in the java libs, and just write
|
||||
/// in/out as wchar_t all the time
|
||||
/// in/out as char all the time
|
||||
|
||||
/*for( unsigned short i = 0; i < UTFLength; i++)
|
||||
{
|
||||
wchar_t theChar = readChar();
|
||||
char theChar = readChar();
|
||||
outputString.push_back(theChar);
|
||||
}*/
|
||||
|
||||
@@ -447,7 +447,7 @@ std::wstring DataInputStream::readUTF() {
|
||||
break;
|
||||
} else if ((firstByte & 0x80) == 0x00) {
|
||||
// One byte UTF
|
||||
wchar_t readChar = (wchar_t)firstByte;
|
||||
char readChar = (char)firstByte;
|
||||
outputString.push_back(readChar);
|
||||
continue;
|
||||
} else if ((firstByte & 0xE0) == 0xC0) {
|
||||
@@ -473,8 +473,8 @@ std::wstring DataInputStream::readUTF() {
|
||||
break;
|
||||
}
|
||||
|
||||
wchar_t readChar =
|
||||
(wchar_t)(((firstByte & 0x1F) << 6) | (secondByte & 0x3F));
|
||||
char readChar =
|
||||
(char)(((firstByte & 0x1F) << 6) | (secondByte & 0x3F));
|
||||
outputString.push_back(readChar);
|
||||
continue;
|
||||
} else if ((firstByte & 0xF0) == 0xE0) {
|
||||
@@ -516,8 +516,8 @@ std::wstring DataInputStream::readUTF() {
|
||||
break;
|
||||
}
|
||||
|
||||
wchar_t readChar =
|
||||
(wchar_t)(((firstByte & 0x0F) << 12) |
|
||||
char readChar =
|
||||
(char)(((firstByte & 0x0F) << 12) |
|
||||
((secondByte & 0x3F) << 6) | (thirdByte & 0x3F));
|
||||
outputString.push_back(readChar);
|
||||
continue;
|
||||
|
||||
@@ -173,7 +173,7 @@ void DataOutputStream::writeUnsignedShort(unsigned short a) {
|
||||
// first. If no exception is thrown, the counter written is incremented by 2.
|
||||
// Parameters:
|
||||
// v - a char value to be written.
|
||||
void DataOutputStream::writeChar(wchar_t v) {
|
||||
void DataOutputStream::writeChar(char v) {
|
||||
stream->write((v >> 8) & 0xff);
|
||||
stream->write(v & 0xff);
|
||||
// TODO 4J Stu - Error handling?
|
||||
@@ -184,7 +184,7 @@ void DataOutputStream::writeChar(wchar_t v) {
|
||||
// Each character is written to the data output stream as if by the writeChar
|
||||
// method. If no exception is thrown, the counter written is incremented by
|
||||
// twice the length of s. Parameters: s - a String value to be written.
|
||||
void DataOutputStream::writeChars(const std::wstring& str) {
|
||||
void DataOutputStream::writeChars(const std::string& str) {
|
||||
for (unsigned int i = 0; i < str.length(); i++) {
|
||||
writeChar(str.at(i));
|
||||
// TODO 4J Stu - Error handling?
|
||||
@@ -212,7 +212,7 @@ void DataOutputStream::writeBoolean(bool b) {
|
||||
// of bytes written to the output stream. This will be at least two plus the
|
||||
// length of str, and at most two plus thrice the length of str. Parameters: str
|
||||
// - a string to be written.
|
||||
void DataOutputStream::writeUTF(const std::wstring& str) {
|
||||
void DataOutputStream::writeUTF(const std::string& str) {
|
||||
int strlen = (int)str.length();
|
||||
int utflen = 0;
|
||||
int c, count = 0;
|
||||
|
||||
@@ -51,7 +51,7 @@ bool FileSeek(std::FILE* file, int64_t offset, int origin) {
|
||||
// denies read access to the file.
|
||||
FileInputStream::FileInputStream(const File& file) : m_fileHandle(nullptr) {
|
||||
#if defined(_WIN32)
|
||||
m_fileHandle = _wfopen(file.getPath().c_str(), L"rb");
|
||||
m_fileHandle = _wfopen(file.getPath().c_str(), "rb");
|
||||
#else
|
||||
const std::string nativePath = std::filesystem::path(file.getPath()).string();
|
||||
m_fileHandle = std::fopen(nativePath.c_str(), "rb");
|
||||
|
||||
@@ -28,7 +28,7 @@ FileOutputStream::FileOutputStream(const File& file) : m_fileHandle(nullptr) {
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
m_fileHandle = _wfopen(file.getPath().c_str(), L"wb");
|
||||
m_fileHandle = _wfopen(file.getPath().c_str(), "wb");
|
||||
#else
|
||||
const std::string nativePath = std::filesystem::path(file.getPath()).string();
|
||||
m_fileHandle = std::fopen(nativePath.c_str(), "wb");
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "java/File.h"
|
||||
#include "java/InputOutputStream/FileInputStream.h"
|
||||
|
||||
InputStream* InputStream::getResourceAsStream(const std::wstring& fileName) {
|
||||
InputStream* InputStream::getResourceAsStream(const std::string& fileName) {
|
||||
File file(fileName);
|
||||
return file.exists() ? new FileInputStream(file) : nullptr;
|
||||
}
|
||||
@@ -29,11 +29,11 @@ int InputStreamReader::read() { return stream->readUTFChar(); }
|
||||
// Returns:
|
||||
// The number of characters read, or -1 if the end of the stream has been
|
||||
// reached
|
||||
int InputStreamReader::read(wchar_t cbuf[], unsigned int offset,
|
||||
int InputStreamReader::read(char cbuf[], unsigned int offset,
|
||||
unsigned int length) {
|
||||
unsigned int charsRead = 0;
|
||||
for (unsigned int i = offset; i < offset + length; i++) {
|
||||
wchar_t value = (wchar_t)stream->readUTFChar();
|
||||
char value = (char)stream->readUTFChar();
|
||||
if (value != -1) {
|
||||
cbuf[i] = value;
|
||||
charsRead++;
|
||||
|
||||
@@ -156,7 +156,7 @@ void System::ReverseULONGLONG(int64_t* pullVal) {
|
||||
pchVal1[7] = pchVal2[0];
|
||||
}
|
||||
|
||||
void System::ReverseWCHARA(wchar_t* pwch, int iLen) {
|
||||
void System::ReverseWCHARA(char* pwch, int iLen) {
|
||||
for (int i = 0; i < iLen; i++) {
|
||||
ReverseUSHORT((unsigned short*)&pwch[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user