コード例 #1
0
SquirrelObject RegularExpression::findAll(const std::string& str)
{
	try {
		size_t pos = 0;
		SquirrelObject res = SquirrelVM::CreateArray(0);
		while (pos <= str.length()) 
		{
			if ( pcre_->search(str, pos)) 
			{ 
				pos = pcre_->get_match_end()+1;
				int count = matchesCount();
				SquirrelObject mat = SquirrelVM::CreateArray(count);
				for ( int i = 0; i < count; i++ ) {
					mat.SetValue(i, pcre_->get_match(i).c_str());
				}
				res.ArrayAppend(mat);
			}
			else {
				break;
			}
		}
		return res;
	} catch( Pcre::exception ex ) {
		LOG(ERROR) << ex.what();
		return SquirrelObject();
	}
}
コード例 #2
0
ファイル: UIManager.cpp プロジェクト: dlunch/foo_alsong_lyric
void UIManager::Draw(HWND hWnd, HDC hdc)
{
    EnterCriticalSection(&m_DrawCrit);
    int before, after;
    unsigned int i, cnt = 0;
    std::vector<LyricLine> lyric = LyricManagerInstance->GetLyric();
    after = before = m_Setting->GetnLine() / 2 - lyric.size() / 2;
    if(after < 0)
        after = 0;
    if(before < 0)
        before = 0;
    std::vector<LyricLine> lyricbefore = LyricManagerInstance->GetLyricBefore(before);
    std::vector<LyricLine> lyricafter = LyricManagerInstance->GetLyricAfter(after + lyric.size() - 1 - (1 - m_Setting->GetnLine() % 2));
    //현재 가사가 1줄 이상인 경우에는 두번째 줄부터
    if(!lyric.size())
        return;

    SquirrelVM::SetVMSys(m_vmSys);
    SquirrelObject lyrics = SquirrelVM::CreateArray(0);

    for(i = 0; i < before - lyricbefore.size(); i ++)
        lyrics.ArrayAppend((std::wstring(1, (wchar_t)2) + TEXT(" ")).c_str());
    if(lyric.size() < m_Setting->GetnLine())
    {
        for(i = 0; i < lyricbefore.size(); i ++)
        {
            std::wstring nowlrcw = std::wstring(1, (wchar_t)2) + pfc::stringcvt::string_wide_from_utf8_fast(lyricbefore[i].lyric.c_str()).get_ptr();
            lyrics.ArrayAppend(nowlrcw.c_str());
        }
    }
    for(i = 0; i < lyric.size(); i ++)
    {
        std::wstring nowlrcw = std::wstring(1, (wchar_t)1) + pfc::stringcvt::string_wide_from_utf8_fast(lyric[i].lyric.c_str()).get_ptr();
        lyrics.ArrayAppend(nowlrcw.c_str());
    }
    for(i = max(lyric.size() - 1, 0); i < lyricafter.size(); i ++)
    {
        std::wstring nowlrcw = std::wstring(1, (wchar_t)2) + pfc::stringcvt::string_wide_from_utf8_fast(lyricafter[i].lyric.c_str()).get_ptr();
        lyrics.ArrayAppend(nowlrcw.c_str());
    }

    UICanvas canvas(hWnd, hdc);
    SqPlus::SquirrelFunction<void>(m_RootTable, TEXT("Draw"))(&canvas, lyrics);

    LeaveCriticalSection(&m_DrawCrit);
}