40 #ifndef _resourcedatastream_cpp
41 #define _resourcedatastream_cpp
44 #include "stringtool.h"
45 #include "exception.h"
51 #define TEMP_STREAM_SIZE 128
57 #ifdef USENEWDATASTREAM
58 void IOStream::Advance(
const StreamOff Count)
60 this->SetStreamPosition(Count,SO_Current);
63 void IOStream::SetStreamPosition(
StreamPos Position)
65 this->SetReadPosition(Position);
66 this->SetWritePosition(Position);
69 void IOStream::SetStreamPosition(
StreamOff Offset, SeekOrigin Origin)
71 this->SetReadPosition(Offset,Origin);
72 this->SetWritePosition(Offset,Origin);
75 StreamPos IOStream::GetStreamPosition(
bool Read =
true)
77 if(Read)
return this->GetReadPosition();
78 else return this->GetWritePosition();
80 #else //USENEWDATASTREAM
120 size_t BufferSize = (this->
Size > 0 ? this->
Size : 4096);
121 char* Buffer =
new char[BufferSize];
127 size_t BytesRead =
Read(Buffer,BufferSize);
128 Ret.append(Buffer,BytesRead);
137 if(Delim.find_first_of(
'\n') != String::npos)
142 char Temp[TEMP_STREAM_SIZE];
143 size_t ChunkSize = std::min(MaxCount,(
size_t)TEMP_STREAM_SIZE - 1);
144 size_t TotalCount = 0;
145 size_t ReadCount = 0;
147 while(ChunkSize && (ReadCount =
Read(Temp,ChunkSize)) != 0)
149 Temp[ReadCount] =
'\0';
150 size_t Pos = std::strcspn(Temp,Delim.c_str());
154 this->
Advance((
long)(Pos + 1 - ReadCount));
159 std::memcpy(Buffer + TotalCount,Temp,Pos);
165 if(TrimCR && TotalCount && Buffer[TotalCount - 1] ==
'\r')
172 ChunkSize = std::min(MaxCount - TotalCount,(
size_t)TEMP_STREAM_SIZE - 1);
174 Buffer[TotalCount] =
'\0';
180 char Temp[TEMP_STREAM_SIZE];
184 while( (ReadCount =
Read(Temp,TEMP_STREAM_SIZE - 1)) != 0 )
186 Temp[ReadCount] =
'\0';
188 char* Pos = std::strchr(Temp,
'\n');
191 this->
Advance((
long)(Pos + 1 - Temp - ReadCount));
199 if(Ret.length() && Ret[Ret.length() - 1] ==
'\r')
201 Ret.erase(Ret.length() - 1, 1);
217 char Temp[TEMP_STREAM_SIZE];
218 size_t TotalBytes = 0;
219 size_t ReadCount = 0;
221 while( (ReadCount =
Read(Temp,TEMP_STREAM_SIZE - 1)) != 0 )
223 Temp[ReadCount] =
'\0';
224 size_t Position = std::strcspn(Temp,Delim.c_str());
226 if(Position < ReadCount)
228 this->
Advance((
long)(Position + 1 - ReadCount));
229 TotalBytes += Position + 1;
233 TotalBytes += ReadCount;