secureswitools/swisistools/source/interpretsislib/is_utils.cpp
branchRCL_3
changeset 62 5cc91383ab1e
parent 0 ba25891c3a9e
child 65 7333d7932ef7
equal deleted inserted replaced
61:cd189dac02f7 62:5cc91383ab1e
     1 /*
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    73 	static std::wstring wstr;
    73 	static std::wstring wstr;
    74 	return Utf8ToUcs2(aStr,wstr);
    74 	return Utf8ToUcs2(aStr,wstr);
    75 }
    75 }
    76 
    76 
    77 
    77 
       
    78 void ConvertToPlatformSpecificPath( TUint16* aIn, TUint32 len )
       
    79 {
       
    80     while( len-- > 0 )
       
    81     {
       
    82     	if( *aIn == '\\' )
       
    83     	{
       
    84     		*aIn = '/';
       
    85     	}
       
    86     	aIn++;
       
    87     }
       
    88 }
       
    89 
       
    90 #ifdef __TOOLS2_LINUX__
       
    91 void ConvertToForwardSlash( std::wstring& aIn)
       
    92 {
       
    93 	std::wstring::size_type idx = 0;
       
    94 	
       
    95 	while( (idx = aIn.find(L"\\", idx)) != std::wstring::npos)
       
    96 		{
       
    97 		aIn.replace( idx, 1, KDirectorySeparator );
       
    98 		}
       
    99 }
       
   100 #endif
       
   101 
       
   102 
    78 void ConvertToLocalPath( std::wstring& aIn, const std::wstring& aDrivePath )
   103 void ConvertToLocalPath( std::wstring& aIn, const std::wstring& aDrivePath )
    79 {
   104 {
    80 	std::wstring::size_type idx = 0;
   105 	std::wstring::size_type idx = 0;
    81 	while( (idx = aIn.find(L"\\\\", idx)) != std::wstring::npos)
   106 
       
   107 	#ifndef __TOOLS2_LINUX__
       
   108 	while( (idx = aIn.find(L"//", idx)) != std::wstring::npos)
    82         {
   109         {
    83 		aIn.replace( idx, 4, KDirectorySeparator );
   110 		aIn.replace( idx, 2, KDoubleSlashPathPrefix );
    84         }
   111         }
    85 	//
   112 
    86     idx = 0;
   113     idx = 0;
       
   114 
    87 	while( (idx = aIn.find(L"/", idx)) != std::wstring::npos)
   115 	while( (idx = aIn.find(L"/", idx)) != std::wstring::npos)
    88         {
   116         {
    89 		aIn.replace( idx, 1, KDirectorySeparator );
   117 		aIn.replace( idx, 1, KDirectorySeparator );
    90         }
   118         }
    91     
   119     #else
       
   120 
       
   121 	idx = 0;
       
   122 
       
   123 	while( (idx = aIn.find(L"\\\\", idx)) != std::wstring::npos)
       
   124         {
       
   125 		aIn.replace( idx, 2, KDoubleSlashPathPrefix );
       
   126         }
       
   127 
       
   128 	idx = 0;
       
   129 
       
   130 	while( (idx = aIn.find(L"\\", idx)) != std::wstring::npos)
       
   131         {
       
   132 		aIn.replace( idx, 1, KDirectorySeparator );
       
   133         }
       
   134 	#endif
    92     // If the first two characters represent a drive specification
   135     // If the first two characters represent a drive specification
    93     // then replace them entirely with the value from the 
   136     // then replace them entirely with the value from the 
    94     // PC's path ('aDrivePath').
   137     // PC's path ('aDrivePath').
    95     //
   138     //
    96     // Otherwise, we'll just prepend the PC's path, leaving
   139     // Otherwise, we'll just prepend the PC's path, leaving
    97     // the data in aIn intact.
   140     // the data in aIn intact.
    98     const bool startsWithDrive = StringUtils::StartsWithDrive( aIn );
   141     const bool startsWithDrive = StringUtils::StartsWithDrive( aIn );
    99     if ( startsWithDrive )
   142     if ( startsWithDrive )
   100     {
   143     {
   101 	    aIn.replace(aIn.begin(), aIn.begin()+2, aDrivePath);
   144 	    aIn.replace(aIn.begin(), aIn.begin()+2, aDrivePath.c_str());
   102     }
   145     }
   103     else
   146     else
   104     {
   147     {
   105         aIn.insert( 0, aDrivePath );
   148         aIn.insert( 0, aDrivePath.c_str() );
   106     }
   149     }
   107 }
   150 }
   108 
       
   109 
   151 
   110 struct TPair {
   152 struct TPair {
   111 	TUint16 first; 
   153 	TUint16 first; 
   112 	TUint16 second;
   154 	TUint16 second;
   113 };
   155 };
  1006 	}
  1048 	}
  1007 	return aC;
  1049 	return aC;
  1008 }
  1050 }
  1009 int FoldedCompare(const std::wstring& aLeft, const std::wstring& aRight)
  1051 int FoldedCompare(const std::wstring& aLeft, const std::wstring& aRight)
  1010 {
  1052 {
  1011 	std::wstring::const_iterator l  = aLeft.begin();
  1053 	std::wstring iLeft=aLeft.c_str();
  1012 	std::wstring::const_iterator r  = aRight.begin();
  1054 	std::wstring iRight=aRight.c_str();
  1013 	std::wstring::const_iterator le = aLeft.end();
  1055 
  1014 	std::wstring::const_iterator re = aRight.end();
  1056 #ifdef __TOOLS2_LINUX__
       
  1057 	std::wstring::size_type idx = 0;
       
  1058 
       
  1059 	while( (idx = iLeft.find(L"\\", idx)) != std::wstring::npos)
       
  1060         {
       
  1061 		iLeft.replace( idx, 1, KDirectorySeparator );
       
  1062         }
       
  1063 #endif
       
  1064 
       
  1065 	std::wstring::const_iterator l  = iLeft.begin();
       
  1066 	std::wstring::const_iterator r  = iRight.begin();
       
  1067 	std::wstring::const_iterator le = iLeft.end();
       
  1068 	std::wstring::const_iterator re = iRight.end();
  1015 
  1069 
  1016 	while (l != le && r != re)
  1070 	while (l != le && r != re)
  1017 	{
  1071 	{
  1018 		wchar_t lf = Fold(*l);
  1072 		wchar_t lf = Fold(*l);
  1019 		wchar_t rf = Fold(*r);
  1073 		wchar_t rf = Fold(*r);
  1023 		}
  1077 		}
  1024 		++l;
  1078 		++l;
  1025 		++r;
  1079 		++r;
  1026 	}
  1080 	}
  1027 
  1081 
  1028 	return aLeft.size() - aRight.size();
  1082 	return iLeft.size() - iRight.size();
  1029 }
  1083 }
  1030 
  1084 
  1031 int ReadSecurityInfo( SBinarySecurityInfo& aInfo, const std::wstring aFileName )
  1085 int ReadSecurityInfo( SBinarySecurityInfo& aInfo, const std::wstring aFileName )
  1032 {
  1086 {
  1033     char fileName[PATHMAX] = "\0";
  1087     char fileName[PATHMAX] = "\0";
  1043     if  (oldStdErr == -1)
  1097     if  (oldStdErr == -1)
  1044 	{
  1098 	{
  1045         throw "Failed in redirection operation";
  1099         throw "Failed in redirection operation";
  1046 	}
  1100 	}
  1047 
  1101 
       
  1102 #ifndef __LINUX__
  1048     nulStdErr = fopen("NUL:" , "w");
  1103     nulStdErr = fopen("NUL:" , "w");
       
  1104 #else
       
  1105     nulStdErr = fopen("/dev/null", "w");
       
  1106 #endif
       
  1107 
  1049     if  (!nulStdErr)
  1108     if  (!nulStdErr)
  1050 	{
  1109 	{
  1051         throw "Failed in redirection operation";
  1110         throw "Failed in redirection operation";
  1052 	}
  1111 	}
  1053 
  1112 
  1085 			aEquivalents[index] = CSISLanguage::ELangNone;
  1144 			aEquivalents[index] = CSISLanguage::ELangNone;
  1086 			} // end if ptr[0]
  1145 			} // end if ptr[0]
  1087 		} // end for i
  1146 		} // end for i
  1088 	}
  1147 	}
  1089 
  1148 
       
  1149 const std::wstring Utils::IntegerToWideString(int aInt)
       
  1150 	{
       
  1151 	std::wstringstream wstream;
       
  1152 	wstream << aInt;
       
  1153 	return wstream.str();
       
  1154 	}
       
  1155 
       
  1156 std::wstring Utils::Int64ToWideString(TInt64 aInt)
       
  1157 	{
       
  1158 	std::wstringstream strInt64;
       
  1159 	strInt64 << aInt;
       
  1160 	return strInt64.str();
       
  1161 	}
       
  1162 
       
  1163 int Utils::WideStringToInteger(const std::wstring& aWideString)
       
  1164 	{
       
  1165 	unsigned long int value=0;
       
  1166 	std::wstringstream str(aWideString);
       
  1167 	str >> value;
       
  1168 	return value;
       
  1169 	}
       
  1170