imgtools/imglib/host/utf16string.cpp
author lorewang
Mon, 22 Nov 2010 10:56:31 +0800
changeset 700 c22eff170fac
parent 606 30b30f9da0b7
permissions -rw-r--r--
update from trunk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
/*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
* All rights reserved.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
* This component and the accompanying materials are made available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
* which accompanies this distribution, and is available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
* Initial Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
* Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
* Description: 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
* @internalComponent * @released
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
*/
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#include "utf16string.h"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#ifdef __LINUX__
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include <iconv.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
#elif defined(WIN32)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#ifdef _STLP_INTERNAL_WINDOWS_H
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#define __INTERLOCKED_DECLARED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
#include <windows.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
UTF16String::UTF16String() :iData(0), iLength(0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
UTF16String::UTF16String(const UTF16String& aRight){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
	iLength = aRight.iLength ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
	iData = new TUint16[iLength + 1];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
	memcpy(iData,aRight.iData, iLength << 1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
	iData[iLength] = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
UTF16String::UTF16String(const string& aUtf8Str){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
	iData = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
	iLength = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
	Assign(aUtf8Str.c_str(),aUtf8Str.length());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
UTF16String::UTF16String(const TUint16* aUtf16Str,TInt aLength /* = -1*/){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
	if(aLength < 0){
606
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 600
diff changeset
    44
		aLength = 0 ;
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
		const TUint16* p = aUtf16Str ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
		while(*p){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
			p++ ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
			aLength ++ ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	if(aLength > 0){		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
		iLength = aLength ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
		aLength <<= 1 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
		iData = new TUint16[iLength + 1] ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
		memcpy(iData,aUtf16Str,aLength);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
		iData[iLength] = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
	}else{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
		iData = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
		iLength = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
UTF16String::UTF16String(const char* aUtf8Str,TInt aLength /*= -1 */){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
	iData = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
	iLength = 0 ;	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	Assign(aUtf8Str,aLength);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
}	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
UTF16String::~UTF16String(){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
	if(iData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
		delete []iData ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
}	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
UTF16String& UTF16String::operator = (const UTF16String& aRight){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
	if(&aRight != this){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
		if(iData) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
			delete []iData ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
		iLength = aRight.iLength ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
		iData = new TUint16[iLength + 1];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
		memcpy(iData,aRight.iData, iLength << 1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
		iData[iLength] = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
	return *this;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
bool UTF16String::FromFile(const char* aFileName){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
	if(!aFileName || !(*aFileName))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
		return false ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
	ifstream ifs(aFileName,ios_base::in + ios_base::binary); 	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
	if(!ifs.is_open())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
		return false ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
	ifs.seekg(0,ios_base::end);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
	size_t length = ifs.tellg();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
	if((length % 2) == 1 ){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
		ifs.close() ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
		return false ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
	ifs.seekg(0,ios_base::beg);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
	TUint16 hdr ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
	size_t readLen = length - sizeof(hdr) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
	length >>= 1 ;	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
	TUint16 *newData = new TUint16[length + 1];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
	ifs.read(reinterpret_cast<char*>(&hdr),sizeof(hdr));		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
	if(hdr == 0xFEFF){ 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
		ifs.read(reinterpret_cast<char*>(newData),readLen);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
		length -- ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
	else{		 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
		*newData = hdr ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
		ifs.read(reinterpret_cast<char*>(&newData[1]),readLen);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
	} 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
	ifs.close();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
	iLength = length ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
	if(iData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
		delete []iData ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
	iData = newData ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
	iData[iLength] = 0;	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
	return true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
* aResult will not changed on error
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
*/
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
bool UTF16String::ToUTF8(string& aResult) const {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
	if(IsEmpty()){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
		aResult = "";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
		return true;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
	size_t bufLen = (iLength + 1) << 2 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
	char* buffer = new char[bufLen] ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
#ifdef WIN32
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
	int r = WideCharToMultiByte(CP_UTF8,0,reinterpret_cast<WCHAR*>(iData),iLength,buffer,bufLen,NULL,NULL);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
	if(r < 0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
		delete []buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
		return false ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
	buffer[r] = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
	aResult.assign(buffer,r);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
#else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
	iconv_t it = iconv_open("UTF-8","UTF-16");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
	if((iconv_t)(-1) == it){ 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
		return  false;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
	char* bufferEnd = buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
	char* in_ptr = reinterpret_cast<char*>(iData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
	size_t in_len = iLength << 1 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
	iconv(it,&in_ptr,&in_len ,&bufferEnd,&bufLen);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
	iconv_close(it);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
	*bufferEnd = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
	size_t length = bufferEnd - buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
	aResult.assign(buffer,length);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
	delete []buffer ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
	return true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
bool UTF16String::Assign(const char* aUtf8Str,TInt aLength /* = -1*/) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
	if(0 == aUtf8Str) return false ;	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
	if(aLength < 0) aLength = strlen(aUtf8Str); 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
		
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
#ifdef WIN32
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
	size_t newLength = aLength + 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
	TUint16* newData = new TUint16[newLength];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
	int r = MultiByteToWideChar(CP_UTF8,0,aUtf8Str,aLength,reinterpret_cast<WCHAR*>(newData),newLength);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
	if(r < 0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
		delete []newData ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
		return false ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
	iLength = r ;	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
#else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
	char* forFree = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
	if(aUtf8Str[aLength - 1] != 0){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
		forFree = new char[aLength + 1];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
		memcpy(forFree,aUtf8Str,aLength );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
		forFree[aLength] = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
		aUtf8Str = forFree ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
	iconv_t it = iconv_open("UTF-16","UTF-8");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
	if((iconv_t)(-1) == it){ 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
		 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
		return  false;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
	size_t newLength = aLength + 2;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
	TUint16* newData = new TUint16[newLength];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
	newLength <<= 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
	char* out_ptr = reinterpret_cast<char*>(newData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
	size_t in_len = aLength ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
	char* in_ptr = const_cast<char*>(aUtf8Str);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
	iconv(it,&in_ptr,&in_len ,&out_ptr ,&newLength);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
	newLength = out_ptr - reinterpret_cast<char*>(newData);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
	iconv_close(it);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
	if(newLength % 2 == 1){ //should not be possible
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
		delete []newData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
		return false ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
	iLength = (newLength >> 1) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
	if(forFree)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
		delete []forFree;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
	newData[iLength] = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
	if(iData){
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
		delete []iData ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
	iData = newData ;	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
	if(*iData == 0xFEFF)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
		iLength -- ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
	return true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
static const TUint16 NullUInt16Str[1] = {0};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
const TUint16* UTF16String::c_str() const {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
	if(0 == iData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
		return NullUInt16Str;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
	else if(0xFEFF != *iData)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
		return iData ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
	else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
		return iData + 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
///
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
/// aUtf16Str must end with '\0'
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
/// 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
int UTF16String::Compare(const TUint16* aUtf16Str) const {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
	if(!aUtf16Str || !(*aUtf16Str))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
		return (iLength > 0) ? 1 : 0; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
	size_t i ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
	for(i = 0 ; aUtf16Str[i] != 0 ; i++) { 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
		if( iData[i] > aUtf16Str[i])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
			return 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
		else if(iData[i] < aUtf16Str[i])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
			return -1 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
	return (i < iLength) ? 1 : 0 ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
///
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
/// aUtf16Str must end with '\0'
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
/// 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
int UTF16String::CompareNoCase(const TUint16* aUtf16Str) const {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
	if(!aUtf16Str || !(*aUtf16Str))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
		return (iLength > 0) ? 1 : 0; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
	size_t i ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
	TUint16 a, b;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
	for(i = 0 ; aUtf16Str[i] != 0 ; i++) { 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
		a = iData[i];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
		b = aUtf16Str[i] ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
		if( a >= 'A' && a <= 'Z') a |= 0x20 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
		if( b >= 'A' && b <= 'Z') b |= 0x20 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
			
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
		if( a > b )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
			return 1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
		else if( a < b )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
			return -1 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
	return (i < iLength) ? 1 : 0 ; 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
TUint16* UTF16String::Alloc(size_t aNewLen) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
	TUint16* newData = new TUint16[aNewLen + 1] ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
	if(!newData) return 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
	if(iData) delete []iData ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
	
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
	iLength = aNewLen ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
	iData = newData ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
	*iData = 0 ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
	iData[aNewLen] = 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
	return iData;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
}