0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > フォルダ文字列に不正な文字が入っているかチェックする実装

Last updated at Posted at 2016-01-20
動作環境
C++ Builder XE4
Rad Studio 10.2 Tokyo Update 2 (追記: 2017/12/27)

フォルダ名に不正な文字列が入っているかのチェックをしたい。

関連 http://qiita.com/7of9/items/9aa82ce970c2898da5d0

Qiitaへのコメントにてセパレータ文字列を1つのstring型で定義している例を参考にした。

Unit1.cpp

static bool DirName_hasInvalidChar(String target, String invalids)
{
	String invld;
	for(int idx = 0; idx <= invalids.Length(); idx++) {
		invld = invalids.SubString(idx + 1, 1);
		if (target.Pos(invld) > 0) {
			return true;
		}
	}
    return false;

}

static void Test_DirName_hasInvalidChar()
{
	String invalids = ".\\/:*?\"<>|";

	bool ok1 = DirName_hasInvalidChar(L"XXX", invalids);
	bool ok2 = DirName_hasInvalidChar(L"314159265358979", invalids);
	bool ng1 = DirName_hasInvalidChar(L"...", invalids);
	bool ng2 = DirName_hasInvalidChar(L"A.B.C", invalids);
	bool ng3 = DirName_hasInvalidChar(L"A\\B", invalids);
	bool ng4 = DirName_hasInvalidChar(L"A/B", invalids);
	bool ng5 = DirName_hasInvalidChar(L"A:B", invalids);
	bool ng6 = DirName_hasInvalidChar(L"A*B", invalids);
	bool ng7 = DirName_hasInvalidChar(L"A?B", invalids);
	bool ng8 = DirName_hasInvalidChar(L"A\"B", invalids);
	bool ng9 = DirName_hasInvalidChar(L"A<B", invalids);
	bool ng10 = DirName_hasInvalidChar(L"A>B", invalids);
	bool ng11 = DirName_hasInvalidChar(L"A|B", invalids);

}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Test_DirName_hasInvalidChar();

}

関数名は今後リファクタを検討するが、とりあえず実装した。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?