IAudioSource* cAudioManager::createAudioSource(IAudioDecoder* decoder, const cAudioString& audioName, const cAudioString& dataSource) { if (!decoder) return NULL; if(decoder->isValid()) { #if CAUDIO_EFX_ENABLED == 1 IAudioSource* audio = CAUDIO_NEW cAudioSource(decoder, AudioContext, ((cAudioEffects*)getEffects())->getEFXInterface()); #else IAudioSource* audio = CAUDIO_NEW cAudioSource(decoder, AudioContext); #endif decoder->drop(); if(audio && audio->isValid()) { if(!audioName.empty()) audioIndex[audioName] = audio; audioSources.push_back(audio); getLogger()->logInfo("AudioManager", "Audio Source (%s) created from Data Source %s.", toUTF8(audioName), toUTF8(dataSource)); return audio; } getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Error creating audio source.", toUTF8(audioName)); audio->drop(); return NULL; } getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Audio data could not be decoded by (.%s) decoder.", toUTF8(audioName), toUTF8(decoder->getType())); decoder->drop(); return NULL; }
void FSAdapter::scan(const wstring& path) { wstring localPath = fromUTF8(m_dirPath) + path; WIN32_FIND_DATAW fd; HANDLE fh = FindFirstFileW((LPCWSTR)(localPath + L"*").c_str(), &fd); if (fh == INVALID_HANDLE_VALUE) { Log::error() << "Cannot open directory " << toUTF8(localPath) << ": " << strerror(errno); return; } do { if (!wcscmp(fd.cFileName, L".") || !wcscmp(fd.cFileName, L"..")) { continue; } if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) scan(path + fd.cFileName + L'\\'); else { wstring fileName = path + fd.cFileName; std::replace(fileName.begin(), fileName.end(), L'\\', L'/'); std::wstring lcPath = fileName; std::transform(fileName.begin(), fileName.end(), lcPath.begin(), ::towlower); m_files[toUTF8(lcPath)] = toUTF8(fileName); } } while (FindNextFileW(fh, &fd)); }
logtofile& logtofile::operator<<(wstring buf) { if(_bDebugLog != bDebugLog) init(); log_mutex.lock(); log.open(toUTF8(path).c_str(), std::ios::app |std::ios::ate); log<<toUTF8(buf); log<<"\n"; log.close(); log_mutex.unlock(); return *this; }
void WPushButton::updateDom(DomElement& element, bool all) { if (textChanged_ || all) { element .setProperty(Wt::PropertyInnerHTML, text_.literal() ? toUTF8(escapeText(text_.value())) : toUTF8(text_.value())); textChanged_ = false; } WFormWidget::updateDom(element, all); }
void SFTP::handle_log_close(int handle, char *emsg) { if (handle_is_ok(handle, HANDLE_FILE)) { logit("%s%sclose \"%s\" bytes read %llu written %llu", emsg == NULL ? "" : emsg, emsg == NULL ? "" : " ", toUTF8(handle_to_name(handle)).c_str (), (unsigned long long)handle_bytes_read(handle), (unsigned long long)handle_bytes_write(handle)); } else { logit("%s%sclosedir \"%s\"", emsg == NULL ? "" : emsg, emsg == NULL ? "" : " ", toUTF8(handle_to_name(handle)).c_str ()); } }
void HistoryLogFunc(HANDLE hContact, std::string message) { if(gbHistoryLog) { if(hContact == INVALID_HANDLE_VALUE) return; std::string msg = message; msg.append("\n"); msg.append("Protocol: ").append(GetContactProto(hContact)).append(" Contact: "); msg.append(toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR))).append(" ID: "); msg.append(toUTF8(GetContactUid(hContact,toUTF16(GetContactProto(hContact))))); HistoryLog(NULL, (char*)msg.c_str(), EVENTTYPE_MESSAGE, DBEF_READ); } }
QString Server::findIssue(const QString & text, int & issue_id) { issue_id = -1; // Not found QUrlQuery params; params.addQueryItem("filters[text][operator]", "="); params.addQueryItem("filters[text][value]", text); QString url = "/arx/issues/find/format/rss?issues/project_key/arx&" + toQString(qUrlQueryToPostData(params)); http::Request request(toUTF8(m_serverPrefix + url)); boost::scoped_ptr<http::Response> response(get(request)); if(!response->ok()) { return QString(); } QXmlStreamReader xml(toQByteArray(response->data())); // Using XPath would have probably been simpler, but it would // add a dependency to QtXmlPatterns... // Look for the first "/rss/channel/item/link" entry... const QString XML_PATH[] = { "rss", "channel", "item", "link" }; size_t currentItem = 0; QString issueLink; while(!xml.atEnd() && !xml.hasError()) { // Read next element QXmlStreamReader::TokenType token = xml.readNext(); if(currentItem == size_t(boost::size(XML_PATH))) { QString issue = xml.text().toString(); if(getIssueIdFromUrl(toUTF8(issue), issue_id)) { return issue; } break; } // If token is StartElement, we'll see if we can read it. if(token == QXmlStreamReader::StartElement && xml.name() == XML_PATH[currentItem]) { currentItem++; } } return QString(); }
int notepad_save_file() { int i; char file[256]; xmlDocPtr doc = NULL; // document pointer xmlNodePtr root_node = NULL, node = NULL; // node pointers safe_snprintf (file, sizeof (file), "%snotes.xml", configdir); doc = xmlNewDoc (BAD_CAST "1.0"); root_node = xmlNewNode (NULL, BAD_CAST "PAD"); xmlDocSetRootElement (doc, root_node); for (i = 0; i < nr_notes; i++) { xmlChar* data; char* subst_string = NULL; // libxml2 expects all data in UTF-8 encoding. xmlChar* name = toUTF8 (note_list[i].name, strlen (note_list[i].name)); substitute_char_with_string (note_list[i].text.data, &subst_string, '&', "&"); data = toUTF8 (subst_string, strlen(subst_string)); node = xmlNewChild (root_node, NULL, BAD_CAST "NOTE", data); xmlNewProp (node, BAD_CAST "NAME", name); free (subst_string); free (data); free (name); } if (xmlSaveFormatFileEnc (file, doc, "UTF-8", 1) < 0) { #ifndef WINDOWS // error writing. try the data directory safe_snprintf (file, sizeof (file), "%s/%s", datadir, "notes.xml"); if (xmlSaveFormatFileEnc(file, doc, "UTF-8", 1) < 0) { LOG_ERROR_OLD(cant_save_notes, file); } #else LOG_ERROR_OLD(cant_save_notes, file); #endif return 0; } // Success! return 1; }
void WComboBox::updateDom(DomElement& element, bool all) { if (itemsChanged_ || all) { if (!all) element.removeAllChildren(); for (unsigned i = 0; i < items_.size(); ++i) { DomElement *item = DomElement::createNew(DomElement::OPTION); item->setAttribute("value", boost::lexical_cast<std::string>(i)); item->setProperty(Wt::PropertyInnerHTML, toUTF8(escapeText(items_[i].value()))); if ((int)i == currentIndex_) item->setProperty(Wt::PropertySelected, "true"); element.addChild(item); } itemsChanged_ = false; } if (selectionChanged_) { element.setProperty(Wt::PropertySelectedIndex, boost::lexical_cast<std::string>(currentIndex_)); selectionChanged_ = false; } if (activated.isConnected() || sactivated.isConnected()) changed.connect(SLOT(this, WComboBox::propagateChange)); WFormWidget::updateDom(element, all); renderOk(); }
static std::string qUrlQueryToPostData(const QUrlQuery & query) { #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) return toStdString(query.encodedQuery()); #else return toUTF8(query.query(QUrl::FullyEncoded)); #endif }
QString Server::createCrashReport(const QString & title, const QString & description, const QString & reproSteps, int version_id, int & issue_id) { QUrlQuery params; params.addQueryItem("project_id", "2"); params.addQueryItem("issuetype_id", "7"); params.addQueryItem("title", title); params.addQueryItem("description", description); params.addQueryItem("reproduction_steps", reproSteps); params.addQueryItem("build_id", QString::number(version_id)); params.addQueryItem("component_id", ""); params.addQueryItem("category_id", "0"); params.addQueryItem("reproducability_id", "0"); params.addQueryItem("estimated_time", ""); params.addQueryItem("priority_id", "0"); params.addQueryItem("resolution_id", "0"); params.addQueryItem("severity_id", "0"); http::POSTRequest request(toUTF8(m_serverPrefix + "/arx/issues/new")); request.setData(qUrlQueryToPostData(params)); request.setFollowRedirects(false); boost::scoped_ptr<http::Response> response(post(request)); if(response->ok() && getIssueIdFromUrl(response->url(), issue_id)) { return toQString(response->url()); } return QString(); }
bool WString::empty() const { if (literal()) return utf8_.empty(); else return toUTF8().empty(); }
// the returned pointer is actually to the second character // if the first character is - then free, otherwise don't static const char *initerr(const char *message, const WCHAR *label, DWORD value) { WCHAR *sysmsg; BOOL hassysmsg; WCHAR *wmessage; WCHAR *wout; char *out; hassysmsg = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, value, 0, (LPWSTR) (&sysmsg), 0, NULL) != 0; if (!hassysmsg) sysmsg = L""; wmessage = toUTF16(message + 1); wout = debugstrf(L"-error initializing libui: %s; code %I32d (0x%08I32X) %s", wmessage, value, value, sysmsg); uiFree(wmessage); if (hassysmsg) LocalFree(sysmsg); // ignore error if (wout == NULL) // debugstrf() failed; return message raw return message + 1; out = toUTF8(wout); uiFree(wout); return out + 1; }
static const char *initerr(const char *message, const WCHAR *label, DWORD value) { WCHAR *sysmsg; BOOL hassysmsg; WCHAR *beforele; WCHAR *afterle; int n; WCHAR *wmessage; WCHAR *wstr; const char *str; if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, value, 0, (LPWSTR) (&sysmsg), 0, NULL) != 0) { hassysmsg = TRUE; beforele = L" ("; afterle = L")"; } else { hassysmsg = FALSE; sysmsg = L""; beforele = L""; afterle = L""; } wmessage = toUTF16(message); n = _scwprintf(initErrorFormat, initErrorArgs); wstr = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); snwprintf(wstr, n + 1, initErrorFormat, initErrorArgs); str = toUTF8(wstr); uiFree(wstr); if (hassysmsg) if (LocalFree(sysmsg) != NULL) logLastError("error freeing system message in loadLastError()"); uiFree(wmessage); return str; }
void SFTP::process_fstat(void) { Attrib a; BY_HANDLE_FILE_INFORMATION st; u_int32_t id; int handle, status = SSH2_FX_FAILURE; id = get_int(); handle = get_handle(); debug("request %u: fstat \"%s\" (handle %u)", id, toUTF8(handle_to_name(handle)).c_str (), handle); const HANDLE fh = handle_to_fh(handle); if (fh != INVALID_HANDLE_VALUE) { if (!::GetFileInformationByHandle (fh, &st)) { status = errno_to_portable(::GetLastError ()); } else { stat_to_attrib(&st, &a); send_attrib(id, &a); status = SSH2_FX_OK; } } if (status != SSH2_FX_OK) send_status(id, status); }
void outputTags(FILE* output) { lua_getglobal(state, "getTagsFromInfoTable"); lua_newtable(state); int size = 0; long lines = getSOSILinesLength(); for (int i = 0; i < lines; i++) { char buffer[256]; char* line = toUTF8(getSOSILine(i), buffer, 256); if (line != NULL) { lua_pushinteger(state, ++size); lua_pushstring(state, line); lua_settable(state, -3); } } lua_setglobal(state, "info"); lua_call(state, 0, 1); lua_pushnil(state); while (lua_next(state, 1) != 0) { if (lua_type(state, -2) != LUA_TSTRING) { fprintf(stderr, "Error in lua script: key must be string, got '%s'\n", lua_tostring(state, -2)); exit(1); } const char* key = lua_tostring(state, -2); const char* value = lua_tostring(state, -1); fprintf(output, "<tag k=\"%s\" v=\"%s\"/>", key, value); lua_pop(state, 1); } lua_pop(state, 1); }
IAudioSource* cAudioManager::createFromMemory(const char* name, const char* data, size_t length, const char* extension) { if(!Initialized) return NULL; cAudioMutexBasicLock lock(Mutex); cAudioString audioName = fromUTF8(name); cAudioString ext = fromUTF8(extension); IAudioDecoderFactory* factory = getAudioDecoderFactory(toUTF8(ext)); if(!factory) { getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Codec (.%s) is not supported.", toUTF8(audioName), toUTF8(ext)); return NULL; } cMemorySource* source = CAUDIO_NEW cMemorySource(data, length, true); if(source && source->isValid()) { IAudioDecoder* decoder = factory->CreateAudioDecoder(source); source->drop(); IAudioSource* audio = createAudioSource(decoder, audioName, _CTEXT("cMemorySource")); if(audio != NULL) return audio; if(source) source->drop(); } return NULL; }
// toUTF8 returns the whole string in UTF-8. std::string toUTF8(TextWord *w) { std::u32string s; for (int i = 0; i < w->getLength(); i++) { s += static_cast<char32_t>(*w->getChar(i)); } return toUTF8(s); }
// toUTF8 returns the whole string in UTF-8. std::string toUTF8(Unicode *u, int n) { std::u32string s; for (int i = 0; i < n; i++) { s += static_cast<char32_t>(*(u + i)); } return toUTF8(s); }
static void create (MemoryBlock& block, const StringPairArray& values) { auto numNotes = values.getValue ("NumCueNotes", "0").getIntValue(); if (numNotes > 0) { MemoryOutputStream out (block, false); out.writeShortBigEndian ((short) numNotes); for (int i = 0; i < numNotes; ++i) { auto prefix = "CueNote" + String (i); out.writeIntBigEndian (values.getValue (prefix + "TimeStamp", "0").getIntValue()); out.writeShortBigEndian ((short) values.getValue (prefix + "Identifier", "0").getIntValue()); auto comment = values.getValue (prefix + "Text", String()); auto commentLength = jmin (comment.getNumBytesAsUTF8(), (size_t) 65534); out.writeShortBigEndian ((short) commentLength + 1); out.write (comment.toUTF8(), commentLength); out.writeByte (0); if ((out.getDataSize() & 1) != 0) out.writeByte (0); } } }
char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd) { IFileDialog *d = NULL; FILEOPENDIALOGOPTIONS opts; IShellItem *result = NULL; WCHAR *wname = NULL; char *name = NULL; HRESULT hr; hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, (LPVOID *) (&d)); if (hr != S_OK) { logHRESULT(L"error creating common item dialog", hr); // always return NULL on error goto out; } hr = d->GetOptions(&opts); if (hr != S_OK) { logHRESULT(L"error getting current options", hr); goto out; } opts |= optsadd; // the other platforms don't check read-only; we won't either opts &= ~FOS_NOREADONLYRETURN; hr = d->SetOptions(opts); if (hr != S_OK) { logHRESULT(L"error setting options", hr); goto out; } hr = d->Show(parent); if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) // cancelled; return NULL like we have ready goto out; if (hr != S_OK) { logHRESULT(L"error showing dialog", hr); goto out; } hr = d->GetResult(&result); if (hr != S_OK) { logHRESULT(L"error getting dialog result", hr); goto out; } hr = result->GetDisplayName(SIGDN_FILESYSPATH, &wname); if (hr != S_OK) { logHRESULT(L"error getting filename", hr); goto out; } name = toUTF8(wname); out: if (wname != NULL) CoTaskMemFree(wname); if (result != NULL) result->Release(); if (d != NULL) d->Release(); return name; }
WString WString::trim() const { std::string u8 = toUTF8(); boost::trim(u8); return WString::fromUTF8(u8, false); }
SingleString StringUtils::toUTF8(const wchar_t* unicode, int32_t length) { if (length == 0) return ""; ByteArray utf8(ByteArray::newInstance(length * MAX_ENCODING_UTF8_SIZE)); int32_t result = toUTF8(unicode, length, utf8); return SingleString((char*)utf8.get(), result); }
void SFTP::process_write(void) { u_int32_t id; u_int64_t off; u_int len; int handle, status = SSH2_FX_FAILURE; char *data; id = get_int(); handle = get_handle(); off = get_int64(); data = (char*) get_string(&len); #ifdef SLOW_DEBUG debug("request %u: write \"%s\" (handle %d) off %llu len %d", id, toUTF8 (handle_to_name(handle)).c_str (), handle, (unsigned long long)off, len); #endif HANDLE fh = handle_to_fh(handle); if (fh != INVALID_HANDLE_VALUE) { LARGE_INTEGER largeOffset; largeOffset.QuadPart = off; if (!::SetFilePointerEx (fh, largeOffset, NULL, FILE_BEGIN) ) { status = errno_to_portable(::GetLastError ()); error("process_write: seek failed"); } else { /* XXX ATOMICIO ? */ DWORD nBytesWritten; if (!::WriteFile (fh, data, len, &nBytesWritten, 0)) { error("process_write: write failed"); int err = ::GetLastError (); if (err != 0) status = errno_to_portable(err); else status = SSH2_FX_FAILURE; //TODO reason? } else if ((size_t) nBytesWritten == len) { status = SSH2_FX_OK; handle_update_write(handle, (ssize_t) nBytesWritten); } else { debug2("nothing at all written"); } } } send_status(id, status); xfree(data); }
char *uiWindowsWindowText(HWND hwnd) { WCHAR *wtext; char *text; wtext = windowText(hwnd); text = toUTF8(wtext); uiFree(wtext); return text; }
int32_t StringUtils::toUTF8(const wchar_t* unicode, int32_t length, const UTF8ResultPtr& utf8Result) { if (length == 0) { utf8Result->length = 0; } else { if (length * MAX_ENCODING_UTF8_SIZE > utf8Result->result.size()) { utf8Result->result.resize(length * MAX_ENCODING_UTF8_SIZE); } utf8Result->length = toUTF8(unicode, length, utf8Result->result); } return utf8Result->length; }
MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) { std::cout << "load ini file: " << filename << std::endl; std::string section(""); MwIniImporter::multistrmap map; boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str()); std::string line; while (std::getline(file, line)) { line = toUTF8(line); // unify Unix-style and Windows file ending if (!(line.empty()) && (line[line.length()-1]) == '\r') { line = line.substr(0, line.length()-1); } if(line[0] == '[') { int pos = line.find(']'); if(pos < 2) { std::cout << "Warning: ini file wrongly formatted (" << line << "). Line ignored." << std::endl; continue; } section = line.substr(1, line.find(']')-1); continue; } int comment_pos = line.find(";"); if(comment_pos > 0) { line = line.substr(0,comment_pos); } if(line.empty()) { continue; } int pos = line.find("="); if(pos < 1) { continue; } std::string key(section + ":" + line.substr(0,pos)); std::string value(line.substr(pos+1)); multistrmap::iterator it; if((it = map.find(key)) == map.end()) { map.insert( std::make_pair (key, std::vector<std::string>() ) ); } map[key].push_back(value); } return map; }
/* internal (EUC/SJIS/UPTEX) to 'enc' code conversion */ static long toENC(long kcode, int enc) { switch (enc) { case ENC_UTF8: return toUTF8(kcode); case ENC_JIS: return toJIS(kcode); case ENC_EUC: return toEUC(kcode); case ENC_SJIS: return toSJIS(kcode); default: fprintf(stderr, "toENC: unknown enc (%d).\n", enc); return 0; } }
std::string toUTF8(const std::string& s) { #ifndef WT_NO_STD_WSTRING return toUTF8(widen(s)); #else // You may want to rewrite this for your system std::string retval = s; for(std::size_t i = 0; i < retval.size(); ++i) if (retval[i] > 127) retval[i] = '?'; return s; #endif }
bool CodeDocument::writeToStream (OutputStream& stream) { for (auto* l : lines) { auto temp = l->line; // use a copy to avoid bloating the memory footprint of the stored string. const char* utf8 = temp.toUTF8(); if (! stream.write (utf8, strlen (utf8))) return false; } return true; }