secureswitools/swisistools/source/rscparser/parse.cpp
changeset 25 98b66e4fb0be
child 50 c6e8afe0ba85
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
       
     1 // Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // 
       
    15 // 
       
    16 //
       
    17 /** 
       
    18 * @file parse.cpp
       
    19 *
       
    20 * @internalComponent
       
    21 * @released
       
    22 */
       
    23 #include "parse.h"
       
    24 #include "barsc2.h"
       
    25 
       
    26 std::string FullNameWithoutDrive(std::string& Buf )
       
    27 	{
       
    28 	  std::string iName;
       
    29 	   std::string::size_type index = Buf.find( ':' );
       
    30 	   if( index != std::string::npos )
       
    31 			iName.assign(Buf, index+1, Buf.size());
       
    32 	
       
    33 	   return iName;
       
    34 	}
       
    35 
       
    36 /**
       
    37  * Converts from Ptr8* datatype to wstring
       
    38  */
       
    39 std::wstring Ptr8ToWstring(const Ptr8* aBuf)
       
    40 {
       
    41 	std::wstring str2(aBuf->GetLength(), L'\0'); // Make room for characters
       
    42 
       
    43 	TUint8* temp = aBuf->GetPtr();
       
    44 	memcpy(str2.begin(),temp,aBuf->GetLength());
       
    45 	
       
    46 	return str2;
       
    47 }
       
    48 
       
    49 /**
       
    50  * Converts from Ptr16* datatype to wstring
       
    51  */
       
    52 std::wstring Ptr16ToWstring(const Ptr16* aBuf)
       
    53 {
       
    54 	std::wstring str2(aBuf->GetLength(), L'\0'); // Make room for characters
       
    55 
       
    56 	TUint16* temp = aBuf->GetPtr();
       
    57 	std::copy(temp,temp+aBuf->GetLength(),str2.begin());
       
    58 
       
    59 	return str2;
       
    60 }
       
    61 
       
    62 /**
       
    63  * Converts from Ptr16* datatype to string
       
    64  */
       
    65 std::string Ptr16ToString(Ptr16* aBuf)
       
    66 {
       
    67 		std::string str2(aBuf->GetLength(), '\0'); // Make room for characters
       
    68 
       
    69 		TUint16* temp = aBuf->GetPtr();
       
    70 		for(int i =0; i<aBuf->GetLength(); i++)
       
    71 		{
       
    72 			str2[i] = *temp++;
       
    73 		}
       
    74 		str2[aBuf->GetLength()] = '\0';
       
    75 		return str2;
       
    76 }
       
    77 
       
    78 //Local function to Copy TUint16
       
    79 void BufCpy(TUint16* aTemp1,TUint16* aTemp2, TInt aLength)
       
    80 {
       
    81 	for(TInt i =0 ; i< aLength; i++)
       
    82 	{
       
    83 		*aTemp1++ = *aTemp2++;
       
    84 	}
       
    85 }
       
    86 
       
    87 //Local function to Copy TUint8
       
    88 void BufCpy8(TUint8* aTemp1, const TUint8* aTemp2, TInt aLength)
       
    89 {
       
    90 	for(TInt i =0 ; i< aLength; i++)
       
    91 	{
       
    92 		*aTemp1++ = *aTemp2++;
       
    93 	}
       
    94 }
       
    95 
       
    96 //Search for either wild character in the input string.
       
    97 //return 1 if found else return 0
       
    98 TInt FindWild(PtrC16 *aPtr)
       
    99 {
       
   100 	TUint32 i = 0;
       
   101 	const TUint16* Pt = aPtr->iPtr;
       
   102 	for( i=0; i < aPtr->iMaxLength; i++)
       
   103 	{
       
   104 		if((*Pt=='*') || (*Pt=='?'))
       
   105 			return 1;
       
   106 		else
       
   107 			Pt++;
       
   108 	}
       
   109 	return 0;
       
   110 }
       
   111 
       
   112 //Find if wild character present in the input string
       
   113 //return 1 if found else return 0
       
   114 TInt FindWild(std::string& aRegistrationFileDrive, std::string& aAppFilePath, std::string& aAppFileNameAndExt)
       
   115 {
       
   116 
       
   117 	string::size_type index1 = aRegistrationFileDrive.find_last_of("*?");
       
   118 	if( index1 != string::npos )
       
   119 		return 1;
       
   120 
       
   121 	string::size_type index2 = aAppFilePath.find_last_of("*?");
       
   122 	if( index2 != string::npos )
       
   123 		return 1;
       
   124 
       
   125 	string::size_type index3 = aAppFileNameAndExt.find_last_of("*?");
       
   126 	if( index3 != string::npos )
       
   127 		return 1;
       
   128 	return 0;
       
   129 }
       
   130 
       
   131 //Default Constructor for class ParsePtrC
       
   132 ParsePtrC::ParsePtrC() 
       
   133 		: iNamePresent(0),iPathPresent(0),iExtPresent(0),iDrivePresent(0)
       
   134 {
       
   135 }
       
   136 
       
   137 //Destructor for class ParsePtrC
       
   138 ParsePtrC::~ParsePtrC() 
       
   139 {
       
   140 	delete iNameBuf;
       
   141 	delete Buf;
       
   142 	iNameBuf = NULL;
       
   143 	Buf = NULL;
       
   144 }
       
   145 
       
   146 //To Avoid double Delete in destructor.
       
   147 void ParsePtrC::SetToNull()
       
   148 {
       
   149 	iNameBuf = NULL;
       
   150 }
       
   151 
       
   152 //Constructor for class ParsePtrC
       
   153 ParsePtrC::ParsePtrC(const PtrC16* aName)
       
   154 	: iNamePresent(0),iPathPresent(0),iExtPresent(0),iDrivePresent(0)
       
   155 	{
       
   156 	iNameBuf = new PtrC16;
       
   157 	TUint16* temp = (TUint16*)aName->iPtr;
       
   158 	if(NULL==iNameBuf)
       
   159 	{
       
   160 		std::string errMsg= "Error in Reading File. Memory Allocation Failed";
       
   161 		throw CResourceFileException(errMsg);
       
   162 	}
       
   163 	iNameBuf->iPtr = aName->iPtr;
       
   164 	iNameBuf->iMaxLength = aName->iMaxLength;
       
   165 
       
   166 	Buf = new string(aName->iMaxLength,'\0');
       
   167 
       
   168 	if(NULL==Buf)
       
   169 	{
       
   170 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   171 		throw CResourceFileException(errMsg);
       
   172 	}
       
   173 
       
   174 	for(TInt i = 0; i<aName->iMaxLength; i++ )
       
   175 	{
       
   176 		(*Buf)[i] = *temp;
       
   177 		temp++;
       
   178 	}
       
   179 }
       
   180 
       
   181 PtrC16* ParsePtrC::FullName()
       
   182 {
       
   183 	return iNameBuf;
       
   184 }
       
   185 
       
   186 std::string ParsePtrC::StrName()
       
   187 {
       
   188 	return *Buf;
       
   189 }
       
   190 
       
   191 //Constructor for class ParsePtrC
       
   192 ParsePtrC::ParsePtrC(std::string aStr)
       
   193 	: iNamePresent(0),iPathPresent(0),iExtPresent(0),iDrivePresent(0)
       
   194 {
       
   195 	Buf = new string;
       
   196 	if(NULL==Buf)
       
   197 	{
       
   198 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   199 		throw CResourceFileException(errMsg);
       
   200 	}
       
   201 	*Buf = aStr;
       
   202 }
       
   203 
       
   204 std::string ParsePtrC::Name()
       
   205 {
       
   206   string iName;
       
   207 
       
   208   TInt i = Buf->rfind("\\");
       
   209   if(i!=string::npos)
       
   210      iName.assign(*Buf, i, Buf->size()-4);
       
   211   else
       
   212   {
       
   213 	  if(ExtPresent())
       
   214 		iName.assign(*Buf, i, Buf->size()-4);
       
   215 	  else
       
   216 		iName.assign(*Buf, 0, Buf->size());
       
   217   }
       
   218 	  
       
   219    return iName;
       
   220 }
       
   221 
       
   222 std::string ParsePtrC::NameAndExt()
       
   223 {
       
   224   string iName;
       
   225 
       
   226   TInt i = Buf->rfind("\\");
       
   227   if(i!=string::npos)
       
   228      iName.assign(*Buf, i, Buf->size());
       
   229 
       
   230    return iName;
       
   231 }
       
   232 
       
   233 std::string ParsePtrC::FullPath()
       
   234 {
       
   235   string iName;
       
   236 
       
   237   TInt i = Buf->rfind("\\");
       
   238   if(i!=string::npos)
       
   239      iName.assign(*Buf, 0, i);
       
   240 
       
   241    return iName;
       
   242 }
       
   243 
       
   244 std::string ParsePtrC::Path()
       
   245 {
       
   246   string iName;
       
   247 
       
   248   TInt j = Buf->rfind("\\");
       
   249   TInt i = Buf->find("\\");
       
   250   if(i!=string::npos)
       
   251      iName.assign(*Buf, i, Buf->size()-j);
       
   252 
       
   253    return iName;
       
   254 }
       
   255 
       
   256 std::string ParsePtrC::Drive()
       
   257 {
       
   258   string iName;
       
   259 
       
   260    string::size_type index = Buf->find( ':' );
       
   261    if( index != string::npos )
       
   262 		iName.assign(*Buf, index-1, 2);
       
   263 
       
   264    return iName;
       
   265 }
       
   266 
       
   267 std::string ParsePtrC::FullNameWithoutDrive()
       
   268 {
       
   269   string iName;
       
   270 
       
   271    string::size_type index = Buf->find( ':' );
       
   272    if( index != string::npos )
       
   273 		iName.assign(*Buf, index+1, Buf->size());
       
   274 
       
   275    return iName;
       
   276 }
       
   277 
       
   278 TInt ParsePtrC::NamePresent()
       
   279 {
       
   280 	TInt i = Buf->rfind("\\");
       
   281 	if(i!=string::npos)
       
   282 		iNamePresent = 1;
       
   283 	else
       
   284 	{
       
   285 		if(Buf!= NULL)
       
   286 			iNamePresent = 1;
       
   287 		else
       
   288 			iNamePresent = 0;
       
   289 	}
       
   290 	return iNamePresent;
       
   291 }
       
   292 
       
   293 TInt ParsePtrC::PathPresent()
       
   294 {
       
   295 	TInt i = Buf->find("\\");
       
   296 	if(i!=string::npos)
       
   297 		iPathPresent = 1;
       
   298 	else
       
   299 		iPathPresent = 0;
       
   300 	return iPathPresent;
       
   301 }
       
   302 
       
   303 TInt ParsePtrC::ExtPresent()
       
   304 {
       
   305 	TInt i = Buf->find(".");
       
   306 	if(i!=string::npos)
       
   307 		iExtPresent = 1;
       
   308 	else
       
   309 		iExtPresent = 0;
       
   310 	return iExtPresent;
       
   311 }
       
   312 
       
   313 TInt ParsePtrC::DrivePresent()
       
   314 {
       
   315 	TInt i = Buf->find(":");
       
   316 	if(i!=string::npos)
       
   317 		iDrivePresent = 1;
       
   318 	else
       
   319 		iDrivePresent = 0;
       
   320 	return iDrivePresent;
       
   321 }
       
   322 
       
   323 TInt ParsePtrC::IsWild()
       
   324 {
       
   325 	string::size_type index = Buf->find_last_of("*?");
       
   326 	if( index != string::npos )
       
   327 		return 1;
       
   328 	return 0;
       
   329 }
       
   330 
       
   331 TInt ParsePtrC::IsValidName()
       
   332 {
       
   333 	string::size_type index = Buf->find_last_of("*?< > : \" / |");
       
   334 	if( index != string::npos )
       
   335 		return 1;
       
   336 	return 0;
       
   337 }