コード例 #1
0
static int
uspell_dict_check (EnchantDict * me, const char *const word, size_t len)
{
	uSpell *manager;
	wide_t buf1[MAXCHARS], buf2[MAXCHARS], *curBuf, *otherBuf, *tmpBuf;
	utf8_t myWord[MAXCHARS];
	int length;
	
	if (len >= MAXCHARS)
		return 1; // too long; can't be right
	memcpy(reinterpret_cast<char *>(myWord), word, len);
	myWord[len] = 0;
	curBuf = buf1;
	otherBuf = buf2;
	manager = reinterpret_cast<uSpell *>(me->user_data);

	length = utf8_wide(curBuf, myWord, MAXCHARS);
	if (manager->isSpelledRight(curBuf, length)) {
		return 0; // correct the first time
	}
	if (manager->theFlags & uSpell::upperLower) {
		toUpper(otherBuf, curBuf, length);
		if (manager->isSpelledRight(otherBuf, length)) {
			manager->acceptWord(myWord);
			return 0; // correct if converted to all upper case
		}
		tmpBuf = curBuf;
		curBuf = otherBuf;
		otherBuf = tmpBuf;
	}
	if (manager->theFlags & uSpell::hasComposition) {
		unPrecompose(otherBuf, &length, curBuf, length);
		if (manager->isSpelledRight(otherBuf, length)) {
			manager->acceptWord(myWord);
			return 0; // correct if precomposed characters expanded, all upper
		}
		tmpBuf = curBuf;
		curBuf = otherBuf;
		otherBuf = tmpBuf;
	}
	if (manager->theFlags & uSpell::hasCompounds) {
		if (manager->isSpelledRightMultiple(curBuf, length)) {
			manager->acceptWord(myWord);
			return 0; // correct as two words.  Not right for all languages.
		}
	}
	return 1;
}
コード例 #2
0
static void
uspell_dict_add_to_session (EnchantDict * me, const char *const word,
		     size_t len)
{
	uSpell *manager;
	wide_t buf[MAXCHARS];
	utf8_t myWord[MAXCHARS];
	int length, index;
	
	manager = reinterpret_cast<uSpell *>(me->user_data);

	manager->acceptWord((const utf8_t *)word);
	if (len >= MAXCHARS)
		return; // too long; can't reasonably convert
	// see if we want to acceptWord(uppercase(myWord))
	if (!(manager->theFlags & uSpell::upperLower)) return; // non-case language
	length = utf8_wide(buf, (const utf8_t *)word, MAXCHARS);
	for (index = 0; index < length; index++) {
		if (g_unichar_isupper(buf[index])) return; // case-sensitive word
		buf[index] = g_unichar_toupper(buf[index]);
	}
	wide_utf8(myWord, MAXCHARS, buf, length);
	manager->acceptWord(myWord);
} // uspell_dict_add_to_session
コード例 #3
0
ファイル: main.cpp プロジェクト: zh99998/qqbot
	// 设置日志保存路径.
	void log_path(const std::string &path)
	{
		m_path = utf8_wide(path);
	}
コード例 #4
0
ファイル: youku_impl.cpp プロジェクト: EchoLiao/avplayer
bool youku_impl::parse_video_files(std::vector<std::string> &videos, const std::string &password)
{
    if (m_vid.empty())
        return -1;

	std::string prefix_query_url =
		"https://openapi.youku.com/v2/videos/files.json?"
		"client_id=e57bc82b1a9dcd2f&"
		"client_secret=a361608273b857415ee91a8285a16b4a&video_id=";

	// 添加id.
    std::string query = prefix_query_url + m_vid;

	// 添加passwd.
    query += password.empty() ? "" : "&watch_password="******"error");
			int err = errinfo.get<int>(L"code");
			// 输出json中包含的错误代码.
			std::cerr << "error code: " << err << std::endl;
			return false;
		}
		catch (std::exception &)
		{}

		// 得到文件表.
		boost::property_tree::wptree files = root.get_child(L"files");
		boost::property_tree::wptree type;

		// 说明: 在得到对应的视频文件表后, 然后解析segs表, 在这个表中, 包含了视频分段信息.
		// 注意m3u8是没有视频分段信息的, 它只有一个m3u8的地址url+duration信息. ok, 在
		// 得到了这些信息后, 我们就可以按此下载数据提供给播放器播放, so, 现在要做的是解析
		// 他们.

		// 得到hd2文件表.

		// 得到mp4文件表.

		// 得到3gp文件表.

		// 得到3gphd文件表.

		// 得到flv文件表.

		// 得到m3u8文件表.

	}
	catch (std::exception &e)
	{
		std::cerr << e.what() << std::endl;
		return false;
	}

	// boost::property_tree::parse_json();

	// 为了编译通过!!
	return false;

	// 查询.

//     curl p;
//     boost::property_tree::wptree root;
//     if (!parse_json(p.curl_send_request(query), root))
//         return -1;

//     boost::property_tree::wptree files=root.get_child(L"files");
// 
//     boost::property_tree::wptree type;

    // 暂时不播放高清和超清视频
    /*
    try
    {
        type=files.get_child(L"hd2");
        BOOST_FOREACH(boost::property_tree::wptree::value_type& v,type.get_child(L"segs"))
        {
            boost::property_tree::wptree value=v.second;
            p.detail[index-1]->hd2.push_back(codepage::w2utf(value.get<std::wstring>(L"url")));
        }
        ret++;
    }
    catch(...)
    {

    }

    try
    {
        type=files.get_child(L"mp4");
        BOOST_FOREACH(boost::property_tree::wptree::value_type& v,type.get_child(L"segs"))
        {
            boost::property_tree::wptree value=v.second;
            p.detail[index-1]->mp4.push_back(codepage::w2utf(value.get<std::wstring>(L"url")));
        }
        ret++;
    }
    catch(...)
    {

    }
    */
//     try
//     {
//         type=files.get_child(L"flv");
//         BOOST_FOREACH(boost::property_tree::wptree::value_type& v,type.get_child(L"segs"))
//         {
//             boost::property_tree::wptree value=v.second;
//             std::string relocation=location(codepage::w2utf(value.get<std::wstring>(L"url")));
//             if (!relocation.empty())
//                 videos.push_back(relocation);
//             else
//                 return -1;
//         }
//         return 0;
//     }
//     catch(...)
//     {
//         return -1;
//     }

}