Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: core/src/fxcrt/fx_basic_buffer.cpp

Issue 1255113003: Kill CFX_ArchiveLoader / CFX_ArchiveSaver and subclasses (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/include/fxcrt/fx_basic.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/fxcrt/fx_basic.h" 7 #include "../../include/fxcrt/fx_basic.h"
8 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); 8 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf);
9 CFX_BinaryBuf::CFX_BinaryBuf() 9 CFX_BinaryBuf::CFX_BinaryBuf()
10 : m_AllocStep(0) 10 : m_AllocStep(0)
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return *this; 235 return *this;
236 } 236 }
237 void CFX_WideTextBuf::operator =(const CFX_WideStringC& str) 237 void CFX_WideTextBuf::operator =(const CFX_WideStringC& str)
238 { 238 {
239 CopyData(str.GetPtr(), str.GetLength() * sizeof(FX_WCHAR)); 239 CopyData(str.GetPtr(), str.GetLength() * sizeof(FX_WCHAR));
240 } 240 }
241 CFX_WideStringC CFX_WideTextBuf::GetWideString() const 241 CFX_WideStringC CFX_WideTextBuf::GetWideString() const
242 { 242 {
243 return CFX_WideStringC((const FX_WCHAR*)m_pBuffer, m_DataSize / sizeof(FX_WC HAR)); 243 return CFX_WideStringC((const FX_WCHAR*)m_pBuffer, m_DataSize / sizeof(FX_WC HAR));
244 } 244 }
245 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (uint8_t i)
246 {
247 if (m_pStream) {
248 m_pStream->WriteBlock(&i, 1);
249 } else {
250 m_SavingBuf.AppendByte(i);
251 }
252 return *this;
253 }
254 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (int i)
255 {
256 if (m_pStream) {
257 m_pStream->WriteBlock(&i, sizeof(int));
258 } else {
259 m_SavingBuf.AppendBlock(&i, sizeof(int));
260 }
261 return *this;
262 }
263 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (FX_DWORD i)
264 {
265 if (m_pStream) {
266 m_pStream->WriteBlock(&i, sizeof(FX_DWORD));
267 } else {
268 m_SavingBuf.AppendBlock(&i, sizeof(FX_DWORD));
269 }
270 return *this;
271 }
272 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (FX_FLOAT f)
273 {
274 if (m_pStream) {
275 m_pStream->WriteBlock(&f, sizeof(FX_FLOAT));
276 } else {
277 m_SavingBuf.AppendBlock(&f, sizeof(FX_FLOAT));
278 }
279 return *this;
280 }
281 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (const CFX_ByteStringC& bstr)
282 {
283 int len = bstr.GetLength();
284 if (m_pStream) {
285 m_pStream->WriteBlock(&len, sizeof(int));
286 m_pStream->WriteBlock(bstr.GetPtr(), len);
287 } else {
288 m_SavingBuf.AppendBlock(&len, sizeof(int));
289 m_SavingBuf.AppendBlock(bstr.GetPtr(), len);
290 }
291 return *this;
292 }
293 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (const FX_WCHAR* wstr)
294 {
295 FX_STRSIZE len = FXSYS_wcslen(wstr);
296 if (m_pStream) {
297 m_pStream->WriteBlock(&len, sizeof(int));
298 m_pStream->WriteBlock(wstr, len);
299 } else {
300 m_SavingBuf.AppendBlock(&len, sizeof(int));
301 m_SavingBuf.AppendBlock(wstr, len);
302 }
303 return *this;
304 }
305 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (const CFX_WideString& wstr)
306 {
307 CFX_ByteString encoded = wstr.UTF16LE_Encode();
308 return operator << (encoded);
309 }
310 void CFX_ArchiveSaver::Write(const void* pData, FX_STRSIZE dwSize)
311 {
312 if (m_pStream) {
313 m_pStream->WriteBlock(pData, dwSize);
314 } else {
315 m_SavingBuf.AppendBlock(pData, dwSize);
316 }
317 }
318 CFX_ArchiveLoader::CFX_ArchiveLoader(const uint8_t* pData, FX_DWORD dwSize)
319 {
320 m_pLoadingBuf = pData;
321 m_LoadingPos = 0;
322 m_LoadingSize = dwSize;
323 }
324 FX_BOOL CFX_ArchiveLoader::IsEOF()
325 {
326 return m_LoadingPos >= m_LoadingSize;
327 }
328 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (uint8_t& i)
329 {
330 if (m_LoadingPos >= m_LoadingSize) {
331 return *this;
332 }
333 i = m_pLoadingBuf[m_LoadingPos++];
334 return *this;
335 }
336 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (int& i)
337 {
338 Read(&i, sizeof(int));
339 return *this;
340 }
341 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (FX_DWORD& i)
342 {
343 Read(&i, sizeof(FX_DWORD));
344 return *this;
345 }
346 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (FX_FLOAT& i)
347 {
348 Read(&i, sizeof(FX_FLOAT));
349 return *this;
350 }
351 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (CFX_ByteString& str)
352 {
353 if (m_LoadingPos + 4 > m_LoadingSize) {
354 return *this;
355 }
356 int len;
357 operator >> (len);
358 str.Empty();
359 if (len <= 0 || m_LoadingPos + len > m_LoadingSize) {
360 return *this;
361 }
362 FX_CHAR* buffer = str.GetBuffer(len);
363 FXSYS_memcpy(buffer, m_pLoadingBuf + m_LoadingPos, len);
364 str.ReleaseBuffer(len);
365 m_LoadingPos += len;
366 return *this;
367 }
368 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (CFX_WideString& str)
369 {
370 CFX_ByteString encoded;
371 operator >> (encoded);
372 str = CFX_WideString::FromUTF16LE((const unsigned short*)encoded.c_str(), en coded.GetLength());
373 return *this;
374 }
375 FX_BOOL CFX_ArchiveLoader::Read(void* pBuf, FX_DWORD dwSize)
376 {
377 if (m_LoadingPos + dwSize > m_LoadingSize) {
378 return FALSE;
379 }
380 FXSYS_memcpy(pBuf, m_pLoadingBuf + m_LoadingPos, dwSize);
381 m_LoadingPos += dwSize;
382 return TRUE;
383 }
384 void CFX_BitStream::Init(const uint8_t* pData, FX_DWORD dwSize) 245 void CFX_BitStream::Init(const uint8_t* pData, FX_DWORD dwSize)
385 { 246 {
386 m_pData = pData; 247 m_pData = pData;
387 m_BitSize = dwSize * 8; 248 m_BitSize = dwSize * 8;
388 m_BitPos = 0; 249 m_BitPos = 0;
389 } 250 }
390 void CFX_BitStream::ByteAlign() 251 void CFX_BitStream::ByteAlign()
391 { 252 {
392 int mod = m_BitPos % 8; 253 int mod = m_BitPos % 8;
393 if (mod == 0) { 254 if (mod == 0) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) 410 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size)
550 { 411 {
551 if (!m_pFile) { 412 if (!m_pFile) {
552 return FALSE; 413 return FALSE;
553 } 414 }
554 if (!pBuf || size < 1) { 415 if (!pBuf || size < 1) {
555 return TRUE; 416 return TRUE;
556 } 417 }
557 return m_pFile->WriteBlock(pBuf, size); 418 return m_pFile->WriteBlock(pBuf, size);
558 } 419 }
OLDNEW
« no previous file with comments | « core/include/fxcrt/fx_basic.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698