Exemplo n.º 1
0
		mbs			getTextUTF8(const void* buffer, size_t size)
		{
			if(size >= 2)
				if(*(unsigned short*)buffer == UNICODE_BYTE_ORDER_MARK)
					return WCSTOMBS(wcs(((const wchar_t*)buffer) + 1, (size_t)((size - 2) >> 1)), CP_UTF8);
			return WCSTOMBS(MBSTOWCS(mbs((char*)buffer, (size_t)size)), CP_UTF8);
		}
Exemplo n.º 2
0
UINT __stdcall Module::ThreadProc(void* dllModPtr)
{
    Module* dllMod = (Module*)dllModPtr;

#if defined(MSVC_DEBUG)
    LPCTSTR pszFileName = PathFindFileName(dllMod->m_wzLocation.c_str());
    DbgSetCurrentThreadName(WCSTOMBS(pszFileName));
#endif

    dllMod->CallInit();

    // We must use a copy of our event, and hope no one has closed it before
    // waiting for it to be signaled.  See: TakeThread() member function.
    SetEvent(dllMod->m_hInitCopyEvent);

    MSG msg;

    while (GetMessage(&msg, 0, 0, 0) > 0)
    {
        if (msg.hwnd == NULL)
        {
            // Thread message
            HandleThreadMessage(msg);
        }
        else
        {
            // Window message
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return 0;
}
Exemplo n.º 3
0
/**
 * @brief sunpinyin called this function while commit the string
 *
 * @param str committed string
 * @return void
 **/
void FcitxWindowHandler::commit(const TWCHAR* str)
{
    FcitxInstance* instance = owner->owner;
    FcitxInputState* input = FcitxInstanceGetInputState(instance);
    char *buf_ = FcitxInputStateGetOutputString(input);
    memset(buf_, 0, MAX_USER_INPUT);
    WCSTOMBS(buf_, str, MAX_USER_INPUT);
    commit_flag = true;
    FcitxInputStateSetCursorPos(input, false);
}
Exemplo n.º 4
0
/**
 * @brief handler called while preedit updated
 *
 * @param ppd preedit string
 * @return void
 **/
void FcitxWindowHandler::updatePreedit(const IPreeditString* ppd)
{
    FcitxInstance* instance = owner->owner;
    FcitxInputState* input = FcitxInstanceGetInputState(instance);
    FcitxInputStateSetCursorPos(input, true);
    candidate_flag = true;

    const wstring& codeinput = this->owner->view->getPySegmentor()->getInputBuffer();
    WCSTOMBS(FcitxInputStateGetRawInputBuffer(input), codeinput.c_str(), MAX_USER_INPUT);
    FcitxInputStateSetRawInputBufferSize(input, strlen(FcitxInputStateGetRawInputBuffer(input)));
}
Exemplo n.º 5
0
void
print_wide(const TWCHAR* wstr)
{
    char buf[512];

#ifdef HAVE_ICONV_H
    iconv_t icv = iconv_open("UTF-8", TWCHAR_ICONV_NAME);
    TIConvSrcPtr src = (TIConvSrcPtr)wstr;
    size_t srclen = (WCSLEN(wstr)+1)*sizeof(TWCHAR);
    char *dst = buf;
    size_t dstlen = 1024;
    iconv(icv, &src, &srclen, &dst, &dstlen);
    iconv_close(icv);
#else // !HAVE_ICONV_H
    memset(&buf[0], 0, sizeof(buf));
    WCSTOMBS(&buf[0], wstr, sizeof(buf) - 1);
#endif // HAVE_ICONV_H

    printf("%s", buf);
}
Exemplo n.º 6
0
void
CPinyinTrie::print(const TNode* pRoot, std::string& prefix, FILE *fp) const
{
    static char buf[1024];
    if (pRoot->m_nWordId > 0) {
        fprintf(fp, "%s", prefix.c_str());
        if (pRoot->m_csLevel)
            fprintf(fp, "(GBK+)");
        unsigned int sz = pRoot->m_nWordId;
        const TWordIdInfo *pwids = pRoot->getWordIdPtr();
        for (unsigned int i = 0; i < sz; ++i) {
            unsigned int id = pwids[i].m_id;
            const TWCHAR *pw = operator[](id);
            int len = WCSLEN(pw);
            if (len != lengthAt(id)) {
                printf(" (lengthAt %d error) ", id);
            }
            WCSTOMBS(buf, pw, 1024);
            fprintf(fp, " %s", buf);
            if (pwids[i].m_bSeen == 0)
                fprintf(fp, "[x]");
            else
                fprintf(fp, "[o]");

            fprintf(fp, "(%d)", pwids[i].m_cost);
        }
        fprintf(fp, "\n");
    }
    unsigned int sz = pRoot->m_nTransfer;
    const TTransUnit* ptrans = pRoot->getTrans();
    for (unsigned int i = 0; i < sz; ++i) {
        unsigned s = ptrans[i].m_Syllable;
        const TNode *pch = transfer(pRoot, s);
        const char *str = CPinyinData::decodeSyllable(s);
        if (!str) break;
        prefix = prefix + str + '\'';
        print(pch, prefix, fp);
        prefix.resize(prefix.size() - strlen(str) - 1);
    }
}
Exemplo n.º 7
0
		wcs	esc_http_str(const wcs& str, uint32_t codepage)
		{
			wcs s;
			int i,j;
			for(i=0;i<(int)str.size();++i)
			{
				wchar_t ch=str[i];
				if(
					(ch>='A'&&ch<='Z')||
					(ch>='a'&&ch<='z')||
					(ch>='0'&&ch<='9')
					)
					s+=str[i];
				else
				{
					mbs c=WCSTOMBS(wcs(L"")+str[i],codepage);
					for(j=0;j<(int)c.size();++j)
						s+=FORMATW(L"%%%02X",(unsigned char)c[j]);
				}
			}
			return s;
		}