Skip to content

Commit eca9316

Browse files
authored
Merge pull request #1860 from GermanAizek/master
Code modernize C++17, refactor and minor optimize
2 parents 58795ee + d20e9d0 commit eca9316

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+157
-167
lines changed

sakura_core/CDicMgr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ BOOL CDicMgr::Search(
5252
CRunningTimer cRunningTimer( L"CDicMgr::Search" );
5353
#endif
5454
long i;
55-
const wchar_t* pszDelimit = L" /// ";
55+
constexpr auto& pszDelimit = L" /// ";
56+
constexpr auto cchDelimit = _countof(pszDelimit) - 1;
5657
wchar_t* pszWork;
5758
int nRes;
5859
wchar_t* pszToken;
@@ -81,7 +82,7 @@ BOOL CDicMgr::Search(
8182
pszWork = wcsstr( szLine, pszDelimit );
8283
if( NULL != pszWork && szLine[0] != L';' ){
8384
*pszWork = L'\0';
84-
pszWork += wcslen( pszDelimit );
85+
pszWork += cchDelimit;
8586

8687
/* 最初のトークンを取得します。 */
8788
wchar_t *context = NULL;

sakura_core/CGrepAgent.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ class CFileLoadOrWnd{
122122
, m_nLineNum(0)
123123
{
124124
}
125-
~CFileLoadOrWnd(){
126-
}
125+
~CFileLoadOrWnd() = default;
127126
ECodeType FileOpen(const WCHAR* pszFile, bool bBigFile, ECodeType charCode, int nFlag)
128127
{
129128
if( m_hWnd ){

sakura_core/CGrepEnumFileBase.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ class CGrepEnumFileBase {
115115
int Enumerates( LPCWSTR lpBaseFolder, VGrepEnumKeys& vecKeys, CGrepEnumOptions& option, CGrepEnumFileBase* pExceptItems = NULL ){
116116
int found = 0;
117117

118+
const auto cchBaseFolder = lpBaseFolder ? wcsnlen_s(lpBaseFolder, 4096 - 1) : 0; // FIXME: パス長の上限は暫定値。
118119
for( int i = 0; i < (int)vecKeys.size(); i++ ){
119-
int baseLen = wcslen( lpBaseFolder );
120+
int baseLen = cchBaseFolder;
120121
LPWSTR lpPath = new WCHAR[ baseLen + wcslen( vecKeys[ i ] ) + 2 ];
121122
if( NULL == lpPath ) break;
122123
wcscpy( lpPath, lpBaseFolder );
@@ -163,11 +164,11 @@ class CGrepEnumFileBase {
163164
if( IsValid( w32fd, lpName ) ){
164165
if( pExceptItems && pExceptItems->IsExist( lpFullPath ) ){
165166
}else{
166-
m_vpItems.push_back( PairGrepEnumItem( lpName, w32fd.nFileSizeLow ) );
167+
m_vpItems.emplace_back( lpName, w32fd.nFileSizeLow );
167168
found++; // 2011.11.19
168169
if( pExceptItems && nKeyDirLen ){
169170
// フォルダーを含んだパスなら検索済みとして除外指定に追加する
170-
pExceptItems->m_vpItems.push_back( PairGrepEnumItem( lpFullPath, w32fd.nFileSizeLow ) );
171+
pExceptItems->m_vpItems.emplace_back( lpFullPath, w32fd.nFileSizeLow );
171172
}else{
172173
delete [] lpFullPath;
173174
}

sakura_core/CGrepEnumKeys.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class CGrepEnumKeys {
6969
}
7070

7171
// 除外ファイルの2つの解析済み配列から1つのリストを作る
72-
auto GetExcludeFiles() const -> std::list<decltype(m_vecExceptFileKeys)::value_type> {
73-
std::list<decltype(m_vecExceptFileKeys)::value_type> excludeFiles;
72+
auto GetExcludeFiles() const -> std::vector<decltype(m_vecExceptFileKeys)::value_type> {
73+
std::vector<decltype(m_vecExceptFileKeys)::value_type> excludeFiles;
7474
const auto& fileKeys = m_vecExceptFileKeys;
7575
excludeFiles.insert( excludeFiles.cend(), fileKeys.cbegin(), fileKeys.cend() );
7676
const auto& absFileKeys = m_vecExceptAbsFileKeys;
@@ -79,8 +79,8 @@ class CGrepEnumKeys {
7979
}
8080

8181
// 除外フォルダーの2つの解析済み配列から1つのリストを作る
82-
auto GetExcludeFolders() const -> std::list<decltype(m_vecExceptFolderKeys)::value_type> {
83-
std::list<decltype(m_vecExceptFolderKeys)::value_type> excludeFolders;
82+
auto GetExcludeFolders() const -> std::vector<decltype(m_vecExceptFolderKeys)::value_type> {
83+
std::vector<decltype(m_vecExceptFolderKeys)::value_type> excludeFolders;
8484
const auto& folderKeys = m_vecExceptFolderKeys;
8585
excludeFolders.insert( excludeFolders.cend(), folderKeys.cbegin(), folderKeys.cend() );
8686
const auto& absFolderKeys = m_vecExceptAbsFolderKeys;

sakura_core/CProfile.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ using namespace std;
7272
*/
7373
void CProfile::Init( void )
7474
{
75-
m_strProfileName = L"";
75+
m_strProfileName.clear();
7676
m_ProfileData.clear();
7777
m_bRead = true;
7878
return;
@@ -100,17 +100,17 @@ void CProfile::ReadOneline(
100100
// セクション取得
101101
// Jan. 29, 2004 genta compare使用
102102
if( line.compare( 0, 1, LTEXT("[") ) == 0
103-
&& line.find( LTEXT("=") ) == line.npos
104-
&& line.find( LTEXT("]") ) == ( line.size() - 1 ) ) {
103+
&& line.find( LTEXT('=') ) == line.npos
104+
&& line.find( LTEXT(']') ) == ( line.size() - 1 ) ) {
105105
Section Buffer;
106106
Buffer.strSectionName = line.substr( 1, line.size() - 1 - 1 );
107107
m_ProfileData.push_back( Buffer );
108108
}
109109
// エントリ取得
110110
else if( !m_ProfileData.empty() ) { //最初のセクション以前の行のエントリは無視
111-
wstring::size_type idx = line.find( LTEXT("=") );
111+
wstring::size_type idx = line.find( LTEXT('=') );
112112
if( line.npos != idx ) {
113-
m_ProfileData.back().mapEntries.insert( PAIR_STR_STR( line.substr(0,idx), line.substr(idx+1) ) );
113+
m_ProfileData.back().mapEntries.emplace( line.substr(0,idx), line.substr(idx+1) );
114114
}
115115
}
116116
}
@@ -247,7 +247,7 @@ bool CProfile::WriteProfile(
247247

248248
std::vector< wstring > vecLine;
249249
if( NULL != pszComment ) {
250-
vecLine.push_back( LTEXT(";") + wstring( pszComment ) ); // //->; 2008/5/24 Uchi
250+
vecLine.emplace_back( LTEXT(";") + wstring( pszComment ) ); // //->; 2008/5/24 Uchi
251251
vecLine.push_back( LTEXT("") );
252252
}
253253
for(auto iter = m_ProfileData.cbegin(); iter != m_ProfileData.cend(); iter++ ) {

sakura_core/CProfile.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class CProfile
5454
typedef std::wstring wstring;
5555
typedef std::string string;
5656

57-
typedef std::pair< wstring, wstring > PAIR_STR_STR;
5857
typedef std::map< wstring, wstring > MAP_STR_STR;
5958
struct Section
6059
{

sakura_core/CPropertyManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ bool CPropertyManager::OpenPropertySheetTypes( HWND hWnd, int nPageNum, CTypeCon
111111
CPropTypes* pcPropTypes = new CPropTypes();
112112
pcPropTypes->Create( G_AppInstance(), m_hwndOwner );
113113

114-
std::unique_ptr<STypeConfig> pType(new STypeConfig());
114+
auto pType = std::make_unique<STypeConfig>();
115115
CDocTypeManager().GetTypeConfig(nSettingType, *pType);
116116
pcPropTypes->SetTypeData(*pType);
117117
// Mar. 31, 2003 genta メモリ削減のためポインタに変更しProperySheet内で取得するように

sakura_core/CSelectLang.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ class CLoadString
130130
/*
131131
|| Constructors
132132
*/
133-
CLoadString(){}
133+
CLoadString() = default;
134134
CLoadString( UINT uid ){ LoadString( uid ); } // 文字列読み込み付きコンストラクタ
135-
/*virtual*/ ~CLoadString(){}
135+
/*virtual*/ ~CLoadString() = default;
136136

137137
/*
138138
|| Attributes & Operations

sakura_core/_main/CControlTray.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ LRESULT CControlTray::DispatchEvent(
815815
int iBitmap = CMenuDrawer::TOOLBAR_ICON_PLUGCOMMAND_DEFAULT - 1;
816816
const CPlug* plug = *it;
817817
if( !plug->m_sIcon.empty() ){
818-
iBitmap = m_cMenuDrawer.m_pcIcons->Add( plug->m_cPlugin.GetFilePath( plug->m_sIcon.c_str() ).c_str() );
818+
iBitmap = m_cMenuDrawer.m_pcIcons->Add( plug->m_cPlugin.GetFilePath( plug->m_sIcon ).c_str() );
819819
}
820820
m_cMenuDrawer.AddToolButton( iBitmap, plug->GetFunctionCode() );
821821
}

sakura_core/basis/CMySize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class CMySize : public SIZE{
3333
public:
3434
//コンストラクタ・デストラクタ
35-
CMySize(){} //※初期化なし
35+
CMySize() : CMySize(0, 0) {}
3636
CMySize(int _cx,int _cy){ cx=_cx; cy=_cy; }
3737
CMySize(const SIZE& rhs){ cx=rhs.cx; cy=rhs.cy; }
3838

0 commit comments

Comments
 (0)