MCPcopy Create free account
hub / github.com/ImpulseAdventure/JPEGsnoop / BufReadStr

Method BufReadStr

DbSigs.cpp:178–219  ·  view source on GitHub ↗

Attempt to read a line from the buffer This is a replacement for CStdioFile::ReadLine() Both 16-bit unicode and 8-bit SBCS encoding modes are supported (via bUni) Offset parameter is incremented accordingly Supports both newline and NULL for string termination

Source from the content-addressed store, hash-verified

176// Offset parameter is incremented accordingly
177// Supports both newline and NULL for string termination
178bool CDbSigs::BufReadStr(PBYTE pBuf,CString &strOut,unsigned nMaxBytes,bool bUni,unsigned &nOffsetBytes)
179{
180 ASSERT(pBuf);
181 CString strOutTmp;
182 bool bDone;
183
184 char chAsc;
185 wchar_t chUni;
186 unsigned nCharSz = ((bUni)?sizeof(wchar_t):sizeof(char));
187
188 bDone = false;
189 strOut = _T("");
190 // Ensure we don't overrun the buffer by calculating the last
191 // byte index required for each iteration.
192 for (unsigned nInd=nOffsetBytes;(!bDone)&&(nInd+nCharSz-1<nMaxBytes);nInd+=nCharSz) {
193 if (bUni) {
194 chUni = pBuf[nInd];
195 if ( (chUni != '\n') && (chUni != 0) ) {
196 strOut += chUni;
197 } else {
198 bDone = true;
199 nOffsetBytes = nInd+nCharSz;
200 }
201 } else {
202 chAsc = pBuf[nInd];
203 if ( (chAsc != '\n') && (chAsc != 0) ) {
204 strOut += chAsc;
205 } else {
206 bDone = true;
207 nOffsetBytes = nInd+nCharSz;
208 }
209 }
210 }
211
212 if (!bDone) {
213 nOffsetBytes = nMaxBytes;
214 // The input was not terminated, so we're still going to return what we got so far
215 return false;
216 }
217
218 return true;
219}
220
221// Return true if we managed to write entire string including terminator
222// without overrunning nMaxBytes

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected