Show stdstring.cpp syntax highlighted
/***************************************************************************
stdstring.cpp - String primitive chunk
-------------------
begin : Wed Feb 26 2003
copyright : (C) 2003 by Reality Rift Studios
email : mattias@realityrift.com
***************************************************************************
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the NeoEngine, NeoChunkIO, stdstring.cpp
The Initial Developer of the Original Code is Mattias Jansson.
Portions created by Mattias Jansson are Copyright (C) 2003
Reality Rift Studios. All Rights Reserved.
***************************************************************************/
#include "stdstring.h"
#include <neoengine/file.h>
#include <neoengine/strutil.h>
using namespace NeoEngine;
using namespace std;
namespace NeoChunkIO
{
int StringChunk::ReadData( File *pkFile, ChunkIO::CHUNKIOMODE eMode, unsigned int uiEnd )
{
if( eMode == ChunkIO::BINARY )
*pkFile >> m_strData;
else if( eMode == ChunkIO::ASCII )
{
static const int uiSize = 128;
char acData[uiSize];
char *pcData = acData;
char *pcEnd = acData + uiSize;
string strData;
while( true )
{
if( !pkFile->Read( pcData, 1 ) )
break;
if( *pcData == ']' )
{
pkFile->Seekg( -1, ios_base::cur );
break;
}
if( ++pcData == pcEnd )
{
strData.append( acData, uiSize );
pcData = acData;
}
}
if( pcData != acData )
strData.append( acData, pcData - acData );
m_strData = Strip( strData );
}
return( !*pkFile ? -1 : ( (int)m_strData.length() + 1 ) );
}
int StringChunk::WriteData( File *pkFile, ChunkIO::CHUNKIOMODE eMode, unsigned int uiLevel )
{
*pkFile << m_strData;
return( !*pkFile ? -1 : ( (int)m_strData.length() + 1 ) );
}
}; // namespace NeoChunkIO
See more files for this project here