void GuiClipboard::put(string const & lyx, docstring const & html, docstring const & text) { LYXERR(Debug::ACTION, "GuiClipboard::put(`" << lyx << "' `" << to_utf8(html) << "' `" << to_utf8(text) << "')"); // We don't convert the encoding of lyx since the encoding of the // clipboard contents is specified in the data itself QMimeData * data = new QMimeData; if (!lyx.empty()) { QByteArray const qlyx(lyx.c_str(), lyx.size()); data->setData(lyxMimeType(), qlyx); // If the OS has not the concept of clipboard ownership, // we recognize internal data through its checksum. if (!hasInternal()) { boost::crc_32_type crc32; crc32.process_bytes(lyx.c_str(), lyx.size()); checksum = crc32.checksum(); } } // Don't test for text.empty() since we want to be able to clear the // clipboard. QString const qtext = toqstr(text); data->setText(qtext); QString const qhtml = toqstr(html); data->setHtml(qhtml); qApp->clipboard()->setMimeData(data, QClipboard::Clipboard); }
docstring InsetListings::getCaption(OutputParams const & runparams) const { if (paragraphs().empty()) return docstring(); InsetCaption const * ins = getCaptionInset(); if (ins == 0) return docstring(); TexRow texrow; odocstringstream ods; otexstream os(ods, texrow); ins->getOptArg(os, runparams); ins->getArgument(os, runparams); // the caption may contain \label{} but the listings // package prefer caption={}, label={} docstring cap = ods.str(); if (!contains(to_utf8(cap), "\\label{")) return cap; // convert from // blah1\label{blah2} blah3 // to // blah1 blah3},label={blah2 // to form options // caption={blah1 blah3},label={blah2} // // NOTE that } is not allowed in blah2. regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)"); string const new_cap("\\1\\3},label={\\2"); return from_utf8(regex_replace(to_utf8(cap), reg, new_cap)); }
ChatClient(void *epoll, void *raddr, int raddrlen) : epoll(epoll) { /* Construct a std::string representation of our remote address. The actual 32 bit address in a sockaddr_in structure is located at +4, and the big endian port number is at +2. Since we don't want our compiler complaining about pointer math we case it to an unsigned char * */ unsigned char *r = (unsigned char *)raddr; void *ht_addrstr = inet_ntoa(*(unsigned *)(r+4)); /* Next up, we need the port number, but since it is in big endian order, we can extract the bytes directly. */ int port = (r[2] << 8) + r[3]; /* Convert that to a string with the HeavyThing string library... of course we could use snprintf, etc but we are mixing it up on purpose here. */ void *ht_portstr = string$from_unsigned(port, 10); /* Now we can construct our char * of the above */ char scratch[32]; int i = string$to_utf8(ht_addrstr, scratch); scratch[i] = ':'; int j = string$to_utf8(ht_portstr, &scratch[i+1]); scratch[i+j+1] = 0; remote_address = std::string(scratch, i+j+1); }
FileFilterList::FileFilterList(docstring const & qt_style_filter) { // FIXME UNICODE string const filter = to_utf8(qt_style_filter) + (qt_style_filter.empty() ? string() : ";;") + to_utf8(_("All Files ")) #if defined(_WIN32) + ("(*.*)"); #else + ("(*)"); #endif // Split data such as "TeX documents (*.tex);;LyX Documents (*.lyx)" // into individual filters. static lyx::regex const separator_re(";;"); string::const_iterator it = filter.begin(); string::const_iterator const end = filter.end(); while (true) { match_results<string::const_iterator> what; if (!lyx::regex_search(it, end, what, separator_re)) { parse_filter(string(it, end)); break; } // Everything from the start of the input to // the start of the match. parse_filter(string(what[-1].first, what[-1].second)); // Increment the iterator to the end of the match. it += distance(it, what[0].second); } }
void InsetRef::validate(LaTeXFeatures & features) const { string const cmd = getCmdName(); if (cmd == "vref" || cmd == "vpageref") features.require("varioref"); else if (cmd == "formatted") { docstring const data = getEscapedLabel(features.runparams()); docstring label; docstring prefix; string const fcmd = to_utf8(getFormattedCmd(data, label, prefix)); if (buffer().params().use_refstyle) { features.require("refstyle"); if (prefix == "cha") features.addPreambleSnippet("\\let\\charef=\\chapref"); else if (!prefix.empty()) { string lcmd = "\\AtBeginDocument{\\providecommand" + fcmd + "[1]{\\ref{" + to_utf8(prefix) + ":#1}}}"; features.addPreambleSnippet(lcmd); } } else { features.require("prettyref"); // prettyref uses "cha" for chapters, so we provide a kind of // translation. if (prefix == "chap") features.addPreambleSnippet("\\let\\pr@chap=\\pr@cha"); } } else if (cmd == "eqref" && !buffer().params().use_refstyle) // with refstyle, we simply output "(\ref{label})" features.require("amsmath"); else if (cmd == "nameref") features.require("nameref"); }
void LaTeXFeatures::showStruct() const { lyxerr << "LyX needs the following commands when LaTeXing:" << "\n***** Packages:" << getPackages() << "\n***** Macros:" << to_utf8(getMacros()) << "\n***** Textclass stuff:" << to_utf8(getTClassPreamble()) << "\n***** done." << endl; }
//****************************************************************************** bool CClipboard::SetString( //Copies the given string into the system clipboard //Returns: true on success, false otherwise. // //Params: const WSTRING& sClip) //(in) { #ifdef WIN32 if (!OpenClipboard(NULL)) return false; EmptyClipboard(); HGLOBAL global = GlobalAlloc(GMEM_ZEROINIT, (sClip.size()+1)*sizeof(WCHAR)); if (global == NULL) { CloseClipboard(); return false; } LPWSTR data = (LPWSTR)GlobalLock(global); WCScpy(data, sClip.c_str()); GlobalUnlock(global); SetClipboardData(CF_UNICODETEXT, global); CloseClipboard(); return true; #elif defined(__APPLE__) PasteboardRef theClipboard; OSStatus err = PasteboardCreate(kPasteboardClipboard, &theClipboard); if (err != noErr) return false; PasteboardClear(theClipboard); PasteboardSynchronize(theClipboard); BYTE *pbOutStr = NULL; if (to_utf8(sClip.c_str(), pbOutStr)) { CFDataRef data = CFDataCreate(kCFAllocatorDefault, (UInt8*)pbOutStr, sClip.size() + 1); PasteboardPutItemFlavor(theClipboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), data, 0); } delete[] pbOutStr; return true; #elif defined(__linux__) || defined(__FreeBSD__) bool bSuccess = false; BYTE *pbOutStr = NULL; if (to_utf8(sClip.c_str(), pbOutStr)) bSuccess = SetStringUTF8((const char*)pbOutStr); delete[] pbOutStr; return bSuccess; #elif defined(__native_client__) return false; #else #error CClipboard::SetString -- Unicode not implemented #endif }
bool LyXVC::registrer() { FileName const filename = owner_->fileName(); // there must be a file to save if (!filename.isReadableFile()) { Alert::error(_("Document not saved"), _("You must save the document " "before it can be registered.")); return false; } // it is very likely here that the vcs is not created yet... if (!vcs) { //check in the root directory of the document FileName const cvs_entries(onlyPath(filename.absFileName()) + "/CVS/Entries"); FileName const svn_entries(onlyPath(filename.absFileName()) + "/.svn/entries"); FileName const git_index(onlyPath(filename.absFileName()) + "/.git/index"); if (git_index.isReadableFile()) { LYXERR(Debug::LYXVC, "LyXVC: registering " << to_utf8(filename.displayName()) << " with GIT"); vcs.reset(new GIT(git_index, owner_)); } else if (svn_entries.isReadableFile()) { LYXERR(Debug::LYXVC, "LyXVC: registering " << to_utf8(filename.displayName()) << " with SVN"); vcs.reset(new SVN(svn_entries, owner_)); } else if (cvs_entries.isReadableFile()) { LYXERR(Debug::LYXVC, "LyXVC: registering " << to_utf8(filename.displayName()) << " with CVS"); vcs.reset(new CVS(cvs_entries, owner_)); } else { LYXERR(Debug::LYXVC, "LyXVC: registering " << to_utf8(filename.displayName()) << " with RCS"); vcs.reset(new RCS(FileName(), owner_)); } } LYXERR(Debug::LYXVC, "LyXVC: registrer"); docstring response; bool ok = Alert::askForText(response, _("LyX VC: Initial description"), _("(no initial description)")); if (!ok) { LYXERR(Debug::LYXVC, "LyXVC: user cancelled"); vcs.reset(0); return false; } if (response.empty()) response = _("(no initial description)"); vcs->registrer(to_utf8(response)); return true; }
// This function borrows some code from the Pidgin project LmHandlerResult handle_iq_time(LmMessageHandler *h, LmConnection *c, LmMessage *m, gpointer ud) { LmMessage *r; LmMessageNode *query; char *buf, *utf8_buf; time_t now_t; struct tm *now; time(&now_t); if (!settings_opt_get_int("iq_hide_requests")) { scr_LogPrint(LPRINT_LOGNORM, "Received an IQ time request from <%s>", lm_message_get_from(m)); } if (settings_opt_get_int("iq_time_hide")) { send_iq_error(c, m, XMPP_ERROR_SERVICE_UNAVAILABLE); return LM_HANDLER_RESULT_REMOVE_MESSAGE; } buf = g_new0(char, 512); r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT); query = lm_message_node_add_child(r->node, "query", NULL); lm_message_node_set_attribute(query, "xmlns", NS_TIME); now = gmtime(&now_t); strftime(buf, 512, "%Y%m%dT%T", now); lm_message_node_add_child(query, "utc", buf); now = localtime(&now_t); strftime(buf, 512, "%Z", now); if ((utf8_buf = to_utf8(buf))) { lm_message_node_add_child(query, "tz", utf8_buf); g_free(utf8_buf); } strftime(buf, 512, "%d %b %Y %T", now); if ((utf8_buf = to_utf8(buf))) { lm_message_node_add_child(query, "display", utf8_buf); g_free(utf8_buf); } lm_connection_send(c, r, NULL); lm_message_unref(r); g_free(buf); return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
int from_utf16(const wchar_t *utf16, TCHAR **buffer, unsigned long *buflen) { #ifdef UNICODE return to_utf16(utf16, buffer, buflen); #else return to_utf8(utf16, buffer, buflen); #endif }
// ignore for session void AppleSpellChecker::accept(WordLangTuple const & word) { string const word_str = to_utf8(word.word()); AppleSpeller_ignore(d->speller, word_str.c_str()); LYXERR(Debug::GUI, "ignore word: \"" << word.word() << "\"") ; advanceChangeNumber(); }
// remove from personal dictionary void AppleSpellChecker::remove(WordLangTuple const & word) { string const word_str = to_utf8(word.word()); AppleSpeller_unlearn(d->speller, word_str.c_str()); LYXERR(Debug::GUI, "unlearn word: \"" << word.word() << "\"") ; advanceChangeNumber(); }
bool open(const std::filesystem::path& jpeg_file) override { auto fp = ::fopen(to_osmbstr(to_utf8(jpeg_file.native())).c_str(), "rb"); if(nullptr == fp) return false; bool is_opened = false; struct ::jpeg_decompress_struct jdstru; error_mgr jerr; jdstru.err = ::jpeg_std_error(&jerr.pub); jerr.pub.error_exit = _m_error_handler; if (!setjmp(jerr.setjmp_buf)) { ::jpeg_create_decompress(&jdstru); ::jpeg_stdio_src(&jdstru, fp); _m_read_jpg(jdstru); jpeg_finish_decompress(&jdstru); is_opened = true; } ::jpeg_destroy_decompress(&jdstru); ::fclose(fp); return is_opened; }
/* Sets, unsets or changes the pathname and name for an icon. * Updates icons_hash and (re)stats the item. * If name is NULL then gets the leafname from pathname. * If pathname is NULL, frees everything. */ void icon_set_path(Icon *icon, const char *pathname, const char *name) { if (icon->path) { icon_unhash_path(icon); icon->src_path = NULL; icon->path = NULL; diritem_free(icon->item); icon->item = NULL; } if (pathname) { if (g_utf8_validate(pathname, -1, NULL)) icon->src_path = g_strdup(pathname); else icon->src_path = to_utf8(pathname); icon->path = expand_path(icon->src_path); icon_hash_path(icon); if (!name) name = g_basename(icon->src_path); icon->item = diritem_new(name); diritem_restat(icon->path, icon->item, NULL); } }
void CairoFont::GetExtent( unsigned char c, float * outWidth, float * outHeight, VGDevice * dev ) const { extern const char* to_utf8 (int n, int& outcount); int n; const char * str = to_utf8(c, n); return GetExtent (str, outWidth, outHeight, (cairo_t *)dev->GetNativeContext()); }
void MainWindow::visitMkvmergeDocumentation() { auto appDirPath = App::applicationDirPath(); auto potentialPaths = QStringList{}; try { auto localeStr = locale_string_c{to_utf8(Util::Settings::get().localeToUse())}; potentialPaths << Q("%1/doc/%2").arg(appDirPath).arg(Q(localeStr.str(locale_string_c::full))); potentialPaths << Q("%1/doc/%2").arg(appDirPath).arg(Q(localeStr.str(static_cast<locale_string_c::eval_type_e>(locale_string_c::language | locale_string_c::territory)))); potentialPaths << Q("%1/doc/%2").arg(appDirPath).arg(Q(localeStr.str(locale_string_c::language))); } catch (mtx::locale_string_format_x const &) { } potentialPaths << Q("%1/doc/en").arg(appDirPath); auto url = QUrl{}; for (auto const &path : potentialPaths) { auto fileName = Q("%1/mkvmerge.html").arg(path); if (QFileInfo{fileName}.exists()) { url.setScheme(Q("file")); url.setPath(fileName); break; } } if (url.isEmpty()) url = m_helpURLs[ui->actionHelpMkvmergeDocumentation]; QDesktopServices::openUrl(url); }
void encoded_string::load(std::istream & is, std::string & target, uint32_t codepage) { std::string temp; binary_string::load(is, temp); to_utf8(temp, target, codepage); }
void Track::setDefaults() { auto &settings = Settings::get(); if (isAudio() && settings.m_setAudioDelayFromFileName) m_delay = extractAudioDelayFromFileName(); if (settings.m_disableAVCompression && (isVideo() || isAudio())) m_compression = CompNone; m_forcedTrackFlag = m_properties[Q("forced_track")] == "1"; m_defaultTrackFlagWasSet = m_properties[Q("default_track")] == "1"; m_name = m_properties[Q("track_name")]; m_cropping = m_properties[Q("cropping")]; if (!m_properties[Q("stereo_mode")].isEmpty()) m_stereoscopy = m_properties[Q("stereo_mode")].toUInt() + 1; auto idx = map_to_iso639_2_code(to_utf8(m_properties[Q("language")]), true); if (0 <= idx) m_language = to_qs(iso639_languages[idx].iso639_2_code); QRegExp re_displayDimensions{"^(\\d+)x(\\d+)$"}; if (-1 != re_displayDimensions.indexIn(m_properties[Q("display_dimensions")])) { m_displayWidth = re_displayDimensions.cap(1); m_displayHeight = re_displayDimensions.cap(2); } }
void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action()) { case LFUN_INSET_MODIFY: setInfo(to_utf8(cmd.argument())); break; case LFUN_INSET_COPY_AS: { cap::clearSelection(); Cursor copy(cur); copy.pushBackward(*this); copy.pit() = 0; copy.pos() = 0; copy.resetAnchor(); copy.pit() = copy.lastpit(); copy.pos() = copy.lastpos(); copy.setSelection(); cap::copySelection(copy); break; } default: InsetCollapsable::doDispatch(cur, cmd); break; } }
void ParagraphParameters::write(ostream & os) const { // Maybe the paragraph has special spacing spacing().writeFile(os, true); // The labelwidth string used in lists. if (!labelWidthString().empty()) os << "\\labelwidthstring " << to_utf8(labelWidthString()) << '\n'; // Start of appendix? if (startOfAppendix()) os << "\\start_of_appendix\n"; // Noindent? if (noindent()) os << "\\noindent\n"; // Do we have a manual left indent? if (!leftIndent().zero()) os << "\\leftindent " << leftIndent().asString() << '\n'; // Alignment? if (align() != LYX_ALIGN_LAYOUT) { int h = 0; switch (align()) { case LYX_ALIGN_LEFT: h = 1; break; case LYX_ALIGN_RIGHT: h = 2; break; case LYX_ALIGN_CENTER: h = 3; break; default: h = 0; break; } os << "\\align " << string_align[h] << '\n'; } }
wxString mmg_options_t::mkvmerge_exe() { #if defined(SYS_WINDOWS) auto exe_with_ext = "mkvmerge.exe"; #else auto exe_with_ext = "mkvmerge"; #endif // Check whether or not the mkvmerge executable path is still set to // the default value "mkvmerge". If it is try getting the // installation path from the registry and use that for a more // precise location for mkvmerge.exe. Fall back to the old default // value "mkvmerge" if all else fails. auto exe = bfs::path{to_utf8(mkvmerge)}; if ((exe.string() == "mkvmerge") || (exe.string() == exe_with_ext)) exe = bfs::path{}; if (exe.empty()) { exe = mtx::sys::get_installation_path(); if (!exe.empty() && bfs::exists(exe) && bfs::exists(exe / exe_with_ext)) exe = exe / exe_with_ext; else exe = bfs::path{}; } if (exe.empty()) exe = exe_with_ext; wxLogMessage(wxT("mkvmerge_exe %s installation_path %s\n"), wxU(exe.string()).c_str(), wxU(mtx::sys::get_installation_path().string()).c_str()); return wxU(exe.string()); }
void GuiSelection::put(docstring const & str) { LYXERR(Debug::SELECTION, "GuiSelection::put: " << to_utf8(str)); qApp->clipboard()->setText(externalLineEnding(str), QClipboard::Selection); }
int main(int argc, char* argv[]) { fs::path game_dir("C:\\my\\unity\\proj1\\proj1\\build\\1_Data"); fs::path managed_dir = game_dir / "Managed"; fs::path mono_dir = game_dir / "Mono"; fs::path dll_path = mono_dir / "_mono.dll"; HMODULE dll = LoadLibraryA(dll_path.string().c_str()); auto f = make_shared<mono_wrapper::functions_t>(mono_wrapper::load_mono_functions_from_dll(dll)); f->mono_set_dirs(managed_dir.string().c_str(), (game_dir / "Mono/etc").string().c_str()); { std::stringstream ss; ss << managed_dir.string() << ";" << mono_dir.string(); f->mono_set_assemblies_path(ss.str().c_str()); } MonoDomain* domain = f->mono_jit_init("My domain"); auto s = new_String(f, "Hello!"); auto s1 = s->ToUpper(); string s1_content = s1->to_utf8(); int32_t len = s->get_Length(); return 0; }
ProcessPtr Process::execute(QString const &command, QStringList const &args, bool useTempFile) { auto runner = [](QString const &commandToUse, QStringList const &argsToUse) { auto pr = std::make_shared<Process>( commandToUse, argsToUse ); pr->run(); return pr; }; if (!useTempFile) return runner(command, args); QTemporaryFile optFile; if (!optFile.open()) throw ProcessX{ to_utf8(QY("Error creating a temporary file (reason: %1).").arg(optFile.errorString())) }; static const unsigned char utf8_bom[3] = {0xef, 0xbb, 0xbf}; optFile.write(reinterpret_cast<char const *>(utf8_bom), 3); for (auto &arg : args) optFile.write(QString{"%1\n"}.arg(arg).toUtf8()); optFile.close(); QStringList argsToUse; argsToUse << QString{"@%1"}.arg(optFile.fileName()); return runner(command, argsToUse); }
/** * Write one version element to disk * @param vparent the parent versions element * @param v the version to write * @param index the index of the version (>=1) * @return 1 if it worked else 0 */ static int write_one_version( dom_item *vparent, version *v, int index ) { int res = 1; char istr[8]; snprintf( istr,8,"%d",index); dom_item *velement = dom_object_create( "version" ); if ( velement != NULL ) { dom_attribute *attr = dom_attribute_create("id",istr); if ( attr != NULL ) { res = dom_add_attribute( velement, attr ); if ( res ) { char *vid = to_utf8( version_id(v), u_strlen(version_id(v)) ); if ( vid != NULL ) { UChar *v_desc = version_description(v); char *description = to_utf8( v_desc, u_strlen(v_desc) ); if ( description != NULL ) { res = dom_add_attribute( velement, dom_attribute_create("vid",vid) ); if ( res ) res = dom_add_attribute( velement, dom_attribute_create("description", description) ); if ( res ) res = dom_add_child( vparent, velement ); free( description ); } free( vid ); } else res = 0; } else res = 0; } else res = 0; } else res = 0; return res; }
/** * Return utf8 version of print_path. * * @param info file information * @return utf8 string on success, NULL if couldn't convert. */ const char* file_info_get_utf8_print_path(struct file_info* info) { if(info->utf8_print_path == NULL) { if(is_utf8()) return info->print_path; info->utf8_print_path = to_utf8(info->print_path); } return info->utf8_print_path; }
void EnchantChecker::accept(WordLangTuple const & word) { enchant::Dict * m = d->speller(word.lang()->code()); if (m) { m->add_to_session(to_utf8(word.word())); advanceChangeNumber(); } }
void EnchantChecker::remove(WordLangTuple const & word) { enchant::Dict * m = d->speller(word.lang()->code()); if (m) { m->remove(to_utf8(word.word())); advanceChangeNumber(); } }
std::string CPPCMS_API to_utf8(std::locale const &loc,std::string const &str) { locale::info const &inf = std::use_facet<locale::info>(loc); if(inf.utf8()) return str; else return to_utf8(inf.encoding().c_str(),str); }
bool ssh_authenticate(void *sshclient, void *ht_username, void *ht_password) { /* Since both the strings we get are HeavyThing strings, we can convert them to std::string's first. */ char *userbuf = (char *)malloc(string$utf8_length(ht_username)+1); userbuf[string$to_utf8(ht_username, userbuf)] = 0; char *passbuf = (char *)malloc(string$utf8_length(ht_password)+1); passbuf[string$to_utf8(ht_password, passbuf)] = 0; std::string user(userbuf); std::string pass(passbuf); std::cout << "Authenticating User: [" << user << "] Pass: [" << pass << "]" << std::endl; return true; }