📄 osaux.cpp
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Jabber
* Copyright (C) 2004 Xie Tian Lu http://sabber.jabberstudio.org/
*/
#include "osaux.h"
#include <string.h>
#include <utf.h>
void CUtil::GetFilenameFromURL( char* url, char* file )
{
char* s, *t;
t = url - 1;
do {
s = t + 1;
t = strstr( s, "/" );
} while ( t != NULL );
strcpy( file, s );
}
void CUtil::GetFilenameFromPath( char* path, char* file )
{
char* s, *t;
t = path - 1;
do {
s = t + 1;
t = strstr( s, "\\" );
} while ( t != NULL );
strcpy( file, s );
}
void CUtil::Str2TBuf1V1( TDes& buf, char* str )
{
for ( int i = 0; i < strlen( str); i++ ) {
buf.Append( str[ i ] );
}
}
void CUtil::Str2TBuf( TDes& buf, char* str )
{
for ( TInt i = 0; i < strlen( str ); i++ )
{
buf.Append( str[ 2 * i ] * 0x100 + str[ 2 * i + 1 ] );
}
}
void CUtil::TBuf2Str( char* str, TDesC& buf )
{
for (TInt i=0; i< buf.Length(); i++)
{
if ( buf[ i ] / 0x100 )
*str++ = buf[ i ] / 0x100;
*str++ = buf[i] % 0x100;
}
*str = 0;
}
void CUtil::RandomFileName( char* file )
{
_LIT(KFormatTxt,"%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
char path[ 128 ];
TBuf<32> iBuf;
int i,j;
TTime * iTime=new (ELeave) TTime;
iTime->HomeTime();
iTime->FormatL(iBuf,KFormatTxt);
for ( i=0, j=0; j < iBuf.Length() && i < 14; i++, j++ )
{
while( iBuf[ j ] < '0' || iBuf[ j ] > '9' ) {
j++;
if ( j >= iBuf.Length() )
goto Lable_end;
}
file[i] = iBuf[j];
}
Lable_end:
file[ i ] = '\0';
delete iTime;
}
void CUtil::RandomFileName( TDes& file )
{
_LIT(KFormatTxt,"%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B");
char path[ 128 ];
TBuf<32> iBuf;
int i,j;
TTime * iTime=new (ELeave) TTime;
iTime->HomeTime();
iTime->FormatL(iBuf,KFormatTxt);
for ( i=0, j=0; j < iBuf.Length() && i < 14; i++, j++ )
{
while( iBuf[ j ] < '0' || iBuf[ j ] > '9' ) {
j++;
if ( j >= iBuf.Length() )
goto Lable_end;
}
file.Append( iBuf[ j ] );
}
Lable_end:
delete iTime;
}
void CUtil::Unicode2UTF8( char* str, TDesC& buf )
{
TPtr8 ptr( (TUint8*)str, 3 * buf.Length() );
CnvUtfConverter* icov = new CnvUtfConverter;
icov->ConvertFromUnicodeToUtf8( ptr, buf );
delete icov;
str[ ptr.Length() ] = 0;
}
void CUtil::UTF82Unicode( TDes& buf, char* str )
{
int len = strlen( str );
TPtr8 ptr( (TUint8*)str, len, len );
CnvUtfConverter* icov = new CnvUtfConverter;
icov->ConvertToUnicodeFromUtf8( buf, ptr );
delete icov;
}
void CUtil::UTF82Unicode( TDes& buf, TPtr8 str )
{
CnvUtfConverter* icov = new CnvUtfConverter;
icov->ConvertToUnicodeFromUtf8( buf, str );
delete icov;
}
/*
void CUtil::Gbk2Unicode( TDes& buf, char* str )
{
int len = strlen( str );
TPtr8 ptr( (TUint8*)str, len, len );
CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
TInt state = CCnvCharacterSetConverter::KStateDefault;
if ( CCnvCharacterSetConverter::EAvailable !=
converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGbk,
CEikonEnv::Static()->FsSession() ) )
User::Leave( KErrNotSupported );
converter->ConvertToUnicode( buf, ptr, state );
CleanupStack::PopAndDestroy();
}
void CUtil::Unicode2Gbk( char* str, TDes& buf )
{
}
void CUtil::Gb23122Unicode( TDes& buf, char* str )
{
int len = strlen( str );
TPtr8 ptr( (TUint8*)str, len, len );
CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
TInt state = CCnvCharacterSetConverter::KStateDefault;
if ( CCnvCharacterSetConverter::EAvailable !=
converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGb2312,
CEikonEnv::Static()->FsSession() ) )
User::Leave( KErrNotSupported );
converter->ConvertToUnicode( buf, ptr, state );
CleanupStack::PopAndDestroy();
}
*/
void CUtil::GetTextFromResource( TDes& buf, TInt id )
{
CEikonEnv::Static()->ReadResource( buf, id );
}
TBool CUtil::IsChar(char c)
{
if(c<='Z'&&c>='A'||c<='z'&&c>='a')
return ETrue;
return EFalse;
}
TInt CUtil::GetLineNum(const TDesC8& iContent)
{
TBuf<1024> ibuf;
CnvUtfConverter* icov = new CnvUtfConverter;
icov->ConvertToUnicodeFromUtf8(ibuf, iContent );
delete icov;
return GetLineNum( ibuf );
}
TInt CUtil::GetLineNum( const TDes& aBuf )
{
CFont *iFont=GetChineseFont();
int i=iFont->MeasureText(aBuf);
return (iFont->MeasureText(aBuf)-1)/144;
}
CFont* CUtil::GetFont( const TDesC& aTypeName, TInt aHeight )
{
CFont * aFont;
TFontSpec fontSpec;
fontSpec = TFontSpec( aTypeName, aHeight );
User::LeaveIfError( CEikonEnv::Static()->ScreenDevice()->GetNearestFontInTwips(aFont, fontSpec));
return aFont;
}
CFont* CUtil::GetChineseFont()
{
CFont * iFont;
TFontSpec fontSpec;
//fontSpec = TFontSpec( _L("CombinedChinesePlain12"), 600 );
fontSpec = TFontSpec( _L("Arial"), 600 );
User::LeaveIfError( CEikonEnv::Static()->ScreenDevice()->GetNearestFontInTwips(iFont, fontSpec));
return iFont;
}
TInt CUtil::GetWidth(const TDesC8& iContent)
{
TBuf<1024> ibuf;
CnvUtfConverter* icov = new CnvUtfConverter;
icov->ConvertToUnicodeFromUtf8(ibuf, iContent );
delete icov;
CFont *iFont=GetChineseFont();
return (iFont->MeasureText(ibuf));
}
TInt CUtil::GetWidth( const TDesC& aBuf )
{
CFont* iFont = GetChineseFont();
return ( iFont->MeasureText( aBuf ) );
}
TInt CUtil::GetWidth(char c)
{
TBuf<2> ibuf;
ibuf.Append(c);
CFont *iFont=GetChineseFont();
return (iFont->MeasureText(ibuf));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -