etc.negui.system.text

文字列。
かなーりstring⇔Text変換の飛び交うネムぃの心臓部。
Note:
調整が必要。
てかtext, exception, timerを同一moduleにすべきなんじゃないだろうか。
History:
1.100: [S] wcharをtcharに。それに伴い変更可能部分を変更中。なんにせよ-Unicodeしないと使い物ならないしあんまし意味無い。
1.00β19: [P] どう見てもNeGuiに癒着していたのでpackageをnemuxi.systemからetc.negui.systemに移動。
1.00β14: std.formatでよく使うやつを実装して強化したい。
alias tchar;

alias tstring;

struct Text;
とりあえずWindowsW文字列を扱いやすく、それでいていい加減な文字列。
構造体だけど中身配列なんでほぼ参照。 外部(Windows)に渡すような関数では大抵これが引数。
 Text str;
 str = Text("aaa");
 assert(str == Text("aaa"c));
 assert(str == Text("aaa"w));
 assert(str == Text("aaa"c));

 str = Text(123);
 assert(str == Text("123"));

 str = Text("%s + %s = %s", 1, 9, 10);
 assert(str == Text("1 + 9 = 10"));
BUGS:
うわー、こいつ命名規則完全に無視してんじゃないか。 一括置き換えでいけるんかねー。
History:
1.100: [F] opCall, opAssign回りの変更とTの限定。関連moduleの修正。 [S] opCallの分割。 [F] 数値とかと比較できなくした。 [F] とりあえずrefへ。
wchar[] text;
実態。
static TypeInfo charType();
static TypeInfo textType();
型。
static Text wrap(wchar[] arg );
ラップ。
tchar[]そのものをTextに取り込む。
Patams:
arg = 取り込む配列。
Returns:
ラップ後のText。
Examples:
 tstring src="abc";

 tchar[] buffer=src.dup;
 auto t=Text.wrap(buffer);

 t[2] = 'C';
 assert(buffer == "abC");
 assert(buffer is t.text);
History:
1.100: 新規作成。
static const(Text) iwrap(tstring arg );
ラップ。
Text.wrapの書き換えないバージョン。
History:
1.100: 新規作成。
deprecated static Text emptyText();
空文字列の作成。
History:
1.100: [S] とりあえずpure/refに。
1.00β15: [S] finalだったのを修正。クラスにしようか迷っていたときの名残か…。
Deprecated:
Text.initでいいじゃん。
static immutable Text newline;

const wchar* ptr(bool NonTextIsNull = false);
Windows用文字列の生成。
Params:
bool NonTextIsNull
trueの場合に文字列が空ならnullを返す。
Returns:
textの0終端文字列を生成。 誰かに渡さないとGCの対象になるんで注意。
History:
1.100: [P] 挙動の変更。 [F] 引数追加。
const size_t length();
文字列の配列長を取得。 UTF-16が一文字純正だったら素敵。
Returns:
文字列の長さ。
size_t length(size_t Size );
文字列の配列長の設定。
Params:
size_t Size
設定する配列長。
History:
1.100: [S] 配列のサイズを返す。 [S] nothrow。
const bool validate();
Unicode文字列判定。
現在の文字列がUnicodeで合法かどうかを判定。
History:
1.100: 新規作成。
const size_t countCharacter();
文字列長取得。
現在のUnicode文字列長を取得。 length()と違い文字列の長さを取得する。
Returns:
文字列長。
In:
文字列がUnicodeとして正しいこと。
History:
1.100: 新規作成。
const Text dup();
文字列のコピー。
Returns:
コピーされた文字列。
const tstring idup();
文字列のimmutableなコピー。
Returns:
Dのwstring。
T toNumber(T, string _file = __FILE__, int _line = __LINE__)();
数値変換。
現在の文字列からTに対応する数値を取得。
Returns:
Tに対応する数値。
Throws:
変換に失敗した場合はNeGuiException。
Examples:
 auto t=Text("123");
 assert(t.toNumber!(int) == 123);
