charutil.cpp

来自「大名鼎鼎的远程登录软件putty的Symbian版源码」· C++ 代码 · 共 69 行

CPP
69
字号
/*    charutil.cpp * * Character set conversion utilities for PuTTY Symbian OS port * * Copyright 2002 Petteri Kangaslampi * * See license.txt for full copyright and license information.*/#include <e32std.h>#include <string.h>extern "C" {#include "putty.h"}#include "charutil.h"#ifdef _UNICODEtypedef TUint16 CharType;#elsetypedef TUint8 CharType;#endifvoid StringToDes(const char *aStr, TDes &aTarget) {    // FIXME: Doesn't really work for anything except US-ASCII    aTarget.SetLength(0);    while ( *aStr ) {        aTarget.Append(*aStr++);    }}TPtr *CreateDes(const char *aStr) {    int len = strlen(aStr);    CharType *buf = (CharType*) smalloc(len * sizeof(CharType));    TPtr *ptr = new TPtr(buf, len);    if ( !ptr ) {        fatalbox("Out of memory");    }    StringToDes(aStr, *ptr);    return ptr;}void DeleteDes(TPtr *aDes) {    const CharType *ptr = aDes->Ptr();    sfree((void*)ptr);    delete aDes;}// Converts a descriptor into a C string. The string needs to be pre-allocatedvoid DesToString(const TDesC &aDes, char *aTarget) {    int i = 0;    int len = aDes.Length();    while ( i < len ) {        *aTarget = (char) aDes[i];        aTarget++;        i++;    }    *aTarget = 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?