Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

検索条件の文字列をエスケープする処理を関数化する #1132

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 29 additions & 38 deletions sakura_core/CGrepAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@
#define ADDTAIL_INTERVAL_MILLISEC 50 // 結果出力の時間間隔
#define UIFILENAME_INTERVAL_MILLISEC 15 // Cancelダイアログのファイル名表示更新間隔

/*!
* 指定された文字列をタイプ別設定に従ってエスケープする
*/
inline CNativeW EscapeStringLiteral( const STypeConfig& type, const CNativeW& cmemString )
{
CNativeW cmemWork2( cmemString );
if( FALSE == type.m_ColorInfoArr[COLORIDX_WSTRING].m_bDisp ){
// 2011.11.28 色指定が無効ならエスケープしない
}else
if( type.m_nStringType == STRING_LITERAL_CPP || type.m_nStringType == STRING_LITERAL_CSHARP
|| type.m_nStringType == STRING_LITERAL_PYTHON ){ /* 文字列区切り記号エスケープ方法 */
cmemWork2.Replace( L"\\", L"\\\\" );
cmemWork2.Replace( L"\'", L"\\\'" );
cmemWork2.Replace( L"\"", L"\\\"" );
}else if( type.m_nStringType == STRING_LITERAL_PLSQL ){
cmemWork2.Replace( L"\'", L"\'\'" );
cmemWork2.Replace( L"\"", L"\"\"" );
}
return cmemWork2;
}

beru marked this conversation as resolved.
Show resolved Hide resolved
CGrepAgent::CGrepAgent()
: m_bGrepMode( false ) /* Grepモードか */
, m_bGrepRunning( false ) /* Grep処理中 */
Expand Down Expand Up @@ -389,6 +410,9 @@ DWORD CGrepAgent::DoGrep(
}
}

// 出力対象ビューのタイプ別設定(grepout固定)
const STypeConfig& type = pcViewDst->m_pcEditDoc->m_cDocType.GetDocumentAttribute();

std::vector<std::wstring> vPaths;
CreateFolders( pcmGrepFolder->GetStringPtr(), vPaths );

Expand All @@ -398,52 +422,19 @@ DWORD CGrepAgent::DoGrep(
CNativeW cmemWork;
cmemMessage.AppendString( LS( STR_GREP_SEARCH_CONDITION ) ); //L"\r\n□検索条件 "
if( 0 < nWork ){
CNativeW cmemWork2;
cmemWork2.SetNativeData( *pcmGrepKey );
const STypeConfig& type = pcViewDst->m_pcEditDoc->m_cDocType.GetDocumentAttribute();
if( FALSE == type.m_ColorInfoArr[COLORIDX_WSTRING].m_bDisp ){
// 2011.11.28 色指定が無効ならエスケープしない
}else
if( type.m_nStringType == STRING_LITERAL_CPP || type.m_nStringType == STRING_LITERAL_CSHARP
|| type.m_nStringType == STRING_LITERAL_PYTHON ){ /* 文字列区切り記号エスケープ方法 */
cmemWork2.Replace( L"\\", L"\\\\" );
cmemWork2.Replace( L"\'", L"\\\'" );
cmemWork2.Replace( L"\"", L"\\\"" );
}else if( type.m_nStringType == STRING_LITERAL_PLSQL ){
cmemWork2.Replace( L"\'", L"\'\'" );
cmemWork2.Replace( L"\"", L"\"\"" );
}
cmemWork.AppendString( L"\"" );
cmemWork.AppendNativeData( cmemWork2 );
cmemWork.AppendString( L"\"\r\n" );
cmemWork = EscapeStringLiteral( type, *pcmGrepKey );
cmemMessage.AppendStringF( L"\"%s\"\r\n", cmemWork.GetStringPtr() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmemWork=>pcmGrepKey は、GUI、コマンドラインともに、普通に2048文字を超える検索に対応しているので、アウトですね。
cmemReplaceのほうも同様です。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//! バッファの最後にデータを追加する (フォーマット機能付き)
void CNativeW::AppendStringF(const wchar_t* pszData, ...)
{
wchar_t buf[2048];
// 整形
va_list v;
va_start(v, pszData);
int len = _vsnwprintf_s(buf, _countof(buf), _TRUNCATE, pszData, v);
int e = errno;
va_end(v);
if (len == -1) {
DEBUG_TRACE(L"AppendStringF error. errno = %d", e);
throw std::exception();
}
// 追加
this->AppendString(buf, len);
}

お、本当ですね。言われてみるとそういえばそうだった…感が…。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1135 を作成しました。

}else{
cmemWork.AppendString( LS( STR_GREP_SEARCH_FILE ) ); //L"「ファイル検索」\r\n"
cmemMessage.AppendString( LS( STR_GREP_SEARCH_FILE ) ); //L"「ファイル検索」\r\n"
}
cmemMessage += cmemWork;

if( bGrepReplace ){
cmemMessage.AppendString( LS(STR_GREP_REPLACE_TO) );
if( bGrepPaste ){
cmemMessage.AppendString( LS(STR_GREP_PASTE_CLIPBOAD) );
}else{
CNativeW cmemWork2;
cmemWork2.SetNativeData( cmemReplace );
const STypeConfig& type = pcViewDst->m_pcEditDoc->m_cDocType.GetDocumentAttribute();
if( FALSE == type.m_ColorInfoArr[COLORIDX_WSTRING].m_bDisp ){
// 2011.11.28 色指定が無効ならエスケープしない
}else
if( type.m_nStringType == STRING_LITERAL_CPP || type.m_nStringType == STRING_LITERAL_CSHARP
|| type.m_nStringType == STRING_LITERAL_PYTHON ){ /* 文字列区切り記号エスケープ方法 */
cmemWork2.Replace( L"\\", L"\\\\" );
cmemWork2.Replace( L"\'", L"\\\'" );
cmemWork2.Replace( L"\"", L"\\\"" );
}else if( type.m_nStringType == STRING_LITERAL_PLSQL ){
cmemWork2.Replace( L"\'", L"\'\'" );
cmemWork2.Replace( L"\"", L"\"\"" );
}
cmemMessage.AppendString( L"\"" );
cmemMessage.AppendNativeData( cmemWork2 );
cmemMessage.AppendString( L"\"\r\n" );
cmemWork = EscapeStringLiteral( type, cmemReplace );
cmemMessage.AppendStringF( L"\"%s\"\r\n", cmemWork.GetStringPtr() );
}
}

Expand Down