mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em ReadChar e ReadChar8
This commit is contained in:
parent
98ee98d67a
commit
a945f460bd
@ -43,7 +43,7 @@ namespace csharp {
|
||||
}
|
||||
|
||||
virtual int32_t PeekChar();
|
||||
virtual int32_t Read();
|
||||
virtual int32_t Read(bool twoBytesPerChar = false);
|
||||
|
||||
virtual uint8_t ReadByte() {
|
||||
return InternalReadByte();
|
||||
@ -58,6 +58,7 @@ namespace csharp {
|
||||
}
|
||||
|
||||
virtual char ReadChar();
|
||||
virtual char ReadChar8();
|
||||
|
||||
virtual int16_t ReadInt16() {
|
||||
return ReadNumeric<int16_t>();
|
||||
@ -183,7 +184,6 @@ namespace csharp {
|
||||
std::shared_ptr<Stream> _stream;
|
||||
bool _leaveOpen;
|
||||
bool _disposed{false};
|
||||
bool _2BytesPerChar{ false };
|
||||
|
||||
std::vector<uint8_t> _auxBuffer;
|
||||
};
|
||||
|
@ -20,6 +20,7 @@ namespace xna {
|
||||
auto reader = csharp::BinaryReader(stream);
|
||||
auto bo = reader.ReadBoolean(); //reader.ReadChar()
|
||||
auto x = reader.ReadChar(); //x
|
||||
auto cedilha = reader.ReadChar8(); //ç
|
||||
auto sb = reader.ReadSByte(); //127
|
||||
auto by = reader.ReadByte(); //255
|
||||
auto i16 = reader.ReadInt16(); //32767
|
||||
|
@ -20,7 +20,7 @@ namespace csharp {
|
||||
return ch;
|
||||
}
|
||||
|
||||
int32_t BinaryReader::Read() {
|
||||
int32_t BinaryReader::Read(bool twoBytesPerChar) {
|
||||
if (_disposed)
|
||||
throw InvalidOperationException();
|
||||
|
||||
@ -36,7 +36,7 @@ namespace csharp {
|
||||
char singleChar = '\0';
|
||||
|
||||
while (charsRead == 0) {
|
||||
numBytes = _2BytesPerChar ? 2 : 1;
|
||||
numBytes = twoBytesPerChar ? 2 : 1;
|
||||
|
||||
auto r = _stream->ReadByte();
|
||||
|
||||
@ -46,7 +46,8 @@ namespace csharp {
|
||||
}
|
||||
if (numBytes == 2)
|
||||
{
|
||||
r |= _stream->ReadByte();
|
||||
auto r2 = _stream->ReadByte();
|
||||
r |= r2;
|
||||
|
||||
if (r == -1)
|
||||
{
|
||||
@ -90,7 +91,18 @@ namespace csharp {
|
||||
}
|
||||
|
||||
return static_cast<char>(value);
|
||||
}
|
||||
}
|
||||
|
||||
char BinaryReader::ReadChar8() {
|
||||
const auto value = Read(true);
|
||||
|
||||
if (value == -1)
|
||||
{
|
||||
throw EndOfStreamException(SR::IO_EOF_ReadBeyondEOF);
|
||||
}
|
||||
|
||||
return static_cast<char>(value);
|
||||
}
|
||||
|
||||
void BinaryReader::InternalRead(std::vector<uint8_t>& buffer) {
|
||||
if (_disposed)
|
||||
@ -142,11 +154,6 @@ namespace csharp {
|
||||
while (bufferLength > 0)
|
||||
{
|
||||
auto numBytes = bufferLength;
|
||||
|
||||
if (_2BytesPerChar)
|
||||
{
|
||||
numBytes <<= 1;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> byteBuffer;
|
||||
|
||||
@ -169,9 +176,7 @@ namespace csharp {
|
||||
bufferLength = charsRead.length();
|
||||
totalCharsRead += charsRead.length();
|
||||
}
|
||||
|
||||
// we may have read fewer than the number of characters requested if end of stream reached
|
||||
// or if the encoding makes the char count too big for the buffer (e.g. fallback sequence)
|
||||
|
||||
return totalCharsRead;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user