STDMETHODIMP CKhParser::Init(int cSafeArr, BSTR www, BSTR dictPath, BSTR notfoundPath, long* hRes ) { Terminate( hRes ); dict = std::wstring(dictPath); notfound = std::wstring(notfoundPath); //"http://khakas.altaica.ru" request = www + request; safeArraySize = cSafeArr; *hRes = pIXMLHTTPRequest.CreateInstance("Msxml2.ServerXMLHTTP"); repl.insert(std::pair<short, short>(L'a', 0x0430)); repl.insert(std::pair<short, short>(L'c', 0x0441)); repl.insert(std::pair<short, short>(L'e', 0x0435)); repl.insert(std::pair<short, short>(L'i', 0x0456)); repl.insert(std::pair<short, short>(L'o', 0x043E)); repl.insert(std::pair<short, short>(L'p', 0x0440)); repl.insert(std::pair<short, short>(L'x', 0x0445)); repl.insert(std::pair<short, short>(L'y', 0x0443)); repl.insert(std::pair<short, short>(0xF6, 0x04E7)); repl.insert(std::pair<short, short>(0xFF, 0x04F1)); repl.insert(std::pair<short, short>(0x04B7, 0x04CC)); char locale_name[32] = ""; locale_name[0] = '.'; _ui64toa_s(1251, locale_name + 1, sizeof(locale_name) - 1, 10); locinfo = _create_locale(LC_ALL, locale_name); return *hRes; }
void wxXLocale::Init(const char *loc) { if (!loc || *loc == '\0') return; m_locale = _create_locale(LC_ALL, loc); }
void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time) { if (hContact && arMonitoredWindows.getIndex((HANDLE)hContact) != -1) { StatusIconData sid = { sizeof(sid) }; sid.szModule = MODULENAME; sid.dwId = 1; sid.flags = MBF_TCHAR; switch (type) { case ICON_HIDDEN: { sid.flags |= MBF_HIDDEN; break; } case ICON_READ: { sid.hIcon = IcoLib_GetIcon("read_icon"); CMString tooltip; if (db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME_TYPE, -1) == MRD_TYPE_READTIME) { TCHAR ttime[64]; _locale_t locale = _create_locale(LC_ALL, ""); _tcsftime_l(ttime, _countof(ttime), _T("%X %x"), localtime(&time), locale); _free_locale(locale); tooltip.Format(L"%s %s", TranslateT("Last message read at"), ttime); } else { tooltip = TranslateT("Last message read (unknown time)"); } sid.tszTooltip = tooltip.Detach(); break; } case ICON_UNREAD: { sid.hIcon = IcoLib_GetIcon("unread_icon"); sid.tszTooltip = TranslateT("Last message is not read"); break; } case ICON_FAILED: { sid.hIcon = IcoLib_GetIcon("fail_icon"); sid.tszTooltip = TranslateT("Last message was not sent."); break; } case ICON_NOSENT: { sid.hIcon = IcoLib_GetIcon("nosent_icon"); sid.tszTooltip = TranslateT("Sending..."); break; } default: return; } Srmm_ModifyIcon(hContact, &sid); } }
// find sorted position after the last separator int FindSortedPos(HMENU hMenu, const char* text) { int pos = -1, nbItems = GetMenuItemCount(hMenu); #ifdef _WIN32 wchar_t widetext[4096], widebuf[4096]; MultiByteToWideChar(CP_UTF8, 0, text, -1, widetext, 4096); _locale_t locale = _create_locale(LC_ALL, ""); #else char buf[4096] = ""; #endif MENUITEMINFO mi = {sizeof(MENUITEMINFO),}; mi.fMask = MIIM_TYPE; for (int i=nbItems-1; i>=0 ; i--) { GetMenuItemInfo(hMenu, i, true, &mi); if (mi.fType == MFT_SEPARATOR) break; #ifdef _WIN32 GetMenuStringW(hMenu, i, widebuf, 4096, MF_BYPOSITION); if (_wcsnicoll_l(widetext, widebuf, 4096, locale) < 0) // setLocale() can break things (atof and comma as a decimal mark) so use temporary locale object pos = i; #else GetMenuString(hMenu, i, buf, sizeof(buf), MF_BYPOSITION); if (strcasecmp(text, buf) < 0) // not as good as on Win OS, e.g. French "Sélectionner" vs "Supprimer" pos = i; #endif } #ifdef _WIN32 _free_locale(locale); #endif return pos<0 ? nbItems : pos; }
wstring s2ws(const string &s,const char *locale /*= ""*/) { assert(locale); wstring result; _locale_t loc = _create_locale(LC_CTYPE,locale); //使用指定的locale。 //如果_create_locale返回空,返回空字符串。 if(!loc) { return result; } const size_t len = s.size()+1; wchar_t *dest = new wchar_t[len]; size_t numOfCharConverted = 0; errno_t err = _mbstowcs_s_l(&numOfCharConverted,dest,len,s.c_str(),_TRUNCATE,loc); _free_locale(loc); if(err == 0) { result = dest; } else if(err == STRUNCATE) { assert(!"dest buffer should be adequate"); result = dest; } else { //转换失败。 } delete []dest; return result; }
string ws2s(const wstring &ws,const char *locale /*= ""*/) { string result; _locale_t loc = _create_locale(LC_CTYPE,locale); if(!loc) { return result; } const size_t len = ws.size()*4+1; char *dest = new char[len]; size_t numOfCharConverted = 0; errno_t err = _wcstombs_s_l(&numOfCharConverted,dest,len,ws.c_str(),_TRUNCATE,loc); _free_locale(loc); if(err == 0) { result = dest; } else if(err == STRUNCATE) { OutputDebugStringA("UniCore ws2s 目标缓冲区不足,字符串被截断。"); result = dest; } else { OutputDebugStringA("UniCore ws2s 转换Unicode字符串到MBCS字符串时失败。"); } delete []dest; return result; }
/* * On Windows, use CP<code page number> instead of the nl_langinfo() result * * Visual Studio 2012 expanded the set of valid LC_CTYPE values, so have its * locale machinery determine the code page. See comments at IsoLocaleName(). * For other compilers, follow the locale's predictable format. * * Visual Studio 2015 should still be able to do the same, but the declaration * of lc_codepage is missing in _locale_t, causing this code compilation to * fail, hence this falls back instead on GetLocaleInfoEx. VS 2015 may be an * exception and post-VS2015 versions should be able to handle properly the * codepage number using _create_locale(). So, instead of the same logic as * VS 2012 and VS 2013, this routine uses GetLocaleInfoEx to parse short * locale names like "de-DE", "fr-FR", etc. If those cannot be parsed correctly * process falls back to the pre-VS-2010 manual parsing done with * using <Language>_<Country>.<CodePage> as a base. * * Returns a malloc()'d string for the caller to free. */ static char * win32_langinfo(const char *ctype) { char *r = NULL; #if (_MSC_VER >= 1700) && (_MSC_VER < 1900) _locale_t loct = NULL; loct = _create_locale(LC_CTYPE, ctype); if (loct != NULL) { r = malloc(16); /* excess */ if (r != NULL) sprintf(r, "CP%u", loct->locinfo->lc_codepage); _free_locale(loct); } #else char *codepage; #if (_MSC_VER >= 1900) uint32 cp; WCHAR wctype[LOCALE_NAME_MAX_LENGTH]; memset(wctype, 0, sizeof(wctype)); MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, LOCALE_NAME_MAX_LENGTH); if (GetLocaleInfoEx(wctype, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER, (LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0) { r = malloc(16); /* excess */ if (r != NULL) sprintf(r, "CP%u", cp); } else #endif { /* * Locale format on Win32 is <Language>_<Country>.<CodePage> . For * example, English_United States.1252. */ codepage = strrchr(ctype, '.'); if (codepage != NULL) { int ln; codepage++; ln = strlen(codepage); r = malloc(ln + 3); if (r != NULL) sprintf(r, "CP%s", codepage); } } #endif return r; }
// Returns false only if parsing should be aborted. bool consume_value(value_t &val, const char** str) { assert(str); const char *c = *str; // Double / float if(*c == '+' || *c == '-') { if(!lc_neutral) { lc_neutral = _create_locale(LC_NUMERIC, "C"); } char *endptr; errno = 0; double result = _strtod_l(*str, &endptr, lc_neutral); if(errno == ERANGE && (result == HUGE_VAL || result == -HUGE_VAL)) { auto val_len = (endptr - *str); log_printf( "ERROR: Floating point constant \"%.*s\" out of range!\n", val_len, str ); return false; } else if(endptr == *str) { // Not actually a floating-point number, keep going though *str += 1; return true; } if(*endptr == 'f') { val.type = VT_FLOAT; val.f = (float)result; endptr++; } else { val.type = VT_DOUBLE; val.d = result; } if(*endptr != ' ' && *endptr != '\0') { val.type = VT_NONE; *str += 1; } else { *str = endptr; } } // Byte else if(is_valid_hex(c[0]) && is_valid_hex(c[1])) { char conv[3]; conv[2] = 0; memcpy(conv, *str, 2); val.type = VT_BYTE; val.b = (unsigned char)strtol(conv, nullptr, 16); *str += 2; } // Nothing, keep going else { *str += 1; } return true; }
/** * Create a locale object from the given locale string. * @param locale Locale string, in the native OS format. * @return Locale object for the given locale * Note: It has to be freed by freelocale(). */ locale_t newlocale_LC_CTYPE(const char *locale) { locale_t locobj; #ifdef _WIN32 locobj = _create_locale(LC_CTYPE, locale); #else locobj = newlocale(LC_CTYPE_MASK, locale, (locale_t)0); #endif /* _WIN32 */ return locobj; }
// C Locale initialization func static void U_CALLCONV initCLocale(void) { ucln_i18n_registerCleanup(UCLN_I18N_DIGITLIST, digitList_cleanup); #if U_USE_STRTOD_L # if U_PLATFORM_USES_ONLY_WIN32_API gCLocale = _create_locale(LC_ALL, "C"); # else gCLocale = newlocale(LC_ALL_MASK, "C", (locale_t)0); # endif #endif }
JSonScanner::JSonScanner(QIODevice* io) : m_allowSpecialNumbers(false), m_io (io), m_criticalError(false) { #ifdef Q_OS_WIN m_C_locale = _create_locale(LC_NUMERIC, "C"); #else m_C_locale = newlocale(LC_NUMERIC_MASK, "C", NULL); #endif }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + A c q u i r e C L o c a l e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireCLocale() allocates the C locale object, or (locale_t) 0 with % errno set if it cannot be acquired. % % The format of the AcquireCLocale method is: % % locale_t AcquireCLocale(void) % */ static locale_t AcquireCLocale(void) { #if defined(MAGICKCORE_HAVE_NEWLOCALE) if (c_locale == (locale_t) NULL) c_locale=newlocale(LC_ALL_MASK,"C",(locale_t) 0); #elif defined(MAGICKCORE_WINDOWS_SUPPORT) if (c_locale == (locale_t) NULL) c_locale=_create_locale(LC_ALL,"C"); #endif return(c_locale); }
int UTF8::FromUnicode(const wchar_t *wstr, int wlen, char *str, int *len) { #if defined(WIN32) || defined(_WINDOWS_) wlen = WideCharToMultiByte(CP_UTF8, 0, wstr, wlen, str, wlen * 4, NULL, NULL); #else if (!m_UTF8_locale) m_UTF8_locale = _create_locale(LC_ALL, "en_US.UTF-8"); wlen = wcstombs_l(str, wstr, wlen, m_UTF8_locale); #endif if (len != NULL) *len = wlen; return (errno = 0); }
bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args) { int writtenCount; #ifdef _WIN32 // You would think *printf are simple, right? Iterate on each character, // if it's a format specifier handle it properly, etc. // // Nooooo. Not according to the C standard. // // According to the C99 standard (7.19.6.1 "The fprintf function") // The format shall be a multibyte character sequence // // Because some character encodings might have '%' signs in the middle of // a multibyte sequence (SJIS for example only specifies that the first // byte of a 2 byte sequence is "high", the second byte can be anything), // printf functions have to decode the multibyte sequences and try their // best to not screw up. // // Unfortunately, on Windows, the locale for most languages is not UTF-8 // as we would need. Notably, for zh_TW, Windows chooses EUC-CN as the // locale, and completely fails when trying to decode UTF-8 as EUC-CN. // // On the other hand, the fix is simple: because we use UTF-8, no such // multibyte handling is required as we can simply assume that no '%' char // will be present in the middle of a multibyte sequence. // // This is why we look up the default C locale here and use _vsnprintf_l. static _locale_t c_locale = nullptr; if (!c_locale) c_locale = _create_locale(LC_ALL, "C"); writtenCount = _vsnprintf_l(out, outsize, format, c_locale, args); #else #if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) locale_t previousLocale = uselocale(GetCLocale()); #endif writtenCount = vsnprintf(out, outsize, format, args); #if !defined(ANDROID) && !defined(__HAIKU__) && !defined(__OpenBSD__) uselocale(previousLocale); #endif #endif if (writtenCount > 0 && writtenCount < outsize) { out[writtenCount] = '\0'; return true; } else { out[outsize - 1] = '\0'; return false; } }
int UTF8::ToUnicode(const char *utf8_data, int len, wchar_t *wstr, int *wlen) { #if defined(WIN32) || defined(_WINDOWS_) len = MultiByteToWideChar(CP_UTF8, 0, utf8_data, len, wstr, len * 4); #else if (!m_UTF8_locale) m_UTF8_locale = _create_locale(LC_ALL, "en_US.UTF-8"); len = mbstowcs_l(wstr, utf8_data, len, m_UTF8_locale); #endif if (wlen != NULL) *wlen = len; return (errno = 0); }
ScCLocale::ScCLocale() :qLocale(QLocale::C) { qLocale.setNumberOptions(QLocale::OmitGroupSeparator); #if defined(Q_WS_WIN) cLocale = _create_locale(LC_ALL, "C"); #else #if not defined(Q_OS_SOLARIS) and not defined(Q_OS_OPENBSD) and not defined (Q_OS_FREEBSD) cLocale = newlocale(LC_ALL_MASK, "C", NULL); #endif #endif }
inline double string_to_float(const std::wstring& s) { static _locale_t locale = _create_locale(LC_NUMERIC, "C"); const wchar_t* begin = &s[0]; wchar_t* end = const_cast<wchar_t*>(begin)+s.size(); double val = _wcstod_l(begin,&end,locale); if (begin == end) { throw std::invalid_argument("Invalid float value"); } return val; }
std::wstring UIniConfig::formatKey( std::wstring &key, va_list ap ) { //该函数返回格式化后的字符串长度,不包括0结束符。 _locale_t loc = _create_locale(LC_ALL,""); const int len = _vscwprintf_p_l(key.c_str(),loc,ap)+1; wchar_t *buffer = new wchar_t[len]; _vswprintf_p_l(buffer,len,key.c_str(),loc,ap); _free_locale(loc); wstring result = buffer; delete[] buffer; return result; }
static locale_t get_C_LC_NUMERIC(void) { static locale_t locobj; if ((locale_t)0 != locobj) return locobj; #ifdef _WIN32 locobj = _create_locale(LC_NUMERIC, "C"); #else locobj = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); #endif /* _WIN32 */ atexit(free_C_LC_NUMERIC); return locobj; }
double wstrtod(const char *nptr, char **eptr) { double d; char *leptr; #if 0 if (clocale == NULL) clocale = _create_locale(LC_ALL, "C"); #endif d = _strtod_l(nptr, &leptr, clocale); /* if 0, check if input was inf */ if (d == 0 && nptr == leptr) { int neg = 0; while (isspace(*nptr)) nptr++; if (*nptr == '+') nptr++; else if (*nptr == '-') { nptr++; neg = 1; } if (strnicmp("INF", nptr, 3) == 0) { if (eptr != NULL) { if (strnicmp("INFINITE", nptr, 8) == 0) *eptr = (char*)(nptr + 8); else *eptr = (char*)(nptr + 3); } if (neg == 1) return -HUGE_VAL; else return HUGE_VAL; } else if (strnicmp("NAN", nptr, 3) == 0) { if (eptr != NULL) *eptr = (char*)(nptr + 3); /* create a NaN : 0 * infinity*/ d = HUGE_VAL; return d * 0; } } if (eptr != NULL) *eptr = leptr; return d; }
bool GetValue(const std::string& sMessage, double& dval) { std::string svalue = ExtractValue(sMessage); printf("GetValue(\"%s\", double)\n", sMessage.c_str()); #ifdef WIN32 _locale_t loc = _create_locale(LC_ALL, "eng"); char point = '.'; #else std::locale loc(""); char point = std::use_facet<std::numpunct<char> >(loc).decimal_point(); #endif for(size_t p=0; p<svalue.length(); p++) { if (svalue[p] == '.' || svalue[p] == ',') svalue[p] = point; } char *pend; const char* szValue = svalue.c_str(); #ifdef WIN32 double dValue =_strtod_l(szValue, &pend, loc); #else double dValue = strtod(szValue, &pend); #endif // return true only if scan was stopped by spaces, linefeed or the terminating NUL and if the // string was not empty to start with if (pend != szValue) { while( *pend!='\0' && (*pend==' '||*pend=='\n')) pend++; if (*pend=='\0') { dval = dValue; return true; } } return false; }
/* * Convert Windows locale name to the ISO formatted one * if possible. * * This function returns NULL if conversion is impossible, * otherwise returns the pointer to a static area which * contains the iso formatted locale name. */ static char * IsoLocaleName(const char *winlocname) { #if (_MSC_VER >= 1400) /* VC8.0 or later */ static char iso_lc_messages[32]; _locale_t loct = NULL; if (pg_strcasecmp("c", winlocname) == 0 || pg_strcasecmp("posix", winlocname) == 0) { strcpy(iso_lc_messages, "C"); return iso_lc_messages; } loct = _create_locale(LC_CTYPE, winlocname); if (loct != NULL) { char isolang[32], isocrty[32]; LCID lcid; lcid = loct->locinfo->lc_handle[LC_CTYPE]; if (lcid == 0) lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT); _free_locale(loct); if (!GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, isolang, sizeof(isolang))) return NULL; if (!GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, isocrty, sizeof(isocrty))) return NULL; snprintf(iso_lc_messages, sizeof(iso_lc_messages) - 1, "%s_%s", isolang, isocrty); return iso_lc_messages; } return NULL; #else return NULL; /* Not supported on this version of msvc/mingw */ #endif /* _MSC_VER >= 1400 */ }
/* * On Windows, use CP<code page number> instead of the nl_langinfo() result * * Visual Studio 2012 expanded the set of valid LC_CTYPE values, so have its * locale machinery determine the code page. See comments at IsoLocaleName(). * For other compilers, follow the locale's predictable format. * * Returns a malloc()'d string for the caller to free. */ static char * win32_langinfo(const char *ctype) { char *r = NULL; #if (_MSC_VER >= 1700) _locale_t loct = NULL; loct = _create_locale(LC_CTYPE, ctype); if (loct != NULL) { r = malloc(16); /* excess */ if (r != NULL) sprintf(r, "CP%u", loct->locinfo->lc_codepage); _free_locale(loct); } #else char *codepage; /* * Locale format on Win32 is <Language>_<Country>.<CodePage> . For * example, English_United States.1252. */ codepage = strrchr(ctype, '.'); if (codepage != NULL) { int ln; codepage++; ln = strlen(codepage); r = malloc(ln + 3); if (r != NULL) sprintf(r, "CP%s", codepage); } #endif return r; }
void LCD_UpdateThread(void* Control) { CMPC_Lcd* ctrl = static_cast<CMPC_Lcd*>(Control); wchar_t str[40]; __time64_t ltime; __time64_t otime = 0; struct tm thetime; _locale_t locale = _create_locale(LC_TIME, ""); while (ctrl->Thread_Loop) { EnterCriticalSection(&ctrl->cs); if (_time64(<ime) != otime) { // Retrieve the time otime = ltime; _localtime64_s(&thetime, <ime); // Format the current time structure into a string // using %#x is the long date representation, // appropriate to the current locale if (_wcsftime_l(str, _countof(str), _T("%#x"), (const struct tm*)&thetime, locale) && (ltime > ctrl->nThread_tTimeout || ltime < otime)) { // message displayed, no update until timeout ctrl->m_MonoPage.m_Text[0].SetText(str); ctrl->m_ColorPage.m_Text[0].SetText(str); } if (_wcsftime_l(str, _countof(str), _T("%X"), (const struct tm*)&thetime, locale)) { ctrl->m_MonoPage.m_Text[1].SetText(str); ctrl->m_ColorPage.m_Text[1].SetText(str); } } ctrl->m_Connection.Update(); LeaveCriticalSection(&ctrl->cs); Sleep(LCD_UPD_TIMER); } _free_locale(locale); _endthread(); }
/* * Convert a Windows setlocale() argument to a Unix-style one. * * Regardless of platform, we install message catalogs under a Unix-style * LL[_CC][.ENCODING][@VARIANT] naming convention. Only LC_MESSAGES settings * following that style will elicit localized interface strings. * * Before Visual Studio 2012 (msvcr110.dll), Windows setlocale() accepted "C" * (but not "c") and strings of the form <Language>[_<Country>][.<CodePage>], * case-insensitive. setlocale() returns the fully-qualified form; for * example, setlocale("thaI") returns "Thai_Thailand.874". Internally, * setlocale() and _create_locale() select a "locale identifier"[1] and store * it in an undocumented _locale_t field. From that LCID, we can retrieve the * ISO 639 language and the ISO 3166 country. Character encoding does not * matter, because the server and client encodings govern that. * * Windows Vista introduced the "locale name" concept[2], closely following * RFC 4646. Locale identifiers are now deprecated. Starting with Visual * Studio 2012, setlocale() accepts locale names in addition to the strings it * accepted historically. It does not standardize them; setlocale("Th-tH") * returns "Th-tH". setlocale(category, "") still returns a traditional * string. Furthermore, msvcr110.dll changed the undocumented _locale_t * content to carry locale names instead of locale identifiers. * * MinGW headers declare _create_locale(), but msvcrt.dll lacks that symbol. * IsoLocaleName() always fails in a MinGW-built postgres.exe, so only * Unix-style values of the lc_messages GUC can elicit localized messages. In * particular, every lc_messages setting that initdb can select automatically * will yield only C-locale messages. XXX This could be fixed by running the * fully-qualified locale name through a lookup table. * * This function returns a pointer to a static buffer bearing the converted * name or NULL if conversion fails. * * [1] http://msdn.microsoft.com/en-us/library/windows/desktop/dd373763.aspx * [2] http://msdn.microsoft.com/en-us/library/windows/desktop/dd373814.aspx */ static char * IsoLocaleName(const char *winlocname) { #if (_MSC_VER >= 1400) /* VC8.0 or later */ static char iso_lc_messages[32]; _locale_t loct = NULL; if (pg_strcasecmp("c", winlocname) == 0 || pg_strcasecmp("posix", winlocname) == 0) { strcpy(iso_lc_messages, "C"); return iso_lc_messages; } loct = _create_locale(LC_CTYPE, winlocname); if (loct != NULL) { #if (_MSC_VER >= 1700) /* Visual Studio 2012 or later */ size_t rc; char *hyphen; /* Locale names use only ASCII, any conversion locale suffices. */ rc = wchar2char(iso_lc_messages, loct->locinfo->locale_name[LC_CTYPE], sizeof(iso_lc_messages), NULL); _free_locale(loct); if (rc == -1 || rc == sizeof(iso_lc_messages)) return NULL; /* * Since the message catalogs sit on a case-insensitive filesystem, we * need not standardize letter case here. So long as we do not ship * message catalogs for which it would matter, we also need not * translate the script/variant portion, e.g. uz-Cyrl-UZ to * uz_UZ@cyrillic. Simply replace the hyphen with an underscore. * * Note that the locale name can be less-specific than the value we * would derive under earlier Visual Studio releases. For example, * French_France.1252 yields just "fr". This does not affect any of * the country-specific message catalogs available as of this writing * (pt_BR, zh_CN, zh_TW). */ hyphen = strchr(iso_lc_messages, '-'); if (hyphen) *hyphen = '_'; #else char isolang[32], isocrty[32]; LCID lcid; lcid = loct->locinfo->lc_handle[LC_CTYPE]; if (lcid == 0) lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT); _free_locale(loct); if (!GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, isolang, sizeof(isolang))) return NULL; if (!GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, isocrty, sizeof(isocrty))) return NULL; snprintf(iso_lc_messages, sizeof(iso_lc_messages) - 1, "%s_%s", isolang, isocrty); #endif return iso_lc_messages; } return NULL; #else return NULL; /* Not supported on this version of msvc/mingw */ #endif /* _MSC_VER >= 1400 */ }
/* * Create a locale_t from a collation OID. Results are cached for the * lifetime of the backend. Thus, do not free the result with freelocale(). * * As a special optimization, the default/database collation returns 0. * Callers should then revert to the non-locale_t-enabled code path. * In fact, they shouldn't call this function at all when they are dealing * with the default locale. That can save quite a bit in hotspots. * Also, callers should avoid calling this before going down a C/POSIX * fastpath, because such a fastpath should work even on platforms without * locale_t support in the C library. * * For simplicity, we always generate COLLATE + CTYPE even though we * might only need one of them. Since this is called only once per session, * it shouldn't cost much. */ pg_locale_t pg_newlocale_from_collation(Oid collid) { collation_cache_entry *cache_entry; /* Callers must pass a valid OID */ Assert(OidIsValid(collid)); /* Return 0 for "default" collation, just in case caller forgets */ if (collid == DEFAULT_COLLATION_OID) return (pg_locale_t) 0; cache_entry = lookup_collation_cache(collid, false); if (cache_entry->locale == 0) { /* We haven't computed this yet in this session, so do it */ #ifdef HAVE_LOCALE_T HeapTuple tp; Form_pg_collation collform; const char *collcollate; const char *collctype; locale_t result; tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(collid)); if (!HeapTupleIsValid(tp)) elog(ERROR, "cache lookup failed for collation %u", collid); collform = (Form_pg_collation) GETSTRUCT(tp); collcollate = NameStr(collform->collcollate); collctype = NameStr(collform->collctype); if (strcmp(collcollate, collctype) == 0) { /* Normal case where they're the same */ #ifndef WIN32 result = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK, collcollate, NULL); #else result = _create_locale(LC_ALL, collcollate); #endif if (!result) report_newlocale_failure(collcollate); } else { #ifndef WIN32 /* We need two newlocale() steps */ locale_t loc1; loc1 = newlocale(LC_COLLATE_MASK, collcollate, NULL); if (!loc1) report_newlocale_failure(collcollate); result = newlocale(LC_CTYPE_MASK, collctype, loc1); if (!result) report_newlocale_failure(collctype); #else /* * XXX The _create_locale() API doesn't appear to support this. * Could perhaps be worked around by changing pg_locale_t to * contain two separate fields. */ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("collations with different collate and ctype values are not supported on this platform"))); #endif } cache_entry->locale = result; ReleaseSysCache(tp); #else /* not HAVE_LOCALE_T */ /* * For platforms that don't support locale_t, we can't do anything * with non-default collations. */ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("nondefault collations are not supported on this platform"))); #endif /* not HAVE_LOCALE_T */ } return cache_entry->locale; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //agenttype_bitmap_notify //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void agenttype_bitmap_notify(agent *a, int notifytype, void *messagedata) { //Get the agent details agenttype_bitmap_details *details = (agenttype_bitmap_details *) a->agentdetails; styledrawinfo *di; int xpos, ypos; switch(notifytype) { case NOTIFY_DRAW: di = (styledrawinfo *) messagedata; if (details->is_icon) { HICON load_sysicon(char *filepath, int size); HICON hIcon = (HICON)LoadImage(plugin_instance_plugin, details->absolute_path, IMAGE_ICON, details->width, details->height, LR_LOADFROMFILE); // this one can retrieve the standard system icons also: if (NULL == hIcon) hIcon = load_sysicon(details->absolute_path, details->width); if (NULL != hIcon) { switch (details->halign) { case 0: xpos = ((di->rect.right - di->rect.left) / 2) - (details->width / 2); break; case 1: xpos = 2; break; case 2: xpos = (di->rect.right - 2) - (details->width); break; } switch (details->valign) { case 0: ypos = ((di->rect.bottom - di->rect.top) / 2) - (details->height / 2); break; case 1: ypos = 2; break; case 2: ypos = (di->rect.bottom - 2) - (details->height); break; } drawIcon (xpos, ypos, details->width, (HICON) hIcon, di->buffer, di->apply_sat_hue); //DrawIconEx(di->buffer, xpos, ypos, (HICON) hIcon, details->width, details->height, 0, NULL, DI_NORMAL); DestroyIcon(hIcon); } } else { WCHAR wTitle[256]; if(!locale) locale = _create_locale(LC_CTYPE,""); _mbstowcs_l(wTitle, details->absolute_path, strlen(details->absolute_path) + 1,locale); pImage = new Gdiplus::Image(wTitle); if (NULL != pImage) { details->width = pImage->GetWidth() * ((double)details->scale / 100); details->height = pImage->GetHeight() * ((double)details->scale / 100); switch (details->halign) { case 0: xpos = ((di->rect.right - di->rect.left) / 2) - (details->width / 2); break; case 1: xpos = 2; break; case 2: xpos = (di->rect.right - 2) - (details->width); break; } switch (details->valign) { case 0: ypos = ((di->rect.bottom - di->rect.top) / 2) - (details->height / 2); break; case 1: ypos = 2; break; case 2: ypos = (di->rect.bottom - 2) - (details->height); break; } imageAttr = new Gdiplus::ImageAttributes(); imageAttr->SetColorKey(RGB(255,0,255), RGB(255,0,255)); graphics = new Gdiplus::Graphics(di->buffer); graphics->DrawImage(pImage, Gdiplus::Rect(xpos, ypos, details->width, details->height), 0, 0, pImage->GetWidth(), pImage->GetHeight(), Gdiplus::UnitPixel, imageAttr, NULL, NULL); delete imageAttr; delete graphics; delete pImage; } } break; case NOTIFY_SAVE_AGENT: //Write existance config_write(config_get_control_setagent_c(a->controlptr, a->agentaction, a->agenttypeptr->agenttypename, details->filename)); //Save properties if (details->is_icon) config_write(config_get_control_setagentprop_i(a->controlptr, a->agentaction, "Size", &details->width)); else if (details->filename) config_write(config_get_control_setagentprop_i(a->controlptr, a->agentaction, "Scale", &details->scale)); config_write(config_get_control_setagentprop_c(a->controlptr, a->agentaction, "VAlign", image_valigns[details->valign])); config_write(config_get_control_setagentprop_c(a->controlptr, a->agentaction, "HAlign", image_haligns[details->halign])); break; } }
utility::string_t Base64::constructBase64HeaderValue(const wchar_t* appendToBegin = 0, const wchar_t* dataToConvert = 0) { if (dataToConvert == NULL) throw std::invalid_argument{ "Empty \"dataToConvert\" value of \"constructBase64HeaderValue\"" }; size_t mByteCounter; char *pMBBuffer = (char*)malloc(BUFFER_SIZE); if (pMBBuffer == NULL) throw std::bad_alloc(); // Convertin a sequence of wide characters to a corresponding sequence of multibyte characters for Unicode support _wcstombs_s_l(&mByteCounter, pMBBuffer, (size_t)BUFFER_SIZE, dataToConvert, (size_t)BUFFER_SIZE, _create_locale(LC_ALL, ".1251")); // Converting sequence of multibyte characters to vector of unsigned chars for using in conversions::to_base64 std::string pString{ pMBBuffer }; std::vector<unsigned char> vCred(mByteCounter - 1); std::transform(pString.begin(), pString.end(), vCred.begin(), [](wchar_t c) { return static_cast<wchar_t>(c); }); // Data prepared, converting it to base64 const auto b64cred{ conversions::to_base64(vCred) }; if (appendToBegin == 0) return b64cred; else { // If something needs to be added before: composign header "Authorization" value utility::string_t valBegin{ appendToBegin }; return valBegin.append(b64cred); } return 0; }
float_reader() { locale = _create_locale(LC_NUMERIC, "C"); }
void hpdf_doc::add_text(et_datachunk &dc) { et_type datatype = dc.type; wstring &out_string = dc.w_string; char *line = new char[4096]; memset(line, 0, 4096); _locale_t loceng; size_t size = 0; loceng = _create_locale(LC_ALL, "en-US"); int len = out_string.length(); // count of space int n_TX = (et_cp.TX > 0) ? et_cp.TX : et_cp.T, n_TY = (et_cp.TY > 0) ? et_cp.TY : et_cp.T; HPDF_REAL f_xpos = dc.rect.left, f_ypos = dc.rect.bottom; HPDF_REAL f_advance = 0.0; HPDF_REAL f_width = MMTEXT2PTX(et_cp.W * n_TX / 2); HPDF_REAL f_gap = MMTEXT2PTX(et_cp.X/2); HPDF_REAL f_space = MMTEXT2PTY((et_cp.Z * n_TY) + et_cp.L); HPDF_Page_BeginText(h_current_page); select_datatype_font(datatype); f_space = HPDF_Page_GetCurrentFontSize(h_current_page); if (f_space > f_linespace) f_linespace = f_space; switch (datatype) { case ET_LATAN: /* size = _wcstombs_l(line, out_string.c_str(), 4096, loceng); if (size == 0) goto END_PROC; HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line); f_advance = HPDF_Page_TextWidth(h_current_page, line); */ if (et_cp.CorE == 'C') f_width = f_width * 2; text_out_eng(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space, loceng); break; case ET_SPACE: f_advance += ((f_width + f_gap) * len); break; case ET_CJK: case ET_CJKFORM: case ET_BOXDRAW: if (et_cp.VorH == 'H' || datatype != ET_CJK) horizontal(f_xpos, f_ypos); else vertical(f_xpos, f_ypos); if (datatype == ET_BOXDRAW) resize_font_boxdraw(); /* size = wchar_to_utf8(out_string.c_str(), out_string.length(), line, 4096, NULL); if (size == 0) goto END_PROC; HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line); //if (datatype == ET_BOXDRAW) // f_advance += (len * ((f_width + f_gap) * 2)); //else f_advance += HPDF_Page_TextWidth(h_current_page, line); //(len * ((f_width + f_gap) * 2)); */ text_out_cjk(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space); break; } HPDF_Page_EndText(h_current_page); if (et_cp.U > 0) { HPDF_Page_SetLineWidth(h_current_page, 0.5); HPDF_Page_MoveTo(h_current_page, f_xpos, f_ypos - f_linespace); HPDF_Page_LineTo(h_current_page, f_xpos, f_ypos); HPDF_Page_Stroke(h_current_page); } f_xpos += f_advance; delete [] line; // free buffer _free_locale(loceng); }