www.itcodet.com
Open in
urlscan Pro
2a06:98c1:3120::c
Public Scan
Submitted URL: https://www.bing.com/ck/a?!&&p=a155e3fde1cf19e8JmltdHM9MTY3MjA5OTIwMCZpZ3VpZD0zZmI4NWFmMy1kOTVjLTY2YWUtMGFlYy00YTI2ZG...
Effective URL: https://www.itcodet.com/cpp/cpp-codecforname-function-examples.html
Submission: On December 27 via manual from IL — Scanned from DE
Effective URL: https://www.itcodet.com/cpp/cpp-codecforname-function-examples.html
Submission: On December 27 via manual from IL — Scanned from DE
Form analysis
1 forms found in the DOMGET /search
<form method="get" class="search-form" action="/search">
<input class="form-control" id="search" name="query" type="text" placeholder="Search..." value="">
<input class="btn" id="submit" type="submit" value="Go">
</form>
Text Content
^ Top * Home * C++ * Python * Java All > Cpp > C++ (Cpp) codecForName Example C++ (CPP) CODECFORNAME EXAMPLE INTRODUCTION The c++ (cpp) codecforname example is extracted from the most popular open source projects, you can refer to the following example for usage. Programming language: C++ (Cpp) Method/Function: codecForName EXAMPLE#1 bool ICQClient::translate(const char *to, const char *from, string &str) { if (*str.c_str() == 0) return true; if (!strcasecmp(from, to)) return true; QTextCodec *fromCodec = (*from) ? codecForName(from) : QTextCodec::codecForLocale(); QTextCodec *toCodec = (*to) ? codecForName(to) : QTextCodec::codecForLocale(); if ((fromCodec == NULL) && (toCodec == NULL) && strcasecmp(from, "UCS-2") && strcasecmp(from, "UTF-8") && strcasecmp(to, "UTF-8")){ if ((*from && strcmp(from, "ascii")) || (*to && strcmp(to, "ascii"))) log(L_WARN, "Codec for %s -> %s not found", from, to); return true; } QString s; if (fromCodec == NULL){ if (strcasecmp(from, "utf-8") == 0){ s = QString::fromUtf8(str.c_str()); }else if (strcasecmp(from, "ucs-2") == 0){ for (unsigned i = 0; i < str.length() / 2; i += 2) s += QChar(*((uint*)(str.c_str() + i))); }else{ if (*from && strcmp(from, "ascii")) log(L_WARN, "Codec for %s not found", from); s = QString::fromLocal8Bit(str.c_str()); } }else{ QTextDecoder *decoder = fromCodec->makeDecoder(); s = decoder->toUnicode(str.c_str(), strlen(str.c_str())); } if (s.length() == 0){ s = ""; return true; } if (toCodec == NULL){ if (strcasecmp(to, "utf-8")){ if (*to && strcmp(to, "ascii")) log(L_WARN, "Codec for %s not found", to); str = s.local8Bit(); }else{ str = s.utf8(); } }else{ QTextEncoder *encoder = toCodec->makeEncoder(); int size = s.length(); str = encoder->fromUnicode(s, size); } return true; } EXAMPLE#2 FILE: NODEHELPER.CPP PROJECT: APPETROSYAN/KUBE const QTextCodec *NodeHelper::codec(KMime::Content *node) { if (! node) { return mLocalCodec; } const QTextCodec *c = mOverrideCodecs.value(node, nullptr); if (!c) { // no override-codec set for this message, try the CT charset parameter: QByteArray charset = node->contentType()->charset(); // utf-8 is a superset of us-ascii, so we don't loose anything, if we it insead // utf-8 is nowadays that widely, that it is a good guess to use it to fix issus with broken clients. if (charset.toLower() == "us-ascii") { charset = "utf-8"; } c = codecForName(charset); } if (!c) { // no charset means us-ascii (RFC 2045), so using local encoding should // be okay c = mLocalCodec; } return c; } EXAMPLE#3 bool ICQClient::translate(const char *to, const char *from, string &str) { if (*str.c_str() == 0) return true; if (!strcasecmp(from, to)) return true; QTextCodec *fromCodec = codecForName(from); QTextCodec *toCodec = codecForName(to); if ((fromCodec == NULL) && (toCodec == NULL)){ if ((*from && strcmp(from, "ascii")) || (*to && strcmp(to, "ascii"))) log(L_WARN, "Codec for %s -> %s not found", from, to); return true; } QString s; if (fromCodec == NULL){ if (*from && strcmp(from, "ascii")) log(L_WARN, "Codec for %s not found", from); s = QString::fromLocal8Bit(str.c_str()); }else{ QTextDecoder *decoder = fromCodec->makeDecoder(); s = decoder->toUnicode(str.c_str(), strlen(str.c_str())); } if (s.length() == 0){ s = ""; return true; } if (toCodec == NULL){ if (*to && strcmp(to, "ascii")) log(L_WARN, "Codec for %s not found", to); str = s.local8Bit(); }else{ QTextEncoder *encoder = toCodec->makeEncoder(); int size = s.length(); str = encoder->fromUnicode(s, size); } return true; } EXAMPLE#4 FILE: KWQKCHARSETS.CPP PROJECT: BACKUPTHEBERLIOS/WXWEBCORE-SVN QTextCodec *KCharsets::codecForName(const QString &qs, bool &ok) const { return codecForName(qs.latin1(), ok); } EXAMPLE#5 FILE: KWQKCHARSETS.CPP PROJECT: BACKUPTHEBERLIOS/WXWEBCORE-SVN QTextCodec *KCharsets::codecForName(const QCString &qs, bool &ok) const { return codecForName(qs.data(), ok); } Previous: C++ (Cpp) codecChanged Example Next: C++ (Cpp) codecList Example RELATED * C++ (Cpp) SInt Example * C++ (Cpp) SGMXASScanConfiguration Example * C++ (Cpp) RequestStats Example * C++ (Cpp) RVar Example * C++ (Cpp) MLVL Example * C++ (Cpp) IHttpStreamAnswer Example * C++ (Cpp) CSid Example * C++ (Cpp) CharReaderBuilder Example * C++ (Cpp) wySprite Example * C++ (Cpp) wxSheetCellRenderer Example * C++ (Cpp) wxScopedCharBuffer Example * C++ (Cpp) wxMouseCaptureChangedEvent Example * C++ (Cpp) wxExVariable Example * C++ (Cpp) wxExVCSCommand Example * C++ (Cpp) wxExItem Example * C++ (Cpp) wxArrayFTPFs Example POPULAR * C++ (Cpp) UniqueRef Example * C++ (Cpp) Var_page Example * C++ (Cpp) XTable Example * C++ (Cpp) ZDragClip_Win_DataObject Example * C++ (Cpp) ZonePacketHandler Example * C++ (Cpp) auto_array_ptr Example * C++ (Cpp) be_ServerImplementation Example * C++ (Cpp) const_inspection_branch_t Example * C++ (Cpp) floatbv_typet Example * C++ (Cpp) imageListType_t Example © 2021 All Rights Reserved. Proudly powered by Wordpress