secureswitools/swisistools/source/interpretsislib/serialiser.h
changeset 60 245df5276b97
parent 0 ba25891c3a9e
equal deleted inserted replaced
53:ae54820ef82c 60:245df5276b97
     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".
    24 #include <vector>
    24 #include <vector>
    25 #include "symbiantypes.h"
    25 #include "symbiantypes.h"
    26 #include "serialisable.h"
    26 #include "serialisable.h"
    27 #include "ucmp.h"
    27 #include "ucmp.h"
    28 #include "cardinality.h"
    28 #include "cardinality.h"
       
    29 #include "utf8_wrapper.h"
    29 
    30 
    30 /**
    31 /**
    31 * @file SERIALISER.H
    32 * @file SERIALISER.H
    32 *
    33 *
    33 * @internalComponent
    34 * @internalComponent
    79 	return *this;
    80 	return *this;
    80 	}
    81 	}
    81 
    82 
    82 	Serialiser& operator<<(std::wstring& val)
    83 	Serialiser& operator<<(std::wstring& val)
    83 	{
    84 	{
       
    85 
       
    86 	std::wstring tempval = val.c_str();
       
    87 	
       
    88 #ifdef __TOOLS2_LINUX__
       
    89 	std::wstring::size_type idx = 0;
       
    90 	while( (idx = tempval.find(L"/", idx)) != std::wstring::npos)
       
    91         {
       
    92 		tempval.replace( idx, 1, L"\\" );
       
    93         }
       
    94 #endif
       
    95 
    84 	Cardinality card;
    96 	Cardinality card;
    85 	TUint32 size = val.size() << 1;
    97 	TUint32 size = tempval.size() << 1;
       
    98 
       
    99 #ifdef __TOOLS2_LINUX__
       
   100 	const wchar_t * source = tempval.c_str();
       
   101 	unsigned short int* buffer = new unsigned short int[size];
       
   102 
       
   103 	// Using a temp variable in place of buffer as ConvertUTF32toUTF16 modifies the source pointer passed.
       
   104 	unsigned short int* temp = buffer;
       
   105 
       
   106 	ConvertUTF32toUTF16(&source, tempval.c_str() + tempval.size(), &temp,  temp + size, lenientConversion);
       
   107 
       
   108 	// Appending NULL to the converted buffer.
       
   109 	*temp = NULL;
       
   110 #endif
       
   111 	
    86 	card.SetSize(size);
   112 	card.SetSize(size);
    87 	*this << card;
   113 	*this << card;
    88 
   114 
    89 	TUnicodeCompressor comp;
   115 	TUnicodeCompressor comp;
    90 	TMemoryUnicodeSource src((TUint16*)val.c_str());
   116 
       
   117 #ifdef __TOOLS2_LINUX__
       
   118 	TMemoryUnicodeSource src((TUint16*)buffer);
       
   119 #else
       
   120 	TMemoryUnicodeSource src((TUint16*)tempval.c_str());
       
   121 #endif
       
   122 
    91 	//The compressed unicode output could end up larger than the input, thus restricting the output to KMaxTInt.
   123 	//The compressed unicode output could end up larger than the input, thus restricting the output to KMaxTInt.
    92 	comp.CompressL(*this, src, KMaxTInt, val.size());
   124 	comp.CompressL(*this, src, KMaxTInt, tempval.size());
       
   125 #ifdef __TOOLS2_LINUX__
       
   126 	delete[] buffer;
       
   127 #endif
    93 	return *this;
   128 	return *this;
    94 	}
   129 	}
    95 
   130 
    96 	template <class T>
   131 	template <class T>
    97 	Serialiser& operator<<(std::vector<T>& val)
   132 	Serialiser& operator<<(std::vector<T>& val)