Skip to content

Commit

Permalink
fix parse string in lisp
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancorvussolis committed Jan 30, 2016
1 parent 0dc8e25 commit f25c703
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions common/parseskkdic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,44 +194,41 @@ void ParseSKKDicOkuriBlock(const std::wstring &s, SKKDICOKURIBLOCKS &o)

std::wstring ParseConcat(const std::wstring &s)
{
std::wstring ret, tmpstr, fmt, numstr, numtmpstr;
std::wstring ret, fmt, numstr, numtmpstr;
std::wregex re;
std::wsmatch res;
wchar_t u;
LPCWSTR bsrep = L"\uf05c";
ret = s;

tmpstr = s;
re.assign(L"^\\(\\s*concat\\s+\".+\"\\s*\\)$");
if(std::regex_search(tmpstr, re))
if(std::regex_search(ret, re))
{
ret.clear();

fmt.assign(L"$1");
re.assign(L"^\\(\\s*concat\\s+\"(.+)\"\\s*\\)$");
tmpstr = std::regex_replace(tmpstr, re, fmt);
fmt.assign(L"");
fmt.assign(L"$1");
ret = std::regex_replace(ret, re, fmt);
re.assign(L"\"\\s+\"");
tmpstr = std::regex_replace(tmpstr, re, fmt);
fmt.assign(L"");
ret = std::regex_replace(ret, re, fmt);
//バックスラッシュ
fmt.assign(bsrep);
re.assign(L"\\\\\\\\");
tmpstr = std::regex_replace(tmpstr, re, fmt);
fmt.assign(bsrep);
ret = std::regex_replace(ret, re, fmt);
//二重引用符
fmt.assign(L"\\\"");
re.assign(L"\\\\\\\"");
tmpstr = std::regex_replace(tmpstr, re, fmt);
fmt.assign(L"\\\"");
ret = std::regex_replace(ret, re, fmt);
//空白文字
fmt.assign(L"\x20");
re.assign(L"\\\\s");
tmpstr = std::regex_replace(tmpstr, re, fmt);
fmt.assign(L"\x20");
ret = std::regex_replace(ret, re, fmt);
//制御文字など
fmt.assign(L"");
re.assign(L"\\\\[abtnvfred ]");
tmpstr = std::regex_replace(tmpstr, re, fmt);
fmt.assign(L"");
ret = std::regex_replace(ret, re, fmt);
//8進数表記の文字
re.assign(L"\\\\[0-3][0-7]{2}");
while(std::regex_search(tmpstr, res, re))
while(std::regex_search(ret, res, re))
{
numstr += res.prefix();
numtmpstr = res.str();
Expand All @@ -241,19 +238,17 @@ std::wstring ParseConcat(const std::wstring &s)
{
numstr.append(1, u);
}
tmpstr = res.suffix();
ret = res.suffix();
}
tmpstr = numstr + tmpstr;
ret = numstr + ret;
//意味なしエスケープ
fmt.assign(L"");
re.assign(L"\\\\");
tmpstr = std::regex_replace(tmpstr, re, fmt);
fmt.assign(L"");
ret = std::regex_replace(ret, re, fmt);
//バックスラッシュ
fmt.assign(L"\\");
re.assign(bsrep);
tmpstr = std::regex_replace(tmpstr, re, fmt);

ret = tmpstr;
fmt.assign(L"\\");
ret = std::regex_replace(ret, re, fmt);
}

return ret;
Expand Down

0 comments on commit f25c703

Please sign in to comment.