refactor: nuke all widestrings and widechars everywhere
This commit is contained in:
@@ -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++;
|
||||
|
||||
Reference in New Issue
Block a user