Skip to content

Commit ae32670

Browse files
authored
Merge ca95ee2 into d65f986
2 parents d65f986 + ca95ee2 commit ae32670

Some content is hidden

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

48 files changed

+472
-347
lines changed

sakura_core/CCodeChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
static bool _CheckSavingEolcode(const CDocLineMgr& pcDocLineMgr, CEol cEolType)
4343
{
4444
bool bMix = false;
45-
if( cEolType == EOL_NONE ){ //改行コード変換なし
45+
if( cEolType.IsNone() ){ //改行コード変換なし
4646
CEol cEolCheck; //比較対象EOL
4747
const CDocLine* pcDocLine = pcDocLineMgr.GetDocLineTop();
4848
if( pcDocLine ){
4949
cEolCheck = pcDocLine->GetEol();
5050
}
5151
while( pcDocLine ){
5252
CEol cEol = pcDocLine->GetEol();
53-
if( cEol != cEolCheck && cEol != EOL_NONE ){
53+
if( cEol != cEolCheck && cEol.IsValid() ){
5454
bMix = true;
5555
break;
5656
}

sakura_core/CEol.cpp

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,16 @@
3232
#include "StdAfx.h"
3333
#include "CEol.h"
3434

35-
/*! 行終端子の配列 */
36-
const EEolType gm_pnEolTypeArr[EOL_TYPE_NUM] = {
37-
EOL_NONE , // == 0
38-
EOL_CRLF , // == 2
39-
EOL_LF , // == 1
40-
EOL_CR , // == 1
41-
EOL_NEL , // == 1
42-
EOL_LS , // == 1
43-
EOL_PS // == 1
44-
};
45-
4635
//-----------------------------------------------
4736
// 固定データ
4837
//-----------------------------------------------
4938

5039
const SEolDefinition g_aEolTable[] = {
5140
{ L"改行無", L"", "", 0 },
52-
{ L"CRLF", L"\x0d\x0a", "\x0d\x0a", 2 },
41+
{ L"CRLF", L"\x0d\x0a", "\x0d\x0a", 2 },
5342
{ L"LF", L"\x0a", "\x0a", 1 },
5443
{ L"CR", L"\x0d", "\x0d", 1 },
55-
{ L"NEL", L"\x85", "", 1 },
44+
{ L"NEL", L"\x85", "", 1 },
5645
{ L"LS", L"\u2028", "", 1 },
5746
{ L"PS", L"\u2029", "", 1 },
5847
};
@@ -83,16 +72,17 @@ static const SEolDefinitionForUniFile g_aEolTable_uni_file[] = {
8372
行終端子の種類を調べる。
8473
@param pszData 調査対象文字列へのポインタ
8574
@param nDataLen 調査対象文字列の長さ
86-
@return 改行コードの種類。終端子が見つからなかったときはEOL_NONEを返す
75+
@return 改行コードの種類。終端子が見つからなかったときはEEolType::noneを返す
8776
*/
8877
template <class T>
8978
EEolType GetEOLType( const T* pszData, int nDataLen )
9079
{
91-
for( int i = 1; i < EOL_TYPE_NUM; ++i ){
92-
if( g_aEolTable[i].StartsWith(pszData, nDataLen) )
93-
return gm_pnEolTypeArr[i];
80+
for( size_t i = 1; i < EOL_TYPE_NUM; ++i ){
81+
if( g_aEolTable[i].StartsWith(pszData, nDataLen) ){
82+
return static_cast<EEolType>(i);
83+
}
9484
}
95-
return EOL_NONE;
85+
return EEolType::none;
9686
}
9787

9888
/*
@@ -101,36 +91,44 @@ EEolType GetEOLType( const T* pszData, int nDataLen )
10191

10292
EEolType _GetEOLType_uni( const char* pszData, int nDataLen )
10393
{
104-
for( int i = 1; i < EOL_TYPE_NUM; ++i ){
105-
if( g_aEolTable_uni_file[i].StartsWithW(pszData, nDataLen) )
106-
return gm_pnEolTypeArr[i];
94+
for( size_t i = 1; i < EOL_TYPE_NUM; ++i ){
95+
if( g_aEolTable_uni_file[i].StartsWithW(pszData, nDataLen) ){
96+
return static_cast<EEolType>(i);
97+
}
10798
}
108-
return EOL_NONE;
99+
return EEolType::none;
109100
}
110101

111102
EEolType _GetEOLType_unibe( const char* pszData, int nDataLen )
112103
{
113-
for( int i = 1; i < EOL_TYPE_NUM; ++i ){
114-
if( g_aEolTable_uni_file[i].StartsWithWB(pszData, nDataLen) )
115-
return gm_pnEolTypeArr[i];
104+
for( size_t i = 1; i < EOL_TYPE_NUM; ++i ){
105+
if( g_aEolTable_uni_file[i].StartsWithWB(pszData, nDataLen) ){
106+
return static_cast<EEolType>(i);
107+
}
116108
}
117-
return EOL_NONE;
109+
return EEolType::none;
118110
}
119111

120112
//-----------------------------------------------
121113
// 実装部
122114
//-----------------------------------------------
123115

124116
//! 現在のEOLの名称取得
125-
const WCHAR* CEol::GetName() const
117+
[[nodiscard]] LPCWSTR CEol::GetName() const noexcept
118+
{
119+
return g_aEolTable[static_cast<size_t>(m_eEolType)].m_szName;
120+
}
121+
122+
//! 現在のEOL文字列先頭へのポインタを取得
123+
[[nodiscard]] LPCWSTR CEol::GetValue2() const noexcept
126124
{
127-
return g_aEolTable[ m_eEolType ].m_szName;
125+
return g_aEolTable[static_cast<size_t>(m_eEolType)].m_szDataW;
128126
}
129127

130-
//!< 現在のEOL文字列先頭へのポインタを取得
131-
const wchar_t* CEol::GetValue2() const
128+
//! 現在のEOL文字列長を取得。文字単位。
129+
[[nodiscard]] CLogicInt CEol::GetLen() const noexcept
132130
{
133-
return g_aEolTable[ m_eEolType ].m_szDataW;
131+
return CLogicInt(g_aEolTable[static_cast<size_t>(m_eEolType)].m_nLen);
134132
}
135133

136134
/*!
@@ -139,16 +137,17 @@ const wchar_t* CEol::GetValue2() const
139137
@retval true 正常終了。設定が反映された。
140138
@retval false 異常終了。強制的にCRLFに設定。
141139
*/
142-
bool CEol::SetType( EEolType t )
140+
constexpr bool CEol::SetType( EEolType t ) noexcept
143141
{
144-
if( t < EOL_NONE || EOL_CODEMAX <= t ){
145-
// 異常値
146-
m_eEolType = EOL_CRLF;
142+
if( IsNoneOrValid( t ) ){
143+
// 正しい値
144+
m_eEolType = t;
145+
return true;
146+
}else{
147+
// 異常値
148+
m_eEolType = EEolType::cr_and_lf;
147149
return false;
148150
}
149-
// 正しい値
150-
m_eEolType = t;
151-
return true;
152151
}
153152

154153
void CEol::SetTypeByString( const wchar_t* pszData, int nDataLen )
@@ -170,3 +169,23 @@ void CEol::SetTypeByStringForFile_unibe( const char* pszData, int nDataLen )
170169
{
171170
SetType( _GetEOLType_unibe( pszData, nDataLen ) );
172171
}
172+
173+
bool operator == ( const CEol& lhs, const CEol& rhs ) noexcept
174+
{
175+
return lhs.operator==(static_cast<EEolType>(rhs));
176+
}
177+
178+
bool operator != ( const CEol& lhs, const CEol& rhs ) noexcept
179+
{
180+
return !(lhs == rhs);
181+
}
182+
183+
bool operator == ( EEolType lhs, const CEol& rhs ) noexcept
184+
{
185+
return rhs.operator==(lhs);
186+
}
187+
188+
bool operator != ( EEolType lhs, const CEol& rhs ) noexcept
189+
{
190+
return !(lhs == rhs);
191+
}

sakura_core/CEol.h

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,29 @@
3535
#pragma once
3636

3737
#include "_main/global.h"
38+
#include "basis/SakuraBasis.h"
3839

39-
// 2002/09/22 Moca EOL_CRLF_UNICODEを廃止
40-
/* 行終端子の種類 */
41-
enum EEolType : char {
42-
EOL_NONE, //!<
43-
EOL_CRLF, //!< 0d0a
44-
EOL_LF, //!< 0a
45-
EOL_CR, //!< 0d
46-
EOL_NEL, //!< 85
47-
EOL_LS, //!< 2028
48-
EOL_PS, //!< 2029
49-
EOL_CODEMAX, //
50-
EOL_UNKNOWN = -1 //
40+
/*!
41+
行終端子の種類
42+
43+
行末記号の種類を定義する。
44+
0より大きい値は、終端の種類に対応する。
45+
ファイル末尾の行では「終端がない状態」があり得る。
46+
ドキュメントの行末スタイルに合わせて自動付与を行うための値も定義しておく。
47+
48+
@date 2002/09/22 Moca EOL_CRLF_UNICODEを廃止
49+
@date 2021/03/27 berryzplus 定数に意味のある名前を付ける
50+
*/
51+
enum class EEolType : char {
52+
auto_detect = -1, //!< 行終端子の自動検出
53+
none, //!< 行終端子なし
54+
cr_and_lf, //!< \x0d\x0a 復帰改行
55+
line_feed, //!< \x0a 改行
56+
carriage_return, //!< \x0d 復帰
57+
next_line, //!< \u0085 NEL
58+
line_separator, //!< \u2028 LS
59+
paragraph_separator, //!< \u2029 PS
60+
code_max, //!< 範囲外検出用のマーカー(行終端子として使用しないこと)
5161
};
5262

5363
struct SEolDefinition{
@@ -59,14 +69,8 @@ struct SEolDefinition{
5969
bool StartsWith(const WCHAR* pData, int nLen) const{ return m_nLen<=nLen && 0==wmemcmp(pData,m_szDataW,m_nLen); }
6070
bool StartsWith(const ACHAR* pData, int nLen) const{ return m_nLen<=nLen && m_szDataA[0] != '\0' && 0==memcmp(pData,m_szDataA,m_nLen); }
6171
};
62-
extern const SEolDefinition g_aEolTable[];
6372

64-
#define EOL_TYPE_NUM EOL_CODEMAX // 8
65-
66-
/* 行終端子の配列 */
67-
extern const EEolType gm_pnEolTypeArr[EOL_TYPE_NUM];
68-
69-
#include "basis/SakuraBasis.h"
73+
constexpr auto EOL_TYPE_NUM = static_cast<size_t>(EEolType::code_max); // 8
7074

7175
/*!
7276
@brief 行末の改行コードを管理
@@ -75,45 +79,64 @@ extern const EEolType gm_pnEolTypeArr[EOL_TYPE_NUM];
7579
オブジェクトに対するメソッドで行えるだけだが、グローバル変数への参照を
7680
クラス内部に閉じこめることができるのでそれなりに意味はあると思う。
7781
*/
78-
class CEol{
82+
class CEol {
83+
EEolType m_eEolType = EEolType::none; //!< 改行コードの種類
84+
7985
public:
80-
//コンストラクタ・デストラクタ
81-
CEol(){ m_eEolType = EOL_NONE; }
82-
CEol( EEolType t ){ SetType(t); }
86+
static constexpr bool IsNone( EEolType t ) noexcept
87+
{
88+
return t == EEolType::none;
89+
}
90+
static constexpr bool IsValid( EEolType t ) noexcept
91+
{
92+
return EEolType::none < t && t < EEolType::code_max;
93+
}
94+
static constexpr bool IsNoneOrValid( EEolType t ) noexcept
95+
{
96+
return IsNone( t ) || IsValid( t );
97+
}
8398

84-
//比較
85-
bool operator==( EEolType t ) const { return GetType() == t; }
86-
bool operator!=( EEolType t ) const { return GetType() != t; }
99+
constexpr explicit CEol( EEolType t ) noexcept
100+
{
101+
SetType( t );
102+
}
103+
CEol() noexcept = default;
87104

88-
//代入
89-
const CEol& operator=( const CEol& t ){ m_eEolType = t.m_eEolType; return *this; }
105+
//取得
106+
[[nodiscard]] bool IsNone() const noexcept { return IsNone( m_eEolType ); } //!< 行終端子がないかどうか
107+
[[nodiscard]] bool IsValid() const noexcept { return !IsNone(); } //!< 行終端子があるかどうか
108+
[[nodiscard]] constexpr EEolType GetType() const noexcept { return m_eEolType; } //!< 現在のTypeを取得
109+
[[nodiscard]] LPCWSTR GetName() const noexcept; //!< 現在のEOLの名称取得
110+
[[nodiscard]] LPCWSTR GetValue2() const noexcept; //!< 現在のEOL文字列先頭へのポインタを取得
111+
[[nodiscard]] CLogicInt GetLen() const noexcept; //!< 現在のEOL長を取得。文字単位。
112+
113+
//比較
114+
[[nodiscard]] constexpr bool operator == ( EEolType t ) const noexcept { return GetType() == t; }
115+
[[nodiscard]] constexpr bool operator != ( EEolType t ) const noexcept { return !operator == ( t ); }
90116

91117
//型変換
92-
operator EEolType() const { return GetType(); }
118+
[[nodiscard]] constexpr explicit operator EEolType() const { return GetType(); }
93119

94120
//設定
95-
bool SetType( EEolType t); // Typeの設定
121+
constexpr bool SetType( EEolType t ) noexcept;
122+
123+
//代入演算子
124+
CEol& operator = ( EEolType t ) noexcept { SetType( t ); return *this; }
125+
126+
//文字列内の行終端子を解析
96127
void SetTypeByString( const wchar_t* pszData, int nDataLen );
97128
void SetTypeByString( const char* pszData, int nDataLen );
98129

99130
//設定(ファイル読み込み時に使用)
100131
void SetTypeByStringForFile( const char* pszData, int nDataLen ){ SetTypeByString( pszData, nDataLen ); }
101132
void SetTypeByStringForFile_uni( const char* pszData, int nDataLen );
102133
void SetTypeByStringForFile_unibe( const char* pszData, int nDataLen );
134+
};
103135

104-
//取得
105-
EEolType GetType() const{ return m_eEolType; } //!< 現在のTypeを取得
106-
CLogicInt GetLen() const { return CLogicInt(g_aEolTable[ m_eEolType ].m_nLen); } //!< 現在のEOL長を取得。文字単位。
107-
const WCHAR* GetName() const; //!< 現在のEOLの名称取得
108-
const wchar_t* GetValue2() const; //!< 現在のEOL文字列先頭へのポインタを取得
109-
//#####
110-
111-
bool IsValid() const
112-
{
113-
return m_eEolType>=EOL_CRLF && m_eEolType<EOL_CODEMAX;
114-
}
136+
// グローバル演算子
137+
bool operator == ( const CEol& lhs, const CEol& rhs ) noexcept;
138+
bool operator != ( const CEol& lhs, const CEol& rhs ) noexcept;
139+
bool operator == ( EEolType lhs, const CEol& rhs ) noexcept;
140+
bool operator != ( EEolType lhs, const CEol& rhs ) noexcept;
115141

116-
private:
117-
EEolType m_eEolType; //!< 改行コードの種類
118-
};
119142
#endif /* SAKURA_CEOL_036E1E16_7462_46A4_8F59_51D8E171E657_H_ */

sakura_core/CSearchAgent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ void CSearchAgent::ReplaceData( DocLineReplaceArg* pArg )
871871
goto prev_line;
872872
}
873873
/* 改行も削除するんかぃのぉ・・・? */
874-
if( EOL_NONE != pCDocLine->GetEol() &&
874+
if( pCDocLine->GetEol().IsValid() &&
875875
nWorkPos + nWorkLen > nLineLen - pCDocLine->GetEol().GetLen() // 2002/2/10 aroka CMemory変更
876876
){
877877
/* 削除する長さに改行も含める */

sakura_core/charset/CCodeBase.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ void CCodeBase::S_GetEol(CMemory* pcmemEol, EEolType eEolType)
117117
int nLen;
118118
}
119119
aEolTable[EOL_TYPE_NUM] = {
120-
{ "", 0 }, // EOL_NONE
121-
{ "\x0d\x0a", 2 }, // EOL_CRLF
122-
{ "\x0a", 1 }, // EOL_LF
123-
{ "\x0d", 1 }, // EOL_CR
124-
{ "", 0 }, // EOL_NEL
125-
{ "", 0 }, // EOL_LS
126-
{ "", 0 }, // EOL_PS
120+
{ "", 0 }, // EEolType::none
121+
{ "\x0d\x0a", 2 }, // EEolType::cr_and_lf
122+
{ "\x0a", 1 }, // EEolType::line_feed
123+
{ "\x0d", 1 }, // EEolType::carriage_return
124+
{ "", 0 }, // EEolType::next_line
125+
{ "", 0 }, // EEolType::line_separator
126+
{ "", 0 }, // EEolType::paragraph_separator
127127
};
128-
pcmemEol->SetRawData(aEolTable[eEolType].szData,aEolTable[eEolType].nLen);
128+
auto& data = aEolTable[static_cast<size_t>(eEolType)];
129+
pcmemEol->SetRawData(data.szData, data.nLen);
129130
}

sakura_core/charset/CCodeBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#pragma once
2929

3030
#include "mem/CNativeW.h"
31+
#include "CEol.h"
3132

3233
//定数
3334
enum EConvertResult{
@@ -37,7 +38,6 @@ enum EConvertResult{
3738
};
3839

3940
struct CommonSetting_Statusbar;
40-
enum EEolType : char;
4141

4242
/*!
4343
文字コード基底クラス。

sakura_core/charset/CUnicode.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ void CUnicode::GetEol(CMemory* pcmemEol, EEolType eEolType)
100100
int nLen;
101101
}
102102
aEolTable[EOL_TYPE_NUM] = {
103-
{ L"", 0 * sizeof(wchar_t) }, // EOL_NONE
104-
{ L"\x0d\x0a", 2 * sizeof(wchar_t) }, // EOL_CRLF
105-
{ L"\x0a", 1 * sizeof(wchar_t) }, // EOL_LF
106-
{ L"\x0d", 1 * sizeof(wchar_t) }, // EOL_CR
107-
{ L"\x85", 1 * sizeof(wchar_t) }, // EOL_NEL
108-
{ L"\u2028", 1 * sizeof(wchar_t) }, // EOL_LS
109-
{ L"\u2029", 1 * sizeof(wchar_t) }, // EOL_PS
103+
{ L"", 0 * sizeof(wchar_t) }, // EEolType::none
104+
{ L"\x0d\x0a", 2 * sizeof(wchar_t) }, // EEolType::cr_and_lf
105+
{ L"\x0a", 1 * sizeof(wchar_t) }, // EEolType::line_feed
106+
{ L"\x0d", 1 * sizeof(wchar_t) }, // EEolType::carriage_return
107+
{ L"\x85", 1 * sizeof(wchar_t) }, // EEolType::next_line
108+
{ L"\u2028", 1 * sizeof(wchar_t) }, // EEolType::line_separator
109+
{ L"\u2029", 1 * sizeof(wchar_t) }, // EEolType::paragraph_separator
110110
};
111-
pcmemEol->SetRawData(aEolTable[eEolType].pData,aEolTable[eEolType].nLen);
111+
auto& data = aEolTable[static_cast<size_t>(eEolType)];
112+
pcmemEol->SetRawData(data.pData, data.nLen);
112113
}

0 commit comments

Comments
 (0)