Skip to content

Commit b47ccff

Browse files
committed
CharPointer.hを削除する
1 parent 0135d88 commit b47ccff

File tree

6 files changed

+34
-124
lines changed

6 files changed

+34
-124
lines changed

sakura/sakura.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@
289289
<ClInclude Include="..\sakura_core\charset\CESI.h" />
290290
<ClInclude Include="..\sakura_core\charset\CEuc.h" />
291291
<ClInclude Include="..\sakura_core\charset\charcode.h" />
292-
<ClInclude Include="..\sakura_core\charset\CharPointer.h" />
293292
<ClInclude Include="..\sakura_core\charset\charset.h" />
294293
<ClInclude Include="..\sakura_core\charset\CJis.h" />
295294
<ClInclude Include="..\sakura_core\charset\CLatin1.h" />

sakura/sakura.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,6 @@
274274
<ClInclude Include="..\sakura_core\charset\charcode.h">
275275
<Filter>Cpp Source Files\charset</Filter>
276276
</ClInclude>
277-
<ClInclude Include="..\sakura_core\charset\CharPointer.h">
278-
<Filter>Cpp Source Files\charset</Filter>
279-
</ClInclude>
280277
<ClInclude Include="..\sakura_core\charset\charset.h">
281278
<Filter>Cpp Source Files\charset</Filter>
282279
</ClInclude>

sakura_core/charset/CharPointer.h

Lines changed: 0 additions & 72 deletions
This file was deleted.

sakura_core/typeprop/CPropTypesKeyHelp.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
#include "env/CShareData.h"
3636
#include "typeprop/CImpExpManager.h" // 2010/4/23 Uchi
3737
#include "dlg/CDlgOpenFile.h"
38-
#include "charset/CharPointer.h"
3938
#include "io/CTextStream.h"
39+
#include "util/file.h"
4040
#include "util/shell.h"
4141
#include "util/module.h"
4242
#include "apiwrap/StdApi.h"
@@ -69,7 +69,7 @@ static const DWORD p_helpids[] = { // 2006.10.10 ryoji
6969
};
7070

7171
static WCHAR* strcnv(WCHAR *str);
72-
static WCHAR* GetFileName(const WCHAR *fullpath);
72+
#define GetFileName(path) const_cast<WCHAR*>(GetFileTitlePointer(path))
7373

7474
static int nKeyHelpRMenuType[] = {
7575
STR_KEYHELP_RMENU_NONE,
@@ -672,23 +672,3 @@ static WCHAR* strcnv(WCHAR *str)
672672
}
673673
return str;
674674
}
675-
676-
/*! フルパスからファイル名を返す
677-
678-
@date 2006.04.10 fon 新規作成
679-
@date 2006.09.14 genta ディレクトリがない場合に最初の1文字が切れないように
680-
*/
681-
static WCHAR* GetFileName(const WCHAR* fullpath)
682-
{
683-
const WCHAR* pszName = fullpath;
684-
CharPointerW p = fullpath;
685-
while( *p != L'\0' ){
686-
if( *p == L'\\' ){
687-
pszName = p + 1;
688-
p++;
689-
}else{
690-
p++;
691-
}
692-
}
693-
return const_cast<WCHAR*>(pszName);
694-
}

sakura_core/util/file.cpp

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131

3232
#include <Shlwapi.h>
3333

34-
#include "charset/CharPointer.h"
34+
#include <regex>
35+
#include <string_view>
36+
37+
#include "charset/codechecker.h"
3538
#include "util/module.h"
3639
#include "util/window.h"
3740
#include "env/CShareData.h"
@@ -203,22 +206,21 @@ bool IsLocalDrive( const WCHAR* pszDrive )
203206
return true;
204207
}
205208

209+
/*! フルパスからファイル名を返す
210+
211+
@date 2006.04.10 fon 新規作成
212+
@date 2006.09.14 genta ディレクトリがない場合に最初の1文字が切れないように
213+
*/
206214
const WCHAR* GetFileTitlePointer(const WCHAR* pszPath)
207215
{
208-
CharPointerW p;
209-
const WCHAR* pszName;
210-
p = pszName = pszPath;
211-
while( *p )
212-
{
213-
if( *p == L'\\' ){
214-
pszName = p + 1;
215-
p++;
216-
}
217-
else{
218-
p++;
216+
std::wstring_view name(pszPath);
217+
if (const size_t sep = name.find_last_of(L'\\'); sep != std::wstring_view::npos) {
218+
if (sep + 1 == name.length()) {
219+
return pszPath + name.length();
219220
}
221+
return pszPath + sep + 1;
220222
}
221-
return pszName;
223+
return pszPath;
222224
}
223225

224226
/*! fnameが相対パスの場合は、実行ファイルのパスからの相対パスとして開く
@@ -445,23 +447,28 @@ int CalcDirectoryDepth(
445447
)
446448
{
447449
int depth = 0;
448-
450+
449451
// とりあえず\の数を数える
450-
for( CharPointerW p = path; *p != L'\0'; ++p ){
451-
if( *p == L'\\' ){
452-
++depth;
453-
// フルパスには入っていないはずだが念のため
454-
// .\はカレントディレクトリなので,深さに関係ない.
455-
while( p[1] == L'.' && p[2] == L'\\' ){
456-
p += 2;
457-
}
452+
std::wstring_view p(path);
453+
std::wstring_view::size_type pos = 0;
454+
do {
455+
pos = p.find_first_of(L'\\', pos);
456+
if (pos == std::wstring_view::npos) break;
457+
++depth;
458+
++pos;
459+
460+
// フルパスには入っていないはずだが念のため
461+
// .\はカレントディレクトリなので,深さに関係ない.
462+
while (pos + 2 <= p.length()
463+
&& p[pos + 0] == L'.'
464+
&& p[pos + 1] == L'\\') {
465+
pos += 2;
458466
}
459-
}
467+
} while (pos < p.length());
460468

461469
// 補正
462470
// ドライブ名はパスの深さに数えない
463-
if( ((L'A' <= path[0] && path[0] <= L'Z') || (L'a' <= path[0] && path[0] <= L'z'))
464-
&& path[1] == L':' && path[2] == L'\\' ){
471+
if (std::regex_search(path, std::wregex(LR"(^[A-Z]:\\)", std::wregex::icase))) {
465472
//フルパス
466473
--depth; // C:\ の \ はルートの記号なので階層深さではない
467474
}

sakura_core/window/CEditWnd.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
#include "env/CShareData.h"
5555
#include "env/CSakuraEnvironment.h"
5656
#include "print/CPrintPreview.h" /// 2002/2/3 aroka
57-
#include "charset/CharPointer.h"
5857
#include "charset/CCodeFactory.h"
5958
#include "charset/CCodeBase.h"
6059
#include "CEditApp.h"

0 commit comments

Comments
 (0)