本文整理汇总了C++中ToUTF8函数的典型用法代码示例。如果您正苦于以下问题:C++ ToUTF8函数的具体用法?C++ ToUTF8怎么用?C++ ToUTF8使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ToUTF8函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SHGetFolderPathW
SString SharedUtil::GetSystemSystemPath ( void )
{
wchar_t szResult[MAX_PATH] = L"";
SHGetFolderPathW( NULL, CSIDL_SYSTEM, NULL, 0, szResult );
if ( IsShortPathName( szResult ) )
return GetSystemLongPathName( ToUTF8( szResult ) );
return ToUTF8( szResult );
}
示例2: GetDllDirectoryW
SString SharedUtil::GetSystemDllDirectory ( void )
{
wchar_t szResult [ 1024 ] = L"";
GetDllDirectoryW ( NUMELMS ( szResult ), szResult );
if ( IsShortPathName( szResult ) )
return GetSystemLongPathName( ToUTF8( szResult ) );
return ToUTF8( szResult );
}
示例3: GetTempPathW
SString SharedUtil::GetSystemTempPath ( void )
{
wchar_t szResult[4030] = L"";
GetTempPathW( 4000, szResult );
if ( IsShortPathName( szResult ) )
return GetSystemLongPathName( ToUTF8( szResult ) );
return ToUTF8( szResult );
}
示例4: sizeof
void
CExampleDlg::OnBnClickedConnectButton()
{
WCHAR awcTempBuf[100];
const int kTempBufSize = sizeof(awcTempBuf) / sizeof(awcTempBuf[0]);
// Pull user input into our member variables
UpdateData(TRUE);
// Clear out the results list, in case this isn't the first time
// we've come in here.
ResultsList.ResetContent();
// Translate the Unicode text we get from the UI into the UTF-8 form
// that MySQL wants.
const int kInputBufSize = 100;
char acServerAddress[kInputBufSize];
char acUserName[kInputBufSize];
char acPassword[kInputBufSize];
ToUTF8(acServerAddress, kInputBufSize, sServerAddress);
ToUTF8(acUserName, kInputBufSize, sUserName);
ToUTF8(acPassword, kInputBufSize, sPassword);
// Connect to the sample database.
mysqlpp::Connection con(false);
if (!con.connect("mysql_cpp_data", acServerAddress, acUserName,
acPassword)) {
AddMessage(_T("Failed to connect to server:"));
if (ToUCS2(awcTempBuf, kTempBufSize, con.error())) {
AddMessage(awcTempBuf);
}
return;
}
// Retrieve a subset of the sample stock table set up by resetdb
mysqlpp::Query query = con.query();
query << "select item from stock";
mysqlpp::StoreQueryResult res = query.store();
if (res) {
// Display the result set
for (size_t i = 0; i < res.num_rows(); ++i) {
if (ToUCS2(awcTempBuf, kTempBufSize, res[i][0])) {
AddMessage(awcTempBuf);
}
}
// Retreive was successful, so save user inputs now
SaveInputs();
}
else {
// Retreive failed
AddMessage(_T("Failed to get item list:"));
if (ToUCS2(awcTempBuf, kTempBufSize, query.error())) {
AddMessage(awcTempBuf);
}
}
}
示例5: GetTempFilePath
EPUB3_BEGIN_NAMESPACE
static string GetTempFilePath(const string& ext)
{
#if EPUB_PLATFORM(WIN)
TCHAR tmpPath[MAX_PATH];
TCHAR tmpFile[MAX_PATH];
DWORD pathLen = ::GetTempPath(MAX_PATH, tmpPath);
if ( pathLen == 0 || pathLen > MAX_PATH )
throw std::system_error(static_cast<int>(::GetLastError()), std::system_category());
UINT fileLen = ::GetTempFileName(tmpPath, TEXT("ZIP"), 0, tmpFile);
if ( fileLen == 0 )
throw std::system_error(static_cast<int>(::GetLastError()), std::system_category());
string r(tmpFile);
return r;
#elif EPUB_PLATFORM(WINRT)
using ToUTF8 = std::wstring_convert<std::codecvt_utf8<wchar_t>>;
auto tempFolder = ::Windows::Storage::ApplicationData::Current->TemporaryFolder;
std::wstring tempFolderPath(tempFolder->Path->Data(), tempFolder->Path->Length());
std::wstringstream ss;
ss << tempFolderPath;
ss << TEXT("\\epub3.");
ss << Windows::Security::Cryptography::CryptographicBuffer::GenerateRandomNumber();
ss << TEXT(".");
ss << ToUTF8().from_bytes(ext.stl_str());
return ToUTF8().to_bytes(ss.str());
#else
std::stringstream ss;
#if EPUB_OS(ANDROID)
ss << gAndroidCacheDir << "epub3.XXXXXX";
#else
ss << "/tmp/epub3.XXXXXX." << ext;
#endif
string path(ss.str());
char *buf = new char[path.length()];
std::char_traits<char>::copy(buf, ss.str().c_str(), sizeof(buf));
#if EPUB_OS(ANDROID)
int fd = ::mkstemp(buf);
#else
int fd = ::mkstemps(buf, static_cast<int>(ext.size()+1));
#endif
if ( fd == -1 )
throw std::runtime_error(std::string("mkstemp() failed: ") + strerror(errno));
::close(fd);
return string(buf);
#endif
}
示例6: mValues
RESULT cConnection::PostRequest(const std::string& sRelativeURI, const string_t& sUserName, const string_t& sPassword, const std::map<std::string, std::string>& _mValues)
{
std::map<std::string, std::string> mValues(_mValues);
mValues["version"] = "1";
mValues["user"] = ToUTF8(sUserName);
mValues["pass"] = ToUTF8(sPassword);
return _PostRequest(sRelativeURI, mValues);
}
示例7: GetModuleFileNameW
// C:\Program Files\gta_sa.exe
SString SharedUtil::GetLaunchPathFilename( void )
{
static SString strLaunchPathFilename;
if ( strLaunchPathFilename.empty() )
{
wchar_t szBuffer[2048];
GetModuleFileNameW( NULL, szBuffer, NUMELMS(szBuffer) - 1 );
if ( IsShortPathName( szBuffer ) )
return GetSystemLongPathName( ToUTF8( szBuffer ) );
strLaunchPathFilename = ToUTF8( szBuffer );
}
return strLaunchPathFilename;
}
示例8: GetCurrentDirectoryW
SString SharedUtil::GetSystemCurrentDirectory ( void )
{
#ifdef WIN32
wchar_t szResult [ 1024 ] = L"";
GetCurrentDirectoryW ( NUMELMS ( szResult ), szResult );
if ( IsShortPathName( szResult ) )
return GetSystemLongPathName( ToUTF8( szResult ) );
return ToUTF8( szResult );
#else
char szBuffer[ MAX_PATH ];
getcwd ( szBuffer, MAX_PATH - 1 );
return szBuffer;
#endif
}
示例9: assert
RESULT cConnection::WatchingMovie(const string_t& sTitle, const cDuration& durationThroughMovie, const cDuration& durationOfMovie)
{
assert(IsOpen());
std::map<std::string, std::string> mValues;
mValues["action"] = "watching";
mValues["title"] = ToUTF8(sTitle);
mValues["position_seconds"] = ToUTF8(durationThroughMovie);
mValues["length_seconds"] = ToUTF8(durationOfMovie);
RESULT result = PostRequest("submit.php", sUserName, sPassword, mValues);
return result;
}
示例10: NS_UnescapeURL
NS_IMETHODIMP
nsUTF8ConverterService::ConvertURISpecToUTF8(const nsACString &aSpec,
const char *aCharset,
nsACString &aUTF8Spec)
{
// assume UTF-8 if the spec contains unescaped non-ASCII characters.
// No valid spec in Mozilla would break this assumption.
if (!IsASCII(aSpec)) {
aUTF8Spec = aSpec;
return NS_OK;
}
aUTF8Spec.Truncate();
nsAutoCString unescapedSpec;
// NS_UnescapeURL does not fill up unescapedSpec unless there's at least
// one character to unescape.
bool written = NS_UnescapeURL(PromiseFlatCString(aSpec).get(), aSpec.Length(),
esc_OnlyNonASCII, unescapedSpec);
if (!written) {
aUTF8Spec = aSpec;
return NS_OK;
}
// return if ASCII only or escaped UTF-8
if (IsASCII(unescapedSpec) || IsUTF8(unescapedSpec)) {
aUTF8Spec = unescapedSpec;
return NS_OK;
}
return ToUTF8(unescapedSpec, aCharset, true, aUTF8Spec);
}
示例11: SendMessage
wstring MediaPlayers::GetTitleFromWinampAPI(HWND hwnd, bool use_unicode) {
if (IsWindow(hwnd)) {
if (SendMessage(hwnd, WM_USER, 0, IPC_ISPLAYING)) {
int list_index = SendMessage(hwnd, WM_USER, 0, IPC_GETLISTPOS);
int base_address = SendMessage(hwnd, WM_USER, list_index,
use_unicode ? IPC_GETPLAYLISTFILEW : IPC_GETPLAYLISTFILE);
if (base_address) {
DWORD process_id;
GetWindowThreadProcessId(hwnd, &process_id);
HANDLE hwnd_winamp = OpenProcess(PROCESS_VM_READ, FALSE, process_id);
if (hwnd_winamp) {
if (use_unicode) {
wchar_t file_name[MAX_PATH];
ReadProcessMemory(hwnd_winamp, reinterpret_cast<LPCVOID>(base_address),
file_name, MAX_PATH, NULL);
CloseHandle(hwnd_winamp);
return file_name;
} else {
char file_name[MAX_PATH];
ReadProcessMemory(hwnd_winamp, reinterpret_cast<LPCVOID>(base_address),
file_name, MAX_PATH, NULL);
CloseHandle(hwnd_winamp);
return ToUTF8(file_name);
}
}
}
}
}
return L"";
}
示例12: while
bool CLocalizeStrings::LoadXML(const CStdString &filename, CStdString &encoding, uint32_t offset /* = 0 */)
{
TiXmlDocument xmlDoc;
if (!xmlDoc.LoadFile(CSpecialProtocol::TranslatePathConvertCase(filename)))
{
CLog::Log(LOGDEBUG, "unable to load %s: %s at line %d", filename.c_str(), xmlDoc.ErrorDesc(), xmlDoc.ErrorRow());
return false;
}
XMLUtils::GetEncoding(&xmlDoc, encoding);
TiXmlElement* pRootElement = xmlDoc.RootElement();
if (!pRootElement || pRootElement->NoChildren() ||
pRootElement->ValueStr()!=CStdString("strings"))
{
CLog::Log(LOGERROR, "%s Doesn't contain <strings>", filename.c_str());
return false;
}
const TiXmlElement *pChild = pRootElement->FirstChildElement("string");
while (pChild)
{
// Load new style language file with id as attribute
const char* attrId=pChild->Attribute("id");
if (attrId && !pChild->NoChildren())
{
int id = atoi(attrId) + offset;
if (m_strings.find(id) == m_strings.end())
m_strings[id] = ToUTF8(encoding, pChild->FirstChild()->Value());
}
pChild = pChild->NextSiblingElement("string");
}
return true;
}
示例13: ToUTF8
/*---------------------------------------------------------------------------*/
wxString wxSQLBook::GetSQLStatementAt(long start, long& end)
{
wxString Str, temp;
bool first = true;
long count = m_SQLEdit->GetLineCount();
end = -1;
for (long i = start; i < count; i++)
{
if (!first)
Str += ("\n");
else
first = false;
temp = m_SQLEdit->GetLine(i).Trim();
if ((temp.Last() == (';')) && !m_SQLEdit->EndLineIsComment(i)) // Arrêt au point virgule de fin de commande
// if (temp.IsEmpty()) // Arrêt à la première ligne vide
{
end = i;
Str += temp;
break;
}
Str += temp;
}
return ToUTF8(Str);
}
示例14: WriteStrLine
// we write str lines into the file
void WriteStrLine(std::string prefix, std::string linkedString, std::string encoding)
{
linkedString = ToUTF8(encoding, linkedString);
fprintf (pPOTFile, "%s", prefix.c_str());
fprintf (pPOTFile, "\"%s\"\n", linkedString.c_str());
return;
}
示例15: GetLongPathNameW
SString SharedUtil::GetSystemLongPathName( const SString& strPath )
{
wchar_t szBuffer[32000];
szBuffer[0] = 0;
GetLongPathNameW( FromUTF8( strPath ), szBuffer, NUMELMS( szBuffer ) - 1 );
return ToUTF8( szBuffer );
}