os/ossrv/lowlevellibsandfws/apputils/bsul/src/IniParserImpl.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/bsul/src/IniParserImpl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,955 @@
     1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// 8 and 16 bit ini file parser
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @internalAll
    1.24 +*/
    1.25 +
    1.26 +#include "IniParserImpl.h"
    1.27 +#include "inifile.h"
    1.28 +#include "s32file.h"
    1.29 +
    1.30 +namespace BSUL
    1.31 +{
    1.32 +/**
    1.33 +Creates a 8 bit section content iterator
    1.34 +this iterator is used to navigate through the key value pairs
    1.35 +within the section.Useful when the number of keys within the 
    1.36 +section is unknown.
    1.37 +@param aSectionName the name of the section to iterate
    1.38 +@param aIniDocument the document object containing the section
    1.39 +@return A pointer to a newly created CIniSecIter8 object
    1.40 +@leave	KErrNoMemory if not enough memory
    1.41 +		KErrArgument if aIniDocument is NULL
    1.42 +*/
    1.43 +EXPORT_C CIniSecIter8* CIniSecIter8::NewL(const TDesC8& aSectionName,const CIniDocument8* aIniDocument)
    1.44 +{
    1.45 +	CIniSecIter8* self=new (ELeave)CIniSecIter8();
    1.46 +	CleanupStack::PushL(self);
    1.47 +	self->iImpl=CIniSecIter8Impl::NewL(aSectionName,aIniDocument);
    1.48 +	CleanupStack::Pop();
    1.49 +	return self;	
    1.50 +}
    1.51 +
    1.52 +/**
    1.53 +Return the next key value pair within the section
    1.54 +@param aKey a pointer to contain the key name
    1.55 +@param aValue a pointer to contain the key value
    1.56 +@return ETrue if there are keyvalue pairs to return
    1.57 +	    EFalse if it is already end of section
    1.58 +@post the iterator points to the next available keyvalue pair
    1.59 +	  the aKeyName points to  the key name
    1.60 +	  the aKeyValue points to the key value
    1.61 +*/	
    1.62 +EXPORT_C TBool CIniSecIter8::Next(TPtrC8& aKey,TPtrC8& aValue)
    1.63 +{
    1.64 +	return iImpl->Next(aKey,aValue);
    1.65 +}
    1.66 +
    1.67 +/**
    1.68 +Look ahead in the section to check whether there is 
    1.69 +still any keyvalue pair in the section to be read
    1.70 +@return ETrue if it is already end of section
    1.71 +	    EFalse indicating the next keyvalue pair exists
    1.72 +*/
    1.73 +EXPORT_C TBool CIniSecIter8::End()
    1.74 +{
    1.75 +	return iImpl->End();
    1.76 +}
    1.77 +
    1.78 +/**
    1.79 +Reset the iterator to point to the first keypair value within
    1.80 +the section.
    1.81 +@post the iterator now points to first keypair in the section
    1.82 +*/
    1.83 +EXPORT_C void CIniSecIter8::Reset()
    1.84 +{
    1.85 +	iImpl->Reset();
    1.86 +}
    1.87 +
    1.88 +/**
    1.89 +Destructor
    1.90 +*/
    1.91 +EXPORT_C CIniSecIter8::~CIniSecIter8()
    1.92 +{
    1.93 +	delete iImpl;
    1.94 +}
    1.95 +
    1.96 +//Default constructor
    1.97 +CIniSecIter8::CIniSecIter8()
    1.98 +{
    1.99 +}
   1.100 +
   1.101 +//
   1.102 +
   1.103 +/** 
   1.104 +Opening 8 bit ini file for reading.If the supplied file name is a valid
   1.105 +ini file, it will instantiate the object and read the content of 
   1.106 +the ini file.If file not found it will simply instantiate the object.
   1.107 +The file is opened for read only and close directly after the construction
   1.108 +of this object is complete.
   1.109 +User will need to explicitly call Externalise(aFileName) to write the content back to ini file.
   1.110 +@param aFs the handle to the file session
   1.111 +@param aFileName the ini file name to read from
   1.112 +@return A pointer to a newly created CIniDocument8 object
   1.113 +*/
   1.114 +EXPORT_C CIniDocument8* CIniDocument8::NewL(RFs& aFs,const TDesC& aFileName)
   1.115 +	{
   1.116 +	CIniDocument8* self=new (ELeave)CIniDocument8();
   1.117 +	CleanupStack::PushL(self);
   1.118 +	self->iImpl=CIniDocument8Impl::NewL(aFs,aFileName);
   1.119 +	CleanupStack::Pop();
   1.120 +	return self;	
   1.121 +	}
   1.122 +
   1.123 +/**
   1.124 +Externalise the buffered content to an output file name
   1.125 +This will first write into a temporary file in the same directory and path
   1.126 +as the supplied aFileName.It will then replace the existing file or 
   1.127 +create a new file if does not exist yet.
   1.128 +@param aFileName the output file name to write to
   1.129 +@return KErrNone if no error
   1.130 +		Other System Wide errors
   1.131 +*/
   1.132 +EXPORT_C TInt CIniDocument8::Externalise(const TDesC& aFileName)
   1.133 +{
   1.134 +	TRAPD(r,iImpl->FlushL(aFileName));
   1.135 +	return r;
   1.136 +}
   1.137 +/**
   1.138 +Compare this document against another for differences.
   1.139 +@param aDoc to compare against.
   1.140 +@return True if same
   1.141 +		Otherwise false
   1.142 +*/
   1.143 +EXPORT_C TBool CIniDocument8::CompareDocs(CIniDocument8& aDoc) 
   1.144 +	{
   1.145 +	return (iImpl->CompareDocs( *(aDoc.iImpl) ));
   1.146 +	}	
   1.147 +
   1.148 +/** 
   1.149 +Get an array of the section name present in the ini document object
   1.150 +Note that any items inside this array will be cleared and the array will
   1.151 +be populated with the sections' names from this document object.
   1.152 +@param aSectionList an array of descriptor to contain the section name
   1.153 +@return KErrNone if successful, otherwise another of the system-wide error codes
   1.154 +@post aSectionList contains all the section name in the document object
   1.155 +*/
   1.156 +EXPORT_C TInt CIniDocument8::GetSectionList(RArray<TPtrC8>& aSectionList) const
   1.157 +	{
   1.158 +	return iImpl->GetSectionList(aSectionList);
   1.159 +	}
   1.160 +
   1.161 +/**
   1.162 +Get the value of a key within a section
   1.163 +@param aSectionName the section where the key resides
   1.164 +@param aKey the key name
   1.165 +@param aValue pointer to the key value
   1.166 +@return
   1.167 +	KErrNotFound if either section or keyname not found
   1.168 +	KErrNone if successful
   1.169 +@post aKeyValue now points to the key value
   1.170 +*/
   1.171 +EXPORT_C TInt CIniDocument8::GetKeyValue(const TDesC8& aSectionName,const TDesC8& aKey,TPtrC8& aValue) const
   1.172 +	{
   1.173 +	TRAPD(ret,iImpl->GetKeyValueL(aSectionName,aKey,aValue));
   1.174 +	return ret;
   1.175 +	}
   1.176 +
   1.177 +/**
   1.178 +Add a section to the ini document object
   1.179 +@param aSectionName the name of the section to be added
   1.180 +@return
   1.181 +	KErrNone if successful
   1.182 +	KErrAlreadyExists if the section with that name already exists
   1.183 +	Any other system wide error code
   1.184 +@post a section with that name is created and added to the document object
   1.185 +*/
   1.186 +EXPORT_C TInt CIniDocument8::AddSection(const TDesC8& aSectionName)
   1.187 +	{
   1.188 +	TRAPD(ret,iImpl->AddSectionL(aSectionName));
   1.189 +	return ret;	
   1.190 +	}
   1.191 +
   1.192 +/**
   1.193 +Remove an existing section from the ini document object
   1.194 +@param aSectionName the name of the section to be removed
   1.195 +@return KErrNone if successful
   1.196 +	    KErrNotFound if section does not exist
   1.197 +	    Any other system wide error code
   1.198 +@post if exist that section is removed from the document object	
   1.199 +*/	
   1.200 +EXPORT_C TInt CIniDocument8::RemoveSection(const TDesC8& aSectionName)
   1.201 +	{
   1.202 +	TRAPD(ret,iImpl->RemoveSectionL(aSectionName));
   1.203 +	return ret;
   1.204 +	}
   1.205 +
   1.206 +/**
   1.207 +Set the value of a key within a section.
   1.208 +This API offers the following flexibility:
   1.209 +-If section does not exist,create a section and key and value
   1.210 +-If section exists but key does not exist, create the key and value
   1.211 +-Else replace the existing key value with the new value
   1.212 +@param aSectionName the name of the section
   1.213 +@param aKey the name of the key
   1.214 +@param aValue the new value for this key
   1.215 +@return
   1.216 +	KErrNone if successful,any other system wide error code
   1.217 +*/
   1.218 +EXPORT_C TInt CIniDocument8::SetKey(const TDesC8& aSectionName,const TDesC8& aKey,const TDesC8& aValue)
   1.219 +	{
   1.220 +	TRAPD(ret,iImpl->SetKeyL(aSectionName,aKey,aValue));	
   1.221 +	return ret;
   1.222 +	}
   1.223 +
   1.224 +/**
   1.225 +Remove an existing key within a section
   1.226 +if supplied section or key name does not exist, it does nothing
   1.227 +@param aSectionName the name of the section where the key resides
   1.228 +@param aKey the name of the key to be removed
   1.229 +@post if exist that key is removed from the section
   1.230 +*/
   1.231 +EXPORT_C TInt CIniDocument8::RemoveKey(const TDesC8& aSectionName,const TDesC8& aKey)
   1.232 +	{
   1.233 +	TRAPD(ret,iImpl->RemoveKeyL(aSectionName,aKey));
   1.234 +	return ret;	
   1.235 +	}
   1.236 +
   1.237 +/**
   1.238 +Destructor
   1.239 +*/	
   1.240 +EXPORT_C CIniDocument8::~CIniDocument8()
   1.241 +	{
   1.242 +	delete iImpl;
   1.243 +	}
   1.244 +
   1.245 +CIniDocument8::CIniDocument8()
   1.246 +{
   1.247 +}
   1.248 +
   1.249 +//
   1.250 +/**
   1.251 +Creates a 8 bit light weight parser
   1.252 +@param aFs the handle to the file session
   1.253 +@param aFileName the ini file name to open
   1.254 +@return A pointer to a newly created CIniFile8 object
   1.255 +@leave	KErrNoMemory if not enough memory
   1.256 +		KErrNotFound if the supplied file does not exist
   1.257 +*/
   1.258 +EXPORT_C CIniFile8* CIniFile8::NewL(RFs& aFs,const TDesC& aFileName)
   1.259 +	{
   1.260 +	CIniFile8* self=new (ELeave)CIniFile8;
   1.261 +	CleanupStack::PushL(self);
   1.262 +	self->iImpl=CIniFile8Impl::NewL(aFs,aFileName);
   1.263 +	CleanupStack::Pop();
   1.264 +	return self;
   1.265 +	}
   1.266 +
   1.267 +/**
   1.268 +Public destructor
   1.269 +*/	
   1.270 +EXPORT_C CIniFile8::~CIniFile8()
   1.271 +	{
   1.272 +	delete iImpl;	
   1.273 +	}
   1.274 +
   1.275 +/**
   1.276 +Get the value of a key within a section
   1.277 +@param aSectionName the section where the key resides
   1.278 +@param aKeyName the key name
   1.279 +@param aValue pointer to the key value
   1.280 +@return
   1.281 +	KErrNotFound if either section or keyname not found
   1.282 +	KErrNone if successful
   1.283 +*/	
   1.284 +EXPORT_C TInt CIniFile8::FindVar(const TDesC8& aSectionName,const TDesC8& aKeyName,TPtrC8& aValue)	const
   1.285 +	{
   1.286 +	return iImpl->FindVar(aSectionName,aKeyName,aValue);
   1.287 +	}
   1.288 +	
   1.289 +CIniFile8::CIniFile8(){}
   1.290 +
   1.291 +//
   1.292 +/**
   1.293 +Creates a 16 bit section content iterator
   1.294 +this iterator is used to navigate through the key value pairs
   1.295 +within the section.Useful when the number of keys within the 
   1.296 +section is unknown.
   1.297 +@param aSectionName the name of the section to iterate
   1.298 +@param aIniDocument the document object containing the section
   1.299 +@return A pointer to a newly created CIniSecIter16 object
   1.300 +@leave	KErrNoMemory if not enough memory
   1.301 +		KErrArgument if aIniDocument is NULL
   1.302 +*/
   1.303 +EXPORT_C CIniSecIter16* CIniSecIter16::NewL(const TDesC16& aSectionName,const CIniDocument16* aIniDocument)
   1.304 +{
   1.305 +	CIniSecIter16* self=new (ELeave)CIniSecIter16();
   1.306 +	CleanupStack::PushL(self);
   1.307 +	self->iImpl=CIniSecIter16Impl::NewL(aSectionName,aIniDocument);
   1.308 +	CleanupStack::Pop();
   1.309 +	return self;	
   1.310 +}
   1.311 +
   1.312 +/**
   1.313 +Return the next key value pair within the section
   1.314 +@param aKey a pointer to contain the key name
   1.315 +@param aValue a pointer to contain the key value
   1.316 +@return ETrue if there are keyvalue pairs to return
   1.317 +	    EFalse if it is already end of section
   1.318 +@post the iterator points to the next available keyvalue pair
   1.319 +	  the aKeyName points to  the key name
   1.320 +	  the aKeyValue points to the key value
   1.321 +*/	
   1.322 +EXPORT_C TBool CIniSecIter16::Next(TPtrC16& aKey,TPtrC16& aValue)
   1.323 +{
   1.324 +	return iImpl->Next(aKey,aValue);
   1.325 +}
   1.326 +
   1.327 +/**
   1.328 +Look ahead in the section to check whether there is 
   1.329 +still any keyvalue pair in the section to be read
   1.330 +@return ETrue if it is already end of section
   1.331 +	    EFalse indicating the next keyvalue pair exists
   1.332 +*/
   1.333 +EXPORT_C TBool CIniSecIter16::End()
   1.334 +{
   1.335 +	return iImpl->End();
   1.336 +}
   1.337 +
   1.338 +/**
   1.339 +Reset the iterator to point to the first keypair value within
   1.340 +the section.
   1.341 +@post the iterator now points to first keypair in the section
   1.342 +*/
   1.343 +EXPORT_C void CIniSecIter16::Reset()
   1.344 +{
   1.345 +	iImpl->Reset();
   1.346 +}
   1.347 +
   1.348 +/**
   1.349 +Destructor
   1.350 +*/
   1.351 +EXPORT_C CIniSecIter16::~CIniSecIter16()
   1.352 +{
   1.353 +	delete iImpl;
   1.354 +}
   1.355 +
   1.356 +//Default constructor
   1.357 +CIniSecIter16::CIniSecIter16()
   1.358 +{
   1.359 +}
   1.360 +
   1.361 +//
   1.362 +
   1.363 +/** 
   1.364 +Opening 16 bit ini file for reading.If the supplied file name is a valid
   1.365 +ini file, it will instantiate the object and read the content of 
   1.366 +the ini file.If file not found it will simply instantiate the object.
   1.367 +The file is opened for read only and close directly after the construction
   1.368 +of this object is complete.
   1.369 +User will need to explicitly call Externalise(aFileName) to write the content back to ini file.
   1.370 +@param aFs the handle to the file session
   1.371 +@param aFileName the ini file name to read from
   1.372 +@return A pointer to a newly created CIniDocument16 object
   1.373 +*/
   1.374 +EXPORT_C CIniDocument16* CIniDocument16::NewL(RFs& aFs,const TDesC& aFileName)
   1.375 +	{
   1.376 +	CIniDocument16* self=new (ELeave)CIniDocument16();
   1.377 +	CleanupStack::PushL(self);
   1.378 +	self->iImpl=CIniDocument16Impl::NewL(aFs,aFileName);
   1.379 +	CleanupStack::Pop();
   1.380 +	return self;	
   1.381 +	}
   1.382 +
   1.383 +/**
   1.384 +Flush the buffered content to an output file name
   1.385 +This will first write into a temporary file in the same directory and path
   1.386 +as the supplied aFileName.It will then replace the existing file or 
   1.387 +create a new file if does not exist yet.
   1.388 +@param aFileName the output file name to write to
   1.389 +@return KErrNone if no error
   1.390 +		Other System Wide errors
   1.391 +*/
   1.392 +EXPORT_C TInt CIniDocument16::Externalise(const TDesC& aFileName)
   1.393 +{
   1.394 +	TRAPD(r,iImpl->FlushL(aFileName));
   1.395 +	return r;
   1.396 +}
   1.397 +	
   1.398 +/** 
   1.399 +Get an array of the section name present in the ini document object
   1.400 +Note that any items inside this array will be cleared and the array will
   1.401 +be populated with the sections' names from this document object.
   1.402 +@param aSectionList an array of descriptor to contain the section name
   1.403 +@return KErrNone if successful, otherwise another of the system-wide error codes
   1.404 +@post aSectionList contains all the section name in the document object
   1.405 +*/
   1.406 +EXPORT_C TInt CIniDocument16::GetSectionList(RArray<TPtrC16>& aSectionList) const
   1.407 +	{
   1.408 +	return iImpl->GetSectionList(aSectionList);
   1.409 +	}
   1.410 +
   1.411 +/**
   1.412 +Get the value of a key within a section
   1.413 +@param aSectionName the section where the key resides
   1.414 +@param aKey the key name
   1.415 +@param aValue pointer to the key value
   1.416 +@return
   1.417 +	KErrNotFound if either section or keyname not found
   1.418 +	KErrNone if successful
   1.419 +@post aKeyValue now points to the key value
   1.420 +*/
   1.421 +EXPORT_C TInt CIniDocument16::GetKeyValue(const TDesC16& aSectionName,const TDesC16& aKey,TPtrC16& aValue) const
   1.422 +	{
   1.423 +	TRAPD(ret,iImpl->GetKeyValueL(aSectionName,aKey,aValue));
   1.424 +	return ret;
   1.425 +	}
   1.426 +
   1.427 +/**
   1.428 +Add a section to the ini document object
   1.429 +@param aSectionName the name of the section to be added
   1.430 +@return
   1.431 +	KErrNone if successful
   1.432 +	KErrAlreadyExists if the section with that name already exists
   1.433 +	Any other system wide error code
   1.434 +@post a section with that name is created and added to the document object
   1.435 +*/
   1.436 +EXPORT_C TInt CIniDocument16::AddSection(const TDesC16& aSectionName)
   1.437 +	{
   1.438 +	TRAPD(ret,iImpl->AddSectionL(aSectionName));
   1.439 +	return ret;	
   1.440 +	}
   1.441 +
   1.442 +/**
   1.443 +Remove an existing section from the ini document object
   1.444 +@param aSectionName the name of the section to be removed
   1.445 +@return KErrNone if successful
   1.446 +	    KErrNotFound if section does not exist
   1.447 +	    Any other system wide error code
   1.448 +@post if exist that section is removed from the document object	
   1.449 +*/	
   1.450 +EXPORT_C TInt CIniDocument16::RemoveSection(const TDesC16& aSectionName)
   1.451 +	{
   1.452 +	TRAPD(ret,iImpl->RemoveSectionL(aSectionName));
   1.453 +	return ret;
   1.454 +	}
   1.455 +
   1.456 +/**
   1.457 +Set the value of a key within a section.
   1.458 +This API offers the following flexibility:
   1.459 +-If section does not exist,create a section and key and value
   1.460 +-If section exists but key does not exist, create the key and value
   1.461 +-Else replace the existing key value with the new value
   1.462 +@param aSectionName the name of the section
   1.463 +@param aKey the name of the key
   1.464 +@param aValue the new value for this key
   1.465 +@return
   1.466 +	KErrNone if successful,any other system wide error code
   1.467 +*/
   1.468 +EXPORT_C TInt CIniDocument16::SetKey(const TDesC16& aSectionName,const TDesC16& aKey,const TDesC16& aValue)
   1.469 +	{
   1.470 +	TRAPD(ret,iImpl->SetKeyL(aSectionName,aKey,aValue));	
   1.471 +	return ret;
   1.472 +	}
   1.473 +
   1.474 +/**
   1.475 +Remove an existing key within a section
   1.476 +if supplied section or key name does not exist, it does nothing
   1.477 +@param aSectionName the name of the section where the key resides
   1.478 +@param aKey the name of the key to be removed
   1.479 +@post if exist that key is removed from the section
   1.480 +*/
   1.481 +EXPORT_C TInt CIniDocument16::RemoveKey(const TDesC16& aSectionName,const TDesC16& aKey)
   1.482 +	{
   1.483 +	TRAPD(ret,iImpl->RemoveKeyL(aSectionName,aKey));
   1.484 +	return ret;	
   1.485 +	}
   1.486 +/**
   1.487 +Compare two document objects. If names, keys or values differ, a false is returned,
   1.488 +else a true is returned.
   1.489 +@param aDoc name of the document to compare against this object.
   1.490 +*/
   1.491 +EXPORT_C TBool CIniDocument16::CompareDocs(CIniDocument16& aDoc)	
   1.492 +	{
   1.493 +	return (iImpl->CompareDocs( *(aDoc.iImpl) ));
   1.494 +	}	
   1.495 +/**
   1.496 +Destructor
   1.497 +*/	
   1.498 +EXPORT_C CIniDocument16::~CIniDocument16()
   1.499 +	{
   1.500 +	delete iImpl;
   1.501 +	}
   1.502 +
   1.503 +CIniDocument16::CIniDocument16(){}
   1.504 +
   1.505 +//
   1.506 +/**
   1.507 +Creates a 16 bit light weight parser
   1.508 +@param aFs the handle to the file session
   1.509 +@param aFileName the ini file name to open
   1.510 +@return A pointer to a newly created CIniFile16 object
   1.511 +@leave	KErrNoMemory if not enough memory
   1.512 +		KErrNotFound if the supplied file does not exist
   1.513 +*/
   1.514 +EXPORT_C CIniFile16* CIniFile16::NewL(RFs& aFs,const TDesC& aFileName)
   1.515 +	{
   1.516 +	return CIniFile16::NewL(aFs,aFileName,EFalse);
   1.517 +	}
   1.518 +
   1.519 +/**
   1.520 +Creates a 16 bit light weight parser
   1.521 +@param aFs the handle to the file session
   1.522 +@param aFileName the ini file name to open
   1.523 +@param aConvert8To16 upconvert 8 bit files otherwise leave with KErrCorrupt
   1.524 +@return A pointer to a newly created CIniFile16 object
   1.525 +@leave	KErrNoMemory if not enough memory
   1.526 +		KErrNotFound if the supplied file does not exist
   1.527 +*/
   1.528 +EXPORT_C CIniFile16* CIniFile16::NewL(RFs& aFs,const TDesC& aFileName,TBool aConvert8To16)
   1.529 +	{
   1.530 +	CIniFile16* self=new (ELeave)CIniFile16;
   1.531 +	CleanupStack::PushL(self);
   1.532 +	self->iImpl=CIniFile16Impl::NewL(aFs,aFileName,aConvert8To16);
   1.533 +	CleanupStack::Pop();
   1.534 +	return self;
   1.535 +	}
   1.536 +
   1.537 +/**
   1.538 +Public Destructor
   1.539 +*/	
   1.540 +EXPORT_C CIniFile16::~CIniFile16()
   1.541 +	{
   1.542 +	delete iImpl;	
   1.543 +	}
   1.544 +
   1.545 +/**
   1.546 +Get the value of a key within a section
   1.547 +@param aSectionName the section where the key resides
   1.548 +@param aKeyName the key name
   1.549 +@param aValue pointer to the key value
   1.550 +@return
   1.551 +	KErrNotFound if either section or keyname not found
   1.552 +	KErrNone if successful
   1.553 +*/		
   1.554 +EXPORT_C TInt CIniFile16::FindVar(const TDesC16& aSectionName,const TDesC16& aKeyName,TPtrC16& aValue)const
   1.555 +	{
   1.556 +	return iImpl->FindVar(aSectionName,aKeyName,aValue);
   1.557 +	}
   1.558 +	
   1.559 +CIniFile16::CIniFile16(){}
   1.560 +
   1.561 +//
   1.562 +
   1.563 +CIniDocument8Impl* CIniDocument8Impl::NewL(RFs& aFs,const TDesC& aFileName)
   1.564 +{
   1.565 +	CIniDocument8Impl* self= new (ELeave) CIniDocument8Impl();
   1.566 +	CleanupStack::PushL(self);
   1.567 +	self->ConstructL(aFs,aFileName);
   1.568 +	CleanupStack::Pop();
   1.569 +	return self;
   1.570 +}
   1.571 +
   1.572 +// This method will panic if, when reading the input configuration file, a key
   1.573 +// is attempted to be processed without a valid section name being already defined.
   1.574 +void CIniDocument8Impl::ConstructL(RFs& aFs,const TDesC& aFileName)
   1.575 +{
   1.576 +	TInt    filesize=0;
   1.577 +	TInt    startOfLine=0;
   1.578 +	CIniSection8* section = NULL;
   1.579 +	HBufC8* fileBuffer=NULL;
   1.580 +	iTempImpl=new (ELeave)CIniDocumentTmpl8(aFs,ETrue);
   1.581 +	
   1.582 +	TRAPD(ret,GetBufferL(aFs,aFileName,fileBuffer));
   1.583 +	//if the file is not found, assume we are creating a new file.
   1.584 +	if (ret==KErrNotFound)
   1.585 +		{
   1.586 +		return;
   1.587 +		}
   1.588 +	User::LeaveIfError(ret);
   1.589 +	if (!fileBuffer)
   1.590 +		{	
   1.591 +		return;	
   1.592 +		}	
   1.593 +	CleanupStack::PushL(fileBuffer);
   1.594 +	filesize = fileBuffer->Length();
   1.595 +	TPtrC8 bufferDescriptor = fileBuffer->Des();
   1.596 +	while (startOfLine < filesize)
   1.597 +		{
   1.598 +		TPtrC8 myBuffer = ExtractLineFromBuffer<HBufC8, TPtrC8>(bufferDescriptor, startOfLine);
   1.599 +		CIniLine8* line = CIniLine8::NewLC(myBuffer);
   1.600 +		startOfLine += (line->LineBuffer()).Length();
   1.601 +		
   1.602 +		switch(line->LineType())
   1.603 +			{
   1.604 +			case ESection:
   1.605 +			 	section = CIniSection8::NewLC(line);
   1.606 +			 	iTempImpl->AddSectionL(section);
   1.607 +			 	CleanupStack::Pop(section);
   1.608 +			 	break;
   1.609 +			 	
   1.610 +			case EKeyValue:
   1.611 +				{
   1.612 +				CIniKey8* key = CIniKey8::NewLC(line);
   1.613 +				if (section == NULL)
   1.614 +					{
   1.615 +					User::Leave(KErrCorrupt);	//Unnamed sections within the file are not allowed but not preventable, hence leave if found. 
   1.616 +					}
   1.617 +			 	section->InsertKeyL(key);
   1.618 +			 	CleanupStack::Pop(key);
   1.619 +			 	break;
   1.620 +				}
   1.621 +				
   1.622 +			case EComment:
   1.623 +				break;
   1.624 +				
   1.625 +			default:
   1.626 +				User::Panic(_L("Invalid LineType"), KErrCorrupt);	// programming error.
   1.627 +			}
   1.628 +		iTempImpl->AppendIntoQueue(line);
   1.629 +		CleanupStack::Pop(line);
   1.630 +		}
   1.631 +	CleanupStack::PopAndDestroy(fileBuffer);
   1.632 +}
   1.633 +
   1.634 +void CIniDocument8Impl::FlushL(const TDesC& aFileName)
   1.635 +{
   1.636 +	iTempImpl->FlushL(aFileName);
   1.637 +}
   1.638 +
   1.639 +TInt CIniDocument8Impl::GetSectionList(RArray<TPtrC8>& aSectionList) const
   1.640 +{
   1.641 +	return iTempImpl->GetSectionList(aSectionList);
   1.642 +}
   1.643 +
   1.644 +void CIniDocument8Impl::GetKeyValueL(const TDesC8& aSectionName,const TDesC8& aKeyName,TPtrC8& aKeyValue) const
   1.645 +{
   1.646 +	iTempImpl->GetKeyValueL(aSectionName,aKeyName,aKeyValue);
   1.647 +}
   1.648 +
   1.649 +void CIniDocument8Impl::AddSectionL(const TDesC8& aSectionName)
   1.650 +{
   1.651 +	iTempImpl->AddSectionL(aSectionName);
   1.652 +}
   1.653 +
   1.654 +void CIniDocument8Impl::RemoveSectionL(const TDesC8& aSectionName)
   1.655 +{
   1.656 +	iTempImpl->RemoveSectionL(aSectionName);
   1.657 +}
   1.658 +
   1.659 +void CIniDocument8Impl::SetKeyL(const TDesC8& aSectionName,const TDesC8& aKeyName,const TDesC8& aKeyValue)
   1.660 +{
   1.661 +	iTempImpl->SetKeyL(aSectionName,aKeyName,aKeyValue);
   1.662 +}
   1.663 +
   1.664 +void CIniDocument8Impl::RemoveKeyL(const TDesC8& aSectionName,const TDesC8& aKeyName)
   1.665 +{
   1.666 +	iTempImpl->RemoveKeyL(aSectionName,aKeyName);
   1.667 +}
   1.668 +
   1.669 +CIniDocument8Impl::~CIniDocument8Impl()
   1.670 +{
   1.671 +	delete iTempImpl;
   1.672 +}
   1.673 +
   1.674 +CIniSection8* CIniDocument8Impl::SectionL(const TDesC8& aSectionName) const
   1.675 +{
   1.676 +	return iTempImpl->SectionL(aSectionName);
   1.677 +}
   1.678 +
   1.679 +TBool CIniDocument8Impl::CompareDocs(CIniDocument8Impl& aDocImpl) 
   1.680 +{
   1.681 +	return(iTempImpl->CompareDocs(*aDocImpl.iTempImpl));
   1.682 +}
   1.683 +
   1.684 +//
   1.685 +CIniDocument16Impl* CIniDocument16Impl::NewL(RFs& aFs,const TDesC& aFileName)
   1.686 +{
   1.687 +	CIniDocument16Impl* self= new (ELeave) CIniDocument16Impl();
   1.688 +	CleanupStack::PushL(self);
   1.689 +	self->ConstructL(aFs,aFileName);
   1.690 +	CleanupStack::Pop();
   1.691 +	return self;
   1.692 +}
   1.693 +
   1.694 +void CIniDocument16Impl::ConstructL(RFs& aFs,const TDesC& aFileName)
   1.695 +{
   1.696 +	TInt    filesize=0;
   1.697 +	TInt    startOfLine=0;
   1.698 +	CIniSection16* section = NULL;
   1.699 +	HBufC8* fileBuffer=NULL;
   1.700 +	iTempImpl=new (ELeave)CIniDocumentTmpl16(aFs,EFalse);
   1.701 +	
   1.702 +	TRAPD(ret,GetBufferL(aFs,aFileName,fileBuffer));
   1.703 +	//if the file is not found, assume we are creating a new file.
   1.704 +	if (ret==KErrNotFound)
   1.705 +		{
   1.706 +		return;
   1.707 +		}
   1.708 +	User::LeaveIfError(ret);
   1.709 +	if (!fileBuffer)
   1.710 +		{	
   1.711 +		return;	
   1.712 +		}	
   1.713 +	CleanupStack::PushL(fileBuffer);
   1.714 +	filesize = fileBuffer->Length()/2;
   1.715 +	
   1.716 +	// process the filemark at the start of the file.
   1.717 +	const TUint16* rawptr16=reinterpret_cast<const TUint16*>(fileBuffer->Ptr());
   1.718 +	TPtrC16 bufferPtr;
   1.719 +	
   1.720 +	//must always start with the byte ordering characters
   1.721 +	bufferPtr.Set(rawptr16,1);
   1.722 +	if (bufferPtr.Compare(_L("\xFEFF"))!=0)
   1.723 +		User::Leave(KErrCorrupt);
   1.724 +	//skip the byte ordering character(FEFF) assuming little endian
   1.725 +	bufferPtr.Set(rawptr16+1,(filesize - 1));	
   1.726 +	
   1.727 +	while (startOfLine < (filesize-1))
   1.728 +		{
   1.729 +		TPtrC16 myBuffer = ExtractLineFromBuffer<HBufC16, TPtrC16>(bufferPtr, startOfLine);
   1.730 +		CIniLine16* line = CIniLine16::NewLC(myBuffer);
   1.731 +		startOfLine += (line->LineBuffer()).Length();
   1.732 +		
   1.733 +		TLineType lineType = line->LineType();
   1.734 +		switch (lineType)
   1.735 +			{
   1.736 +			case ESection:
   1.737 +				section = CIniSection16::NewLC(line);
   1.738 +				iTempImpl->AddSectionL(section);
   1.739 +			 	CleanupStack::Pop(section);
   1.740 +			 	break;
   1.741 +			 	
   1.742 +			case EKeyValue:
   1.743 +				{
   1.744 +				CIniKey16* key = CIniKey16::NewLC(line);
   1.745 +				
   1.746 +				if (section == NULL)
   1.747 +					{
   1.748 +					User::Leave(KErrCorrupt);	//Unnamed sections are not allowed hence leave if found.
   1.749 +					}
   1.750 +				section->InsertKeyL(key);
   1.751 +				CleanupStack::Pop(key);
   1.752 +			 	break;
   1.753 +				}
   1.754 +				
   1.755 +			case EComment:
   1.756 +				break;
   1.757 +				
   1.758 +			default:
   1.759 +				User::Panic(_L("Invalid LineType"), KErrCorrupt);
   1.760 +			}
   1.761 +		iTempImpl->AppendIntoQueue(line);
   1.762 +		CleanupStack::Pop(line);
   1.763 +	}	
   1.764 +	CleanupStack::PopAndDestroy(fileBuffer);
   1.765 +}
   1.766 +
   1.767 +void CIniDocument16Impl::FlushL(const TDesC& aFileName)
   1.768 +{
   1.769 +	iTempImpl->FlushL(aFileName);
   1.770 +}
   1.771 +
   1.772 +TInt CIniDocument16Impl::GetSectionList(RArray<TPtrC16>& aSectionList) const
   1.773 +{
   1.774 +	return iTempImpl->GetSectionList(aSectionList);
   1.775 +}
   1.776 +
   1.777 +void CIniDocument16Impl::GetKeyValueL(const TDesC16& aSectionName,const TDesC16& aKeyName,TPtrC16& aKeyValue) const
   1.778 +{
   1.779 +	iTempImpl->GetKeyValueL(aSectionName,aKeyName,aKeyValue);
   1.780 +}
   1.781 +
   1.782 +void CIniDocument16Impl::AddSectionL(const TDesC16& aSectionName)
   1.783 +{
   1.784 +	iTempImpl->AddSectionL(aSectionName);
   1.785 +}
   1.786 +
   1.787 +void CIniDocument16Impl::RemoveSectionL(const TDesC16& aSectionName)
   1.788 +{
   1.789 +	iTempImpl->RemoveSectionL(aSectionName);
   1.790 +}
   1.791 +
   1.792 +void CIniDocument16Impl::SetKeyL(const TDesC16& aSectionName,const TDesC16& aKeyName,const TDesC16& aKeyValue)
   1.793 +{
   1.794 +	iTempImpl->SetKeyL(aSectionName,aKeyName,aKeyValue);
   1.795 +}
   1.796 +
   1.797 +void CIniDocument16Impl::RemoveKeyL(const TDesC16& aSectionName,const TDesC16& aKeyName)
   1.798 +{
   1.799 +	iTempImpl->RemoveKeyL(aSectionName,aKeyName);
   1.800 +}
   1.801 +
   1.802 +CIniDocument16Impl::~CIniDocument16Impl()
   1.803 +	{
   1.804 +	delete iTempImpl;
   1.805 +	}
   1.806 +
   1.807 +CIniSection16* CIniDocument16Impl::SectionL(const TDesC16& aSectionName) const
   1.808 +{
   1.809 +	return iTempImpl->SectionL(aSectionName);
   1.810 +}
   1.811 +
   1.812 +TBool CIniDocument16Impl::CompareDocs(CIniDocument16Impl& aDocImpl) 
   1.813 +{
   1.814 +	return(iTempImpl->CompareDocs(*(aDocImpl.iTempImpl)));
   1.815 +}
   1.816 +
   1.817 +//	
   1.818 +
   1.819 +CIniSecIter8Impl* CIniSecIter8Impl::NewL(const TDesC8& aSectionName,const CIniDocument8* aIniDocument) 
   1.820 +	{
   1.821 +	CIniSecIter8Impl* self=new (ELeave)CIniSecIter8Impl();
   1.822 +	CleanupStack::PushL(self);
   1.823 +	self->ConstructL(aSectionName,aIniDocument);
   1.824 +	CleanupStack::Pop();
   1.825 +	return self;
   1.826 +	}
   1.827 +
   1.828 +void CIniSecIter8Impl::ConstructL(const TDesC8& aSectionName,const CIniDocument8* aIniDocument)
   1.829 +	{
   1.830 +	iTempImpl=new (ELeave)CIniSecIterTmpl8();
   1.831 +	if (!aIniDocument)
   1.832 +		User::Leave(KErrArgument);
   1.833 +	iTempImpl->iSection=aIniDocument->iImpl->SectionL(aSectionName);
   1.834 +	}
   1.835 +	
   1.836 +TBool CIniSecIter8Impl::Next(TPtrC8& aKeyName,TPtrC8& aKeyValue)	
   1.837 +	{
   1.838 +	return iTempImpl->Next(aKeyName,aKeyValue);
   1.839 +	}
   1.840 +	
   1.841 +void CIniSecIter8Impl::Reset()
   1.842 +	{
   1.843 +	iTempImpl->Reset();	
   1.844 +	}
   1.845 +
   1.846 +//
   1.847 +CIniSecIter16Impl* CIniSecIter16Impl::NewL(const TDesC16& aSectionName,const CIniDocument16* aIniDocument) 
   1.848 +	{
   1.849 +	CIniSecIter16Impl* self=new (ELeave)CIniSecIter16Impl();
   1.850 +	CleanupStack::PushL(self);
   1.851 +	self->ConstructL(aSectionName,aIniDocument);
   1.852 +	CleanupStack::Pop();
   1.853 +	return self;
   1.854 +	}
   1.855 +
   1.856 +void CIniSecIter16Impl::ConstructL(const TDesC16& aSectionName,const CIniDocument16* aIniDocument)
   1.857 +	{
   1.858 +	iTempImpl=new (ELeave)CIniSecIterTmpl16();
   1.859 +	if (!aIniDocument)
   1.860 +		User::Leave(KErrArgument);	
   1.861 +	iTempImpl->iSection=aIniDocument->iImpl->SectionL(aSectionName);
   1.862 +	}
   1.863 +	
   1.864 +TBool CIniSecIter16Impl::Next(TPtrC16& aKeyName,TPtrC16& aKeyValue)	
   1.865 +	{
   1.866 +	return iTempImpl->Next(aKeyName,aKeyValue);
   1.867 +	}
   1.868 +	
   1.869 +void CIniSecIter16Impl::Reset()
   1.870 +	{
   1.871 +	iTempImpl->Reset();
   1.872 +	}
   1.873 +
   1.874 +//
   1.875 +CIniFile8Impl* CIniFile8Impl::NewL(RFs& aFs,const TDesC& aFileName)
   1.876 +	{
   1.877 +	CIniFile8Impl* self=new (ELeave)CIniFile8Impl;
   1.878 +	CleanupStack::PushL(self);
   1.879 +	self->ConstructL(aFs,aFileName);
   1.880 +	CleanupStack::Pop();
   1.881 +	return self;
   1.882 +	}
   1.883 +
   1.884 +void CIniFile8Impl::ConstructL(RFs& aFs,const TDesC& aFileName)
   1.885 +	{
   1.886 +	iTempImpl=new (ELeave)CIniFileTmpl8();
   1.887 +	HBufC8* tempBuffer=NULL;
   1.888 +	//read the file
   1.889 +	GetBufferL(aFs,aFileName,tempBuffer);
   1.890 +	if (tempBuffer)
   1.891 +		{
   1.892 +		CleanupStack::PushL(tempBuffer);
   1.893 +		iTempImpl->ProcessBufferL(*tempBuffer);
   1.894 +		CleanupStack::Pop();
   1.895 +		delete tempBuffer;
   1.896 +		}
   1.897 +	}
   1.898 +
   1.899 +TInt CIniFile8Impl::FindVar(const TDesC8& aSection,const TDesC8& aKey,TPtrC8& aValue)
   1.900 +	{
   1.901 +	return iTempImpl->FindVar(aSection,aKey,aValue);	
   1.902 +	}
   1.903 +
   1.904 +//
   1.905 +CIniFile16Impl* CIniFile16Impl::NewL(RFs& aFs,const TDesC& aFileName,TBool aConvert8To16)
   1.906 +	{
   1.907 +	CIniFile16Impl* self=new (ELeave)CIniFile16Impl;
   1.908 +	CleanupStack::PushL(self);
   1.909 +	self->ConstructL(aFs,aFileName,aConvert8To16);
   1.910 +	CleanupStack::Pop();
   1.911 +	return self;
   1.912 +	}
   1.913 +
   1.914 +void CIniFile16Impl::ConstructL(RFs& aFs,const TDesC& aFileName,TBool aConvert8To16)
   1.915 +	{
   1.916 +	iTempImpl=new (ELeave)CIniFileTmpl16();
   1.917 +	HBufC8* tempBuffer=NULL;
   1.918 +	//read the file
   1.919 +	GetBufferL(aFs,aFileName,tempBuffer);
   1.920 +	if (tempBuffer)
   1.921 +		{
   1.922 +		CleanupStack::PushL(tempBuffer);
   1.923 +		TPtrC16 bufferPtr;
   1.924 +		const TUint16* rawptr16=reinterpret_cast<const TUint16*>(tempBuffer->Ptr());
   1.925 +		//must always start with the byte ordering characters
   1.926 +		bufferPtr.Set(rawptr16,1);
   1.927 +		if (bufferPtr.Compare(_L("\xFEFF"))==0)
   1.928 +			{
   1.929 +			//skip the byte ordering character(FEFF) assuming little endian
   1.930 +			bufferPtr.Set(rawptr16+1,(tempBuffer->Length()/2)-1);
   1.931 +			}
   1.932 +		else
   1.933 +			{
   1.934 +			//byte ordering characters not found, so leave, unless we should upconvert
   1.935 +			if (!aConvert8To16)
   1.936 +				{			
   1.937 +				User::Leave(KErrCorrupt);
   1.938 +				}
   1.939 +			//treat as an 8-bit file and upconvert to 16
   1.940 +			HBufC16* tempBuffer16=HBufC16::NewL(tempBuffer->Length());
   1.941 +			tempBuffer16->Des().Copy(*tempBuffer);
   1.942 +			CleanupStack::PopAndDestroy(tempBuffer);
   1.943 +			CleanupStack::PushL(tempBuffer16);	
   1.944 +			bufferPtr.Set(*tempBuffer16);
   1.945 +			}	
   1.946 +		iTempImpl->ProcessBufferL(bufferPtr);
   1.947 +		CleanupStack::PopAndDestroy();
   1.948 +		}
   1.949 +	}
   1.950 +
   1.951 +TInt CIniFile16Impl::FindVar(const TDesC16& aSection,const TDesC16& aKey,TPtrC16& aValue)
   1.952 +	{
   1.953 +	return iTempImpl->FindVar(aSection,aKey,aValue);	
   1.954 +	}
   1.955 +	
   1.956 +}//namespace
   1.957 +
   1.958 +