History:
1.100: 新規作成
bool tryNumber(T)(out T Value );
数値変換。
toNumber()と違い例外出力を行わない。
Params:
Value
変換後の数値。
Returns:
変換成功の真偽値。
Examples:
 auto t=Text("123");
 int result;
 if(t.tryNumber!(int)(result)) {
 	assert(result == 123);
 }
History:
1.100: 新規作成
Text numberSplit(T)(T number , tchar SplitChar = ',', size_t SplitCount = 3);
数値に区切り追加。
1000を1,000のように変換。
Params:
number
変換する数値。
SplitChar
区切りにする文字。
SplitCount
SplitCharを設定する桁数。
Returns:
区切り文字の追加された文字列。
In:
SplitCount > 0
Examples:
 assert(Text.numberSplit(1000) == Text("1,000"));
 assert(Text.numberSplit(1000, '.') == Text("1.000"));
 assert(Text.numberSplit(1000, ',', 1) == Text("1,0,0,0"));
History:
1.100: 新規作成。
static int numeralChatToNum(char c );
文字からn進数取得。
Params:
char c
n進数の最大値を表す文字。
Returns:
n進数。
Throws:
失敗時にNeGuiException。
Note:
一応公開してるけどユーザー側で使うことはまず無い。
Text toNumeral(T, BASE : int)(in T number , in BASE n = 16, in size_t Increment = BUFFER.INCREMENT);
Text toNumeral(T, BASE = char)(in T number , in BASE c = 'F', in size_t Increment = BUFFER.INCREMENT);
数値をn進数に変換。
History:
1.100: 新規作成。
T toNumeral10(T, BASE : int)(in Text Numeral , BASE n );
T toNumeral10(T, BASE : char)(in Text Numeral , BASE c );
n進数から10進数へ変換。
Text sort();
ソート。
Text reverse();
反転。
const string toString();
死んでしまえ。
History:
1.00β14: 空の場合に若干変更
string toString();
History:
1.00β19: 新規作成。
const string str();
UTF-8文字列取得。
History:
1.090: [S] 名前変更(text8 -> str)
1.00β19: 新規作成。
alias text8;
UTF-9文字列。
alias text16;
UTF-16文字列。
const dstring text32();
UTF-32文字列。
const const(char*) toStringz();

const Text opCat(in Text Value );
連結。
Text opCatAssign(in Text Value );
連結。
Text opCall(T)(in T arg );
文字からTextを生成。
Examples:
 Text t;

 t = Text('a');
 assert(t == Text("a"));
 t = Text('あ');
 assert(t == Text("あ"));
Text opCall(T)(in T* arg );
C形式文字列ポインタからText生成。
Examples:
 Text t;

 t = Text(x"313233003435360037383900".ptr);
 assert(t.text == "123");
 t = Text(x"313233003435360037383900"w.ptr);
 assert(t.text == "123");
 t = Text(x"313233003435360037383900"d.ptr);
 assert(t.text == "123");
Text opCall(T)(in T arg );
クラスからText生成。
TはITextを継承していること。
Text opCall(T)(ref const T arg );
構造体からText生成。
TはtoTextを持っていること。
Text opCall(T : Text)(ref const T arg );
TextからText生成。
Text.dup()を内部で呼び出し。
Text opCall(T)(in T arg );
引数からText生成。
Params:
arg
inなのでObject.toStringはできない。
Text opCall(String, T...)(in String SrcFormat , T Args );
書式からText生成。
Params:
SrcFormat
書式。
Note:
std.format.doFormat参照。
const tchar opIndex(size_t n );
[n ]
tchar opIndexAssign(tchar value , size_t n );
[n ] = value
Text opSlice();
[]
const Text opSlice(in size_t start , in size_t end );
[n..m]
History:
1.00β17: [B] 事前条件がDの仕様と違っていたのを修正。
const hash_t toHash();

