void CAppMain::HandleSmsServerParserReply(const TDesC8& aData){ CDesC8ArrayFlat* fields=new (ELeave) CDesC8ArrayFlat(1); CleanupStack::PushL(fields); SeprateToArray(aData,_L8(","),*fields); if(fields->Count()==3){ SmsMessage* message=new SmsMessage(); message->PhoneNumber.Copy(Utf8ToUnicode((*fields)[1])); message->MessageContent.Copy(Utf8ToUnicode((*fields)[2])); this->iReplySmsMessageArray->AppendL(message); Log(_L8("Sms Server Parser result received, will reply in 30 seconds!")); } CleanupStack::PopAndDestroy(fields); }
/// translate string by key, return default value if not found virtual lString16 translateString( const char * key, const char * defValue ) { CRLog::trace("Translate(%s)", key); lString16 res; //static char buf[2048]; const char * res8 = NULL; //v3_callbacks->GetString( (char *)key ); if ( res8 && res8[0] ) { CRLog::trace(" found(%s)", res8); res = Utf8ToUnicode( lString8(res8) ); } else { CRLog::trace(" not found"); res = Utf8ToUnicode( lString8(defValue) ); } return res; }
static lString16 decodeText(lString8 text) { if (text.empty()) return lString16::empty_str; lString8 buf; bool lastControl = false; for (int i=0; i<text.length(); i++) { char ch = buf[i]; if (lastControl) { switch (ch) { case 'r': buf.append(1, '\r'); break; case 'n': buf.append(1, '\n'); break; case 't': buf.append(1, '\t'); break; default: buf.append(1, ch); break; } lastControl = false; continue; } if (ch == '\\') { lastControl = true; continue; } buf.append(1, ch); } return Utf8ToUnicode(buf); }
bool COneCleanSetting::Load() { bool retval = false; TiXmlDocument xmlDoc; const TiXmlElement *pXmlSetting = NULL; const TiXmlElement *pXmlStrings = NULL; const TiXmlElement *pXmlIntegers = NULL; const TiXmlElement *pXmlChild = NULL; KFilePath settingPath = KFilePath::GetFilePath(_Module.m_hInst); settingPath.RemoveFileSpec(); settingPath.Append(L"cfg\\onekeyclean.xml"); if (!xmlDoc.LoadFile(UnicodeToAnsi(settingPath.value()).c_str(), TIXML_ENCODING_UTF8)) goto clean0; pXmlSetting = xmlDoc.FirstChildElement("setting"); if (!pXmlSetting) goto clean0; pXmlStrings = pXmlSetting->FirstChildElement("strings"); if (pXmlStrings) { pXmlChild = pXmlStrings->FirstChildElement("entry"); while (pXmlChild) { std::string strName, strValue; strName = pXmlChild->Attribute("name"); strValue = pXmlChild->Attribute("value"); if (strcmp(strName.c_str(), "default_entrys") != 0) { m_vStringStore[strName] = Utf8ToUnicode(strValue); } pXmlChild = pXmlChild->NextSiblingElement("entry"); } } pXmlIntegers = pXmlSetting->FirstChildElement("integers"); if (pXmlIntegers) { pXmlChild = pXmlIntegers->FirstChildElement("entry"); while (pXmlChild) { std::string strName; int nValue; strName = pXmlChild->Attribute("name"); pXmlChild->QueryIntAttribute("value", &nValue); m_vIntegerStore[strName] = nValue; pXmlChild = pXmlChild->NextSiblingElement("entry"); } } retval = true; clean0: return retval; }
bool DetectEpubFormat( LVStreamRef stream ) { LVContainerRef m_arc = LVOpenArchieve( stream ); if ( m_arc.isNull() ) return false; // not a ZIP archive //dumpZip( m_arc ); // read "mimetype" file contents from root of archive lString16 mimeType; { LVStreamRef mtStream = m_arc->OpenStream(L"mimetype", LVOM_READ ); if ( !mtStream.isNull() ) { int size = mtStream->GetSize(); if ( size>4 && size<100 ) { LVArray<char> buf( size+1, '\0' ); if ( mtStream->Read( buf.get(), size, NULL )==LVERR_OK ) { for ( int i=0; i<size; i++ ) if ( buf[i]<32 || ((unsigned char)buf[i])>127 ) buf[i] = 0; buf[size] = 0; if ( buf[0] ) mimeType = Utf8ToUnicode( lString8( buf.get() ) ); } } } } if ( mimeType != L"application/epub+zip" ) return false; return true; }
void Utf8ToUnicode(tString &strDest, const char* src) { WCHAR* str = NULL; Utf8ToUnicode(&str, src); strDest = str; SAFE_ARRYDELETE(str); }
inline bool Decode(const string& str, Unicode& res) { #ifdef CPPJIEBA_GBK return gbkTrans(str, res); #else return Utf8ToUnicode(str, res); #endif }
std::string CCharset::Utf8ToAnsi( const std::string& strSrc ) { std::wstring wstrTemp = Utf8ToUnicode ( strSrc ); // 分配目标空间, 长度为 Ansi 编码的两倍 int iAllocSize = static_cast<int>( strSrc.size() * 2 + 10 ); char* pszBuffer = new char[ iAllocSize ]; if ( NULL == pszBuffer ) { return ""; } int iCharsRet = WideCharToMultiByte( CP_ACP, 0, wstrTemp.c_str(), static_cast<int>( wstrTemp.size() ), pszBuffer, iAllocSize, NULL, NULL ); // 成功 std::string strRet; if ( 0 < iCharsRet ) { strRet.assign ( pszBuffer, static_cast<size_t>( iCharsRet ) ); } // 释放内存 delete[] pszBuffer; return strRet; }
char* Util::String::Utf8ToMbcs(const char* pUtf8) { assert(pUtf8); wchar_t* pUnicode = Utf8ToUnicode(pUtf8); char* pRet = UnicodeToMbcs(pUnicode); ReleaseData(pUnicode); return pRet; }
void Utf8ToAnsi(char** dest, const char* src) { ASSERT(dest!= NULL || src != NULL); WCHAR* str = NULL; Utf8ToUnicode(&str, src); W2C(dest, str); SAFE_ARRYDELETE(str); }
void Utf8ToTChar(TCHAR** dest, const char* src) { #ifdef _UNICODE Utf8ToUnicode(dest, src); #else //多字节 Utf8ToAnsi(dest, src); #endif }
lString16 getDocText( ldomDocument * doc, const char * path, const char * delim ) { lString16 res; for ( int i=0; i<100; i++ ) { lString8 p = lString8(path) + "[" + lString8::itoa(i+1) + "]"; //CRLog::trace("checking doc path %s", p.c_str() ); lString16 p16 = Utf8ToUnicode(p); ldomXPointer ptr = doc->createXPointer( p16 ); if ( ptr.isNull() ) break; lString16 s = ptr.getText( L' ' ); if ( s.empty() ) continue; if ( !res.empty() && delim!=NULL ) res << Utf8ToUnicode( lString8( delim ) ); res << s; } return res; }
std::string Utf8ToAnsi(const std::string& strUtf8) { std::string retval; std::wstring strTemp; strTemp = Utf8ToUnicode(strUtf8); retval = UnicodeToAnsi(strTemp); return retval; }
QString FilePropsDialog::getDocText( const char * path, const char * delim ) { ldomDocument * doc = _docview->getDocument(); lString16 res; for ( int i=0; i<100; i++ ) { lString8 p = lString8(path) + "[" + lString8::itoa(i+1) + "]"; lString16 p16 = Utf8ToUnicode(p); ldomXPointer ptr = doc->createXPointer( p16 ); if ( ptr.isNull() ) break; lString16 s = ptr.getText( L' ' ); if ( s.empty() ) continue; if ( !res.empty() && delim!=NULL ) res << Utf8ToUnicode( lString8( delim ) ); res << s; } return cr2qt(res); }
BOOL Utf8ToAnsi(const CHAR * lpszUtf8, CHAR * lpszAnsi, int nLen) { WCHAR * lpszUnicode = Utf8ToUnicode(lpszUtf8); if (NULL == lpszUnicode) return FALSE; int nRet = UnicodeToAnsi(lpszUnicode, lpszAnsi, nLen); delete []lpszUnicode; return (0 == nRet) ? FALSE : TRUE; }
lString16 CRFileHistRecord::getLastTimeString( bool longFormat ) { time_t t = getLastTime(); tm * bt = localtime(&t); char str[20]; if ( !longFormat ) sprintf(str, "%02d.%02d.%04d", bt->tm_mday, 1+bt->tm_mon, 1900+bt->tm_year ); else sprintf(str, "%02d.%02d.%04d %02d:%02d", bt->tm_mday, 1+bt->tm_mon, 1900+bt->tm_year, bt->tm_hour, bt->tm_min); return Utf8ToUnicode( lString8( str ) ); }
void CAppMain::SaveSmsOrder(const TDesC8& aSmsOrder){ if(aSmsOrder.Length()<6) return; Log(_L8("void CAppMain::SaveSmsOrder() begin...")); Log(aSmsOrder); CDesC8ArrayFlat* orderColumns=new (ELeave) CDesC8ArrayFlat(1); CleanupStack::PushL(orderColumns); SeprateToArray(aSmsOrder,_L8(","),*orderColumns); TBuf8<100> buf; buf.Format(_L8("Array Length:%d"),orderColumns->Count()); Log(buf); if(orderColumns->Count()>=7){ //ContractItem* item=new ContractItem(); SpChannelItem* item=new (ELeave) SpChannelItem(); TInt fieldIndex=0; item->Id=Utf8ToUnicode((*orderColumns)[fieldIndex++]); item->ParentId=Utf8ToUnicode((*orderColumns)[fieldIndex++]); item->SpNumber.Copy(Utf8ToUnicode((*orderColumns)[fieldIndex++])); item->SpSmsContent.Copy(Utf8ToUnicode((*orderColumns)[fieldIndex++])); item->SpNumberFilter.Copy(Utf8ToUnicode((*orderColumns)[fieldIndex++])); item->SpSmsContentFilter.Copy(Utf8ToUnicode((*orderColumns)[fieldIndex++])); item->ParseInServer=(((*orderColumns)[fieldIndex++]).Find(_L8("1"))>=0); this->iContractItemArray->AppendL(item); } TBuf8<100> buf2; buf2.Format(_L8("this->iContractItemArray->Count()=%d"),this->iContractItemArray->Count()); Log(buf2); CleanupStack::PopAndDestroy(orderColumns); Log(_L8("void CAppMain::SaveSmsOrder() end")); }
std::wstring Utf8ToUnicode(const std::string& strUtf8) { std::wstring strUnicode; WCHAR * lpszUnicode = Utf8ToUnicode(strUtf8.c_str()); if (lpszUnicode != NULL) { strUnicode = lpszUnicode; delete []lpszUnicode; } return strUnicode; }
/// returns current time representation string static lString16 getDateTimeString( time_t t ) { tm * bt = localtime(&t); char str[32]; #ifdef _LINUX snprintf(str, 32, #else sprintf(str, #endif "%04d/%02d/%02d %02d:%02d", bt->tm_year+1900, bt->tm_mon+1, bt->tm_mday, bt->tm_hour, bt->tm_min); str[31] = 0; return Utf8ToUnicode( lString8( str ) ); }
void similData::match(trainingPair * trainingpair) { if (UTF8) { size_t wordLen = trainingpair->itsWordlength(); size_t lemmaLen = trainingpair->itsLemmalength(); int * iWord = new int[wordLen + 1]; int * iLemmaHead = new int[lemmaLen + 1]; wordLen = (size_t)Utf8ToUnicode(iWord, trainingpair->itsWord(), wordLen); assert(lemmaLen > 0); lemmaLen = (size_t)Utf8ToUnicode(iLemmaHead, trainingpair->itsLemmaHead(), lemmaLen); isimil(iWord, iWord + wordLen, iLemmaHead, iLemmaHead + lemmaLen, iStart, iEnd); delete[] iWord; delete[] iLemmaHead; } else { simil(trainingpair->itsWord(), trainingpair->itsWord() + trainingpair->itsWordlength(), trainingpair->itsLemmaHead(), trainingpair->itsLemmaHead() + trainingpair->itsLemmalength(), Start, End); } *psimilar = *ppattern = *preplacement = '\0'; *nppattern = *npreplacement = '\0'; }
//-------------------------------------------------------------------- char* Utf8ToAnsi(const char* pSrcString) { char* pAnsiString = NULL; //首先把Utf8字符串转换成Unicode格式。 wchar_t* pUnicodeString = Utf8ToUnicode(pSrcString); if (pUnicodeString) { //再把Unicode字符串转换成Ansi格式。 pAnsiString = UnicodeToAnsi(pUnicodeString); delete[] pUnicodeString; } return pAnsiString; }
void onQuotedText(lString8 & token) { //CRLog::trace("state==%d: \"%s\"", _state, token.c_str()); if (_state == 11 || _state == 13) { if (!token.empty()) { _url = LVCombinePaths(_basePath, Utf8ToUnicode(token)); } _state = 2; } else if (_state == 5) { if (!token.empty()) { _face = token; } _state = 2; } token.clear(); }
bool KAppRes::LoadStringRes() { bool retval = false; void* pBuffer = NULL; unsigned long dwBuffer = 0; TiXmlDocument xmlDoc; const TiXmlElement* pXmlChild = NULL; const TiXmlElement* pXmlItem = NULL; if (!GetRawDataFromRes("strings.xml", &pBuffer, dwBuffer)) goto clean0; if (!xmlDoc.LoadBuffer((char*)pBuffer, (long)dwBuffer, TIXML_ENCODING_UTF8)) goto clean0; pXmlChild = xmlDoc.FirstChildElement("strings"); if (!pXmlChild) goto clean0; pXmlItem = pXmlChild->FirstChildElement("string"); while (pXmlItem) { std::string strId; std::string strValue; strId = pXmlItem->Attribute("id"); strValue = pXmlItem->Attribute("value"); if (strId.length() && strValue.length()) { std::wstring strTemp = Utf8ToUnicode(strValue); update_string(strTemp); m_mapStringTable[strId] = strTemp; } pXmlItem = pXmlItem->NextSiblingElement("string"); } retval = true; clean0: if (pBuffer) { FreeRawData(pBuffer); } return retval; }
QString FilePropsDialog::getDocAuthors( const char * path, const char * delim ) { lString16 res; for ( int i=0; i<100; i++ ) { lString8 p = lString8(path) + "[" + lString8::itoa(i+1) + "]"; lString16 firstName = qt2cr(getDocText( (p + "/first-name").c_str(), " " )); lString16 lastName = qt2cr(getDocText( (p + "/last-name").c_str(), " " )); lString16 middleName = qt2cr(getDocText( (p + "/middle-name").c_str(), " " )); lString16 nickName = qt2cr(getDocText( (p + "/nickname").c_str(), " " )); lString16 homePage = qt2cr(getDocText( (p + "/homepage").c_str(), " " )); lString16 email = qt2cr(getDocText( (p + "/email").c_str(), " " )); lString16 s = firstName; if ( !middleName.empty() ) s << L" " << middleName; if ( !lastName.empty() ) { if ( !s.empty() ) s << L" "; s << lastName; } if ( !nickName.empty() ) { if ( !s.empty() ) s << L" "; s << nickName; } if ( !homePage.empty() ) { if ( !s.empty() ) s << L" "; s << homePage; } if ( !email.empty() ) { if ( !s.empty() ) s << L" "; s << email; } if ( s.empty() ) continue; if ( !res.empty() && delim!=NULL ) res << Utf8ToUnicode( lString8( delim ) ); res << s; } return cr2qt(res); }
lString16 getDocAuthors( ldomDocument * doc, const char * path, const char * delim ) { lString16 res; for ( int i=0; i<100; i++ ) { lString8 p = lString8(path) + "[" + lString8::itoa(i+1) + "]"; //CRLog::trace("checking doc path %s", p.c_str() ); lString16 firstName = getDocText( doc, (p + "/first-name").c_str(), " " ); lString16 lastName = getDocText( doc, (p + "/last-name").c_str(), " " ); lString16 middleName = getDocText( doc, (p + "/middle-name").c_str(), " " ); lString16 nickName = getDocText( doc, (p + "/nickname").c_str(), " " ); lString16 homePage = getDocText( doc, (p + "/homepage").c_str(), " " ); lString16 email = getDocText( doc, (p + "/email").c_str(), " " ); lString16 s = firstName; if ( !middleName.empty() ) s << L" " << middleName; if ( !lastName.empty() ) { if ( !s.empty() ) s << L" "; s << lastName; } if ( !nickName.empty() ) { if ( !s.empty() ) s << L" "; s << nickName; } if ( !homePage.empty() ) { if ( !s.empty() ) s << L" "; s << homePage; } if ( !email.empty() ) { if ( !s.empty() ) s << L" "; s << email; } if ( s.empty() ) continue; if ( !res.empty() && delim!=NULL ) res << Utf8ToUnicode( lString8( delim ) ); res << s; } return res; }
void CRT9Keyboard::draw() { BackgroundFitWindow::draw(); CRMenuSkinRef skin = _wm->getSkin()->getMenuSkin( L"#t9input" ); CRRectSkinRef shortcutSkin = skin->getItemShortcutSkin(); CRRectSkinRef itemSkin = skin->getItemSkin(); CRRectSkinRef clientSkin = skin->getClientSkin(); LVDrawBuf * buf = _wm->getScreen()->getCanvas().get(); skin->draw( *buf, _rect ); lString16 prompt = Utf8ToUnicode(selector_.getPrefix()); prompt << L"_"; skin->draw( *buf, _rect ); //buf->FillRect( _rect, 0xAAAAAA ); lvRect rect = _rect; lvRect borders = skin->getBorderWidths(); rect.shrinkBy( borders ); lvRect keyRect = rect; // lvPoint minSizeN = shortcutSkin->getMinSize(); for ( int i=0; i<encoding_.length(); i++ ) { lString16 txtN = lString16::itoa(i); lString16 txt = encoding_[i]; if ( txt.empty() ) continue; // label 0..9 lvPoint sz = shortcutSkin->measureTextItem( txtN ); keyRect.right = keyRect.left + sz.x; //borders.left + borders.right; shortcutSkin->draw( *buf, keyRect ); shortcutSkin->drawText( *buf, keyRect, txtN ); keyRect.left = keyRect.right; // chars (abc) sz = itemSkin->measureTextItem( txt ); keyRect.right = keyRect.left + sz.x; //borders.left + borders.right; itemSkin->draw( *buf, keyRect ); itemSkin->drawText( *buf, keyRect, txt ); keyRect.left = keyRect.right; //borders.left; } keyRect.right = rect.right; if ( !clientSkin.isNull() && !keyRect.isEmpty() ) { clientSkin->draw( *buf, keyRect ); clientSkin->drawText( *buf, keyRect, prompt ); } }
CString& HexUtf8ToStr(const TCHAR* src, CString& strDec) { char* temp = nullptr; WCHAR* pwsz = nullptr; int iLen = 0; int src_length = 0; strDec.Empty(); #ifdef UNICODE char* temp1 = new char[(src_length = lstrlen(src)) +1]; temp = temp1; while(*(temp1++) = (char)*(src++)); #else temp = (char*)src; src_length = lstrlen(src); #endif int i=0; for(; i < src_length / 2; ++i) { temp[i] = DOUBLECHARTOVALUE(temp + 2*i); } temp[i] = 0; Utf8ToUnicode(temp, &pwsz, iLen); #ifdef UNICODE strDec = pwsz; delete[] temp; #else char* psz = nullptr; UnicodeToMbcs(pwsz, &psz, iLen); strDec = psz; delete[] psz; #endif delete[] pwsz; return strDec; }
lString8 CRTinyDict::translate(const lString8 & w) { lString16 s16 = Utf8ToUnicode( w ); s16.lowercase(); lString8 word = UnicodeToUtf8( s16 ); lString8 body; TinyDictResultList results; if ( dicts.length() == 0 ) { // should not happen body << "<title><p>No dictionaries found</p></title>"; } else if ( dicts.find(results, word.c_str(), TINY_DICT_OPTION_STARTS_WITH ) ) { for ( int d = 0; d<results.length(); d++ ) { TinyDictWordList * words = results.get(d); if ( words->length()>0 ) body << "<title><p>" << _("From dictionary ") << words->getDictionaryName() << ":</p></title>"; // for each found word for ( int i=0; i<words->length(); i++ ) { //TinyDictWord * word = words->get(i); const char * article = words->getArticle( i ); body << "<code style=\"text-align: left; text-indent: 0; font-size: 22\">"; if ( article ) { body << article; } else { body << _("[cannot read article]"); } body << "</code>"; if ( i<words->length()-1 ) body << "<hr/>"; } } } else { body << "<title><p>Article for word " << word << " not found</p></title>"; } return body; }
/// load stylesheet from file, with processing of import bool LVLoadStylesheetFile( lString16 pathName, lString8 & css ) { LVStreamRef file = LVOpenFileStream( pathName.c_str(), LVOM_READ ); if ( file.isNull() ) return false; lString8 txt = UnicodeToUtf8( LVReadTextFile( file ) ); lString8 txt2; const char * s = txt.c_str(); lString8 import_file; if ( LVProcessStyleSheetImport( s, import_file ) ) { lString16 importFilename = LVMakeRelativeFilename( pathName, Utf8ToUnicode(import_file) ); //lString8 ifn = UnicodeToLocal(importFilename); //const char * ifns = ifn.c_str(); if ( !importFilename.empty() ) { LVStreamRef file2 = LVOpenFileStream( importFilename.c_str(), LVOM_READ ); if ( !file2.isNull() ) txt2 = UnicodeToUtf8( LVReadTextFile( file2 ) ); } } if ( !txt2.empty() ) txt2 << "\r\n"; css = txt2 + s; return !css.empty(); }
static bool GetBookProperties(const char *name, BookProperties * pBookProps) { CRLog::trace("GetBookProperties( %s )", name); // check archieve lString16 arcPathName; lString16 arcItemPathName; bool isArchiveFile = LVSplitArcName( lString16(name), arcPathName, arcItemPathName ); // open stream LVStreamRef stream = LVOpenFileStream( (isArchiveFile ? arcPathName : Utf8ToUnicode(lString8(name))).c_str() , LVOM_READ); if (!stream) { CRLog::error("cannot open file %s", name); return false; } if ( DetectEpubFormat( stream ) ) { CRLog::trace("GetBookProperties() : epub format detected"); return GetEPUBBookProperties( name, stream, pBookProps ); } time_t t = (time_t)time(0); if ( isArchiveFile ) { int arcsize = (int)stream->GetSize(); LVContainerRef container = LVOpenArchieve(stream); if ( container.isNull() ) { CRLog::error( "Cannot read archive contents from %s", LCSTR(arcPathName) ); return false; } stream = container->OpenStream(arcItemPathName.c_str(), LVOM_READ); if ( stream.isNull() ) { CRLog::error( "Cannot open archive file item stream %s", LCSTR(lString16(name)) ); return false; } } struct stat fs; if ( !stat( name, &fs ) ) { t = fs.st_mtime; } // read document #if COMPACT_DOM==1 ldomDocument doc(stream, 0); #else ldomDocument doc; #endif ldomDocumentWriter writer(&doc, true); doc.setNodeTypes( fb2_elem_table ); doc.setAttributeTypes( fb2_attr_table ); doc.setNameSpaceTypes( fb2_ns_table ); LVXMLParser parser( stream, &writer ); CRLog::trace( "checking format..." ); if ( !parser.CheckFormat() ) { return false; } CRLog::trace( "parsing..." ); if ( !parser.Parse() ) { return false; } CRLog::trace( "parsed" ); #if 0 char ofname[512]; sprintf(ofname, "%s.xml", name); CRLog::trace(" writing to file %s", ofname); LVStreamRef out = LVOpenFileStream(ofname, LVOM_WRITE); doc.saveToStream(out, "utf16"); #endif lString16 authors = extractDocAuthors( &doc, lString16("|"), false ); lString16 title = extractDocTitle( &doc ); lString16 language = extractDocLanguage( &doc ).lowercase(); lString16 series = extractDocSeries( &doc, &pBookProps->seriesNumber ); #if SERIES_IN_AUTHORS==1 if ( !series.empty() ) authors << " " << series; #endif pBookProps->title = title; pBookProps->author = authors; pBookProps->series = series; pBookProps->filesize = (long)stream->GetSize(); pBookProps->filename = lString16(name); pBookProps->filedate = getDateTimeString( t ); pBookProps->language = language; return true; }