-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCEol.h
119 lines (95 loc) · 3.89 KB
/
CEol.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*! @file
@brief End of Line種別の管理
@author genta
@date 2000/5/15 新規作成
*/
/*
Copyright (C) 2000-2001, genta
Copyright (C) 2002, frozen, Moca
Copyright (C) 2018-2021, Sakura Editor Organization
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SAKURA_CEOL_036E1E16_7462_46A4_8F59_51D8E171E657_H_
#define SAKURA_CEOL_036E1E16_7462_46A4_8F59_51D8E171E657_H_
#pragma once
#include "_main/global.h"
// 2002/09/22 Moca EOL_CRLF_UNICODEを廃止
/* 行終端子の種類 */
enum EEolType : char {
EOL_NONE, //!<
EOL_CRLF, //!< 0d0a
EOL_LF, //!< 0a
EOL_CR, //!< 0d
EOL_NEL, //!< 85
EOL_LS, //!< 2028
EOL_PS, //!< 2029
EOL_CODEMAX, //
EOL_UNKNOWN = -1 //
};
struct SEolDefinition{
const WCHAR* m_szName;
const WCHAR* m_szDataW;
const ACHAR* m_szDataA;
int m_nLen;
bool StartsWith(const WCHAR* pData, int nLen) const{ return m_nLen<=nLen && 0==wmemcmp(pData,m_szDataW,m_nLen); }
bool StartsWith(const ACHAR* pData, int nLen) const{ return m_nLen<=nLen && m_szDataA[0] != '\0' && 0==memcmp(pData,m_szDataA,m_nLen); }
};
extern const SEolDefinition g_aEolTable[];
#define EOL_TYPE_NUM EOL_CODEMAX // 8
/* 行終端子の配列 */
extern const EEolType gm_pnEolTypeArr[EOL_TYPE_NUM];
#include "basis/SakuraBasis.h"
/*!
@brief 行末の改行コードを管理
管理とは言ってもオブジェクト化することで安全に設定を行えたり関連情報の取得を
オブジェクトに対するメソッドで行えるだけだが、グローバル変数への参照を
クラス内部に閉じこめることができるのでそれなりに意味はあると思う。
*/
class CEol{
public:
//コンストラクタ・デストラクタ
CEol(){ m_eEolType = EOL_NONE; }
CEol( EEolType t ){ SetType(t); }
//比較
bool operator==( EEolType t ) const { return GetType() == t; }
bool operator!=( EEolType t ) const { return GetType() != t; }
//代入
const CEol& operator=( const CEol& t ){ m_eEolType = t.m_eEolType; return *this; }
//型変換
operator EEolType() const { return GetType(); }
//設定
bool SetType( EEolType t); // Typeの設定
void SetTypeByString( const wchar_t* pszData, int nDataLen );
void SetTypeByString( const char* pszData, int nDataLen );
//設定(ファイル読み込み時に使用)
void SetTypeByStringForFile( const char* pszData, int nDataLen ){ SetTypeByString( pszData, nDataLen ); }
void SetTypeByStringForFile_uni( const char* pszData, int nDataLen );
void SetTypeByStringForFile_unibe( const char* pszData, int nDataLen );
//取得
EEolType GetType() const{ return m_eEolType; } //!< 現在のTypeを取得
CLogicInt GetLen() const { return CLogicInt(g_aEolTable[ m_eEolType ].m_nLen); } //!< 現在のEOL長を取得。文字単位。
const WCHAR* GetName() const; //!< 現在のEOLの名称取得
const wchar_t* GetValue2() const; //!< 現在のEOL文字列先頭へのポインタを取得
//#####
bool IsValid() const
{
return m_eEolType>=EOL_CRLF && m_eEolType<EOL_CODEMAX;
}
private:
EEolType m_eEolType; //!< 改行コードの種類
};
#endif /* SAKURA_CEOL_036E1E16_7462_46A4_8F59_51D8E171E657_H_ */