const bool opEquals(ref const Text arg );

const int opCmp(ref const Text arg );

const int cmp(in Text text );
文字列比較。
History:
1.00β11: 新規作成。
const int icmp(in Text text );
文字列比較。
大文字小文字を区別しない。
History:
1.100: [S] 名前変更(cmpi -> icmp)。
1.00β11: 新規作成。
const Text chomp(in Text Delimiter = (Text).init);
文字列からDelimiter削除。
Params:
Text Delimiter
取り去る文字列。 Text.initならCR,LF,CRLF、
Note:
まんまstd.string.chomp
History:
1.100: [P] 引数追加。
const Text stripl();
先頭空白文字削除。
History:
1.063: [B] 全部ホワイトスペースでアウト。
1.010: [S] 属性変更。
const Text stripr();
末尾空白文字削除。
History:
1.063: [B] 全部ホワイトスペースでアウト。
1.010: [S] 属性変更。
const Text strip();
両端空白文字削除。
History:
1.010: [S] 属性変更。
enum CASE_SENSITIVE;

YES

NO

enum START;

HEAD

TAIL

const size_t count(in tchar c );
文字列カウント。
Examples:
 Text t;

 t = Text("abc;d;e;;f;g");
 assert(t.count(';') == 5);

 t = Text("abcdefg");
 assert(t.count(';') == 0);

 t=Text("");
 assert(t.count(';') == 0);

 t=Text(";");
 assert(t.count(';') == 1);
const size_t count(in Text Word );
文字列カウント。
Examples:
 Text t;

 t=Text("123aa456aa789");
 assert(t.count(Text("aa")) == 2);

 t=Text("123aa456aa789aa");
 assert(t.count(Text("aa")) == 3);

 t=Text("aaaaaaaa");
 assert(t.count(Text("aa")) == 4);

 t=Text("aaaaaaaaa");
 assert(t.count(Text("aa")) == 4);

 t=Text("");
 assert(t.count(Text("aa")) == 0);
History:
1.100: [B] 保持している文字列長が0でRange violation。
1.00β14: 新規作成。
deprecated const int find(in tchar c );
Note:
多すぎる。 std.string.indexOf, std.string.lastIndexOfにあわせるべき。
Deprecated:
Text.indexOfを使用すべき。
deprecated const int ifind(in tchar c );
ditto
Deprecated:
Text.indexOfを使用すべき。
deprecated const int rfind(in tchar c );
ditto
Deprecated:
Text.indexOfを使用すべき。
deprecated const int irfind(in tchar c );
ditto
Deprecated:
Text.indexOfを使用すべき。
deprecated const int find(in Text Word );
ditto
Deprecated:
Text.indexOfを使用すべき。
deprecated const int ifind(in Text Word );
ditto
Deprecated:
Text.indexOfを使用すべき。
deprecated const int rfind(in Text Word );
ditto
Deprecated:
Text.indexOfを使用すべき。
deprecated const int irfind(in Text Word );
ditto
Deprecated:
Text.indexOfを使用すべき。
const int indexOf(tchar c , CASE_SENSITIVE CaseSensitive = (CASE_SENSITIVE).YES, START Start = (START).HEAD);
文字検索。
Params:
tchar c
検索する文字。
CASE_SENSITIVE CaseSensitive
大文字小文字の区別。
START Start
検索位置。
Returns:
見つかった場合はそのインデックス、 見つからなかった場合は-1を返す。
Examples:
 Text t;
 t = Text("123456789abcdABCD");

 assert(t.indexOf('1', CASE_SENSITIVE.YES, START.HEAD) == 0);
 assert(t.indexOf('9', CASE_SENSITIVE.YES, START.HEAD) == 8);
 assert(t.indexOf('a', CASE_SENSITIVE.YES, START.HEAD) == 9);
 assert(t.indexOf('A', CASE_SENSITIVE.YES, START.HEAD) == 13);

 assert(t.indexOf('1', CASE_SENSITIVE.NO, START.HEAD) == 0);
 assert(t.indexOf('9', CASE_SENSITIVE.NO, START.HEAD) == 8);
 assert(t.indexOf('a', CASE_SENSITIVE.NO, START.HEAD) == 9);
 assert(t.indexOf('A', CASE_SENSITIVE.NO, START.HEAD) == 9);

 assert(t.indexOf('D', CASE_SENSITIVE.YES, START.TAIL) == 16);
 assert(t.indexOf('d', CASE_SENSITIVE.NO, START.TAIL) == 16);
 assert(t.indexOf('1', CASE_SENSITIVE.NO, START.TAIL) == 0);
const int indexOf(in Text Word , CASE_SENSITIVE CaseSensitive = (CASE_SENSITIVE).YES, START Start = (START).HEAD);
文字検索。
Params:
Text Word
検索する文字列。
CASE_SENSITIVE CaseSensitive
大文字小文字の区別。
START Start
検索位置。
Returns:
見つかった場合はそのインデックス、 見つからなかった場合は-1を返す。
Examples:
 Text t;
 t = Text("123456789abcdABCD");

 assert(t.indexOf(Text("1"), CASE_SENSITIVE.YES, START.HEAD) == 0);
 assert(t.indexOf(Text("abcd"), CASE_SENSITIVE.YES, START.HEAD) == 9);

 assert(t.indexOf(Text("1"), CASE_SENSITIVE.NO, START.HEAD) == 0);
 assert(t.indexOf(Text("12"), CASE_SENSITIVE.NO, START.HEAD) == 0);
 assert(t.indexOf(Text("ABCD"), CASE_SENSITIVE.NO, START.HEAD) == 9);
 assert(t.indexOf(Text("123456789abcdABCD"), CASE_SENSITIVE.NO, START.HEAD) == 0);
 assert(t.indexOf(Text("123456789abcdABCDE"), CASE_SENSITIVE.NO, START.HEAD) == -1);

 assert(t.indexOf(Text("12"), CASE_SENSITIVE.YES, START.TAIL) == 0);
 assert(t.indexOf(Text("23"), CASE_SENSITIVE.YES, START.TAIL) == 1);
 assert(t.indexOf(Text("abcd"), CASE_SENSITIVE.YES, START.TAIL) == 9);
 assert(t.indexOf(Text("ABCD"), CASE_SENSITIVE.NO, START.TAIL) == 13);
 assert(t.indexOf(Text("abcd"), CASE_SENSITIVE.NO, START.TAIL) == 13);
const Text[] split(in tchar c );
文字列分割。
Examples:
 Text t;
 Text[] list;

 t = Text("123 456 789");
 list = t.split(' ');
 assert(list.length == 3);
 assert(list[0].text == "123");
 assert(list[1].text == "456");
 assert(list[2].text == "789");

 t = Text("123,456,789,");
 list = t.split(',');
 assert(list.length == 4);
 assert(list[0].text == "123");
 assert(list[1].text == "456");
 assert(list[2].text == "789");
 assert(list[3].text == "");

 t = Text("");
 list = t.split(',');
 assert(!list.length);

 t = Text("123456789");
 list = t.split(',');
 assert(!list.length);

 t = Text("あ@い@う@え@お");
 list = t.split('@');
 assert(list.length == 5);

History:
1.00β14: 分割が変だったのを修正。
const Text[] split(in Text Word );
文字列分割。
Examples:
 Text t;
 Text[] list;

 t = Text("123..456..789");
 list = t.split(Text(".."));
 assert(list.length == 3);
 assert(list[0].text == "123");
 assert(list[1].text == "456");
 assert(list[2].text == "789");

 t = Text("123....456..789");
 list = t.split(Text(".."));
 assert(list.length ==4);
 assert(list[0].text == "123");
 assert(list[1].text == "");
 assert(list[2].text == "456");
 assert(list[3].text == "789");

 t = Text("");
 list = t.split(Text(".."));
 assert(!list.length);

 t = Text("テキスト文字列text文字列てきすと");
 list = t.split(Text("文字列"));
 assert(list.length == 3);
 assert(list[0].text == "テキスト");
 assert(list[1].text == "text");
 assert(list[2].text == "てきすと");

 t = Text("abcdefg");
 list = t.split(Text(".."));
 assert(!list.length);
History:
1.100: [S] 属性変更。 [B] 保持している文字列長が0でRange violation。 [B] 一致しない場合に戻り値がある。
1.00β14: 新規作成。
const Text[] splitlines();
改行分割。
Note:
std.string.splitlines
History:
1.100: 新規作成。
Text replaceRaw(in Text SrcWord , in Text NewWord );
文字列置き換え。
Textそのものに作用。
History:
1.100: 新規作成。
const Text replace(in Text SrcWord , in Text NewWord );
文字列置き換え。
History:
1.100: 新規作成。
Text insertRaw(in Text Word , size_t Index );
文字列挿入。
Textそのものに作用。
History:
1.100: 新規作成。
const Text insert(in Text Word , size_t Index );
文字列挿入。
History:
1.100: 新規作成。
static Text repeat(in Text Src , size_t Repeat );
文字列を繰り返す。
History:
1.100: [P] Repeatが一回の場合にSrcを返すのではなくSrcのコピーを返す用に変更。
1.00β14: 新規作成。
static Text repeat(tchar c , size_t Repeat );
文字を繰り返す。
History:
1.100: 新規作成。
const Text repeat(size_t Repeat );
現在の文字列を繰り返す。
History:
1.050: 新規作成。
Text quot(T)(in T left , in T right );
History:
1.061: [S] 属性変更。
Text quot(T)(in T arg );
History:
1.061: [S] 属性変更。
const bool isNumeric(bool Separator = true);
文字列は数値か。
Params:
bool Separator
セパレータを無視するか。
Note:
std.string.isNumeric
const Text filter(in wchar[] Characters );
const Text filter(tchar Character , in wchar[] Characters ...);
フィルタ。
フィルタに引っ掛かる文字を省く。
Params:
wchar[] Characters
フィルタとする文字。
Returns:
Charactersを取り除いたText。
const bool startsWith(in Text Word );
先頭文字列比較。
文字列の先頭が指定した文字列で始まっているかを調べる。
Params:
Text Word
比較したい文字列。
History:
1.100: 新規作成。
const bool endsWith(in Text Word );
末尾文字列比較。
文字列の末尾が指定した文字列で終わっているか調べる。
Params:
Text Word
比較したい文字列。
History:
1.100: 新規作成。
Text toText(in string s );

Text toText(in wstring s );

Text toText(in dstring s );

Text[] Texts(T...)(in T args );
Text[] Texts(T)(in T[] args );
string[] Strings(in Text[] texts );
Text/string配列作成。
見返すと使用頻度が多いコードだったんで作成。
History:
1.00β14: [F] 引数がnull時にnullを返すように変更。
abstract interface IText;

abstract interface ITitleText;
History:
1.100: [S] package移動(etc.negui.window.dialog.system -> etc.negui.system.text)。
abstract const Text text();

abstract void text(in Text);

Text join(in Text[] texts , in Text sep );
History:
1.00β14: 新規作成。
Text GetUnique(in Text[] TextArray , in Text Src );
History:
1.100: 名前変更(GetNoneDouble->GetUnique)。
1.090: 新規作成というかnemuxi.gui.window.dialog.settingdialog.groupdialogから独立。
struct TEXTNULLLIST;
NULL結合+終端NULL二つの文字列郡を作成。 Windowsへの橋渡し用。
BUGS:
汎用性を持たせるべき。
History:
1.100: 新規作成。