etc.negui.system.text

文字列。
かなーりstring⇔Text変換の飛び交うネムぃの心臓部。
Note:
調整が必要。
てかtext, exception, timerを同一moduleにすべきなんじゃないだろうか。
History:
1.100
  • sourcewcharをtcharに。それに伴い変更可能部分を変更中。なんにせよ-Unicodeしないと使い物ならないしあんまし意味無い。
1.00β19
  • sourceどう見てもNeGuiに癒着していたのでpackageをnemuxi.systemからetc.negui.systemに移動。
1.00β14
  • std.formatでよく使うやつを実装して強化したい。
alias tchar;
alias tstring;
文字及び文字列。
wcharでコーディングしていたNeGuiのために作ったけど他のpackage以前にこのmoduleですら対応できてない現状。
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"));
ToDo:
空文字列とnullな文字列の判定をきちんと実装すべき。
Note:
そろそろ正規表現も扱いたい。
BUGS:
うわー、こいつ命名規則完全に無視してんじゃないか。 一括置き換えでいけるんかねー。
History:
1.110
  • deletecmpi削除。
1.101
  • sourcetext8の説明がRFC 4042な文字コードの説明になっていた。
  • deleteemptyText削除。
  • deletefind, ifind, rfind, irfind削除。
1.100
  • featuresopCall, opAssign回りの変更とTの限定。関連moduleの修正。
  • sourceopCallの分割。
  • features数値とかと比較できなくした。
  • featuresとりあえずrefへ。
wchar[] text;
実体。
static TypeInfo charType();
static TypeInfo textType();
型。
Note:
これ何のために作ったんだろう。
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.110
  • source属性変更(static pure ref -> static pure)。
1.100
  • 新規作成。
static immutable Text newline;
改行。
const wchar* ptr(bool NonTextIsNull = false);
Windows用文字列の生成。
Params:
bool NonTextIsNull
trueの場合に文字列が空ならnullを返す。
Returns:
textのC形式(0終端)文字列を生成。 誰かに渡さないとGCの対象になるんで注意。
History:
1.100
  • program挙動の変更。
  • source引数追加。
const size_t length();
文字列の配列長を取得。
Note:
UTF-16が一文字純正だったら素敵だった。
Returns:
文字列の長さ。
size_t length(size_t Size );
文字列の配列長の設定。
Params:
size_t Size
設定する配列長。
History:
1.100
  • source配列のサイズを返す。
  • sourcenothrow。
const bool validate();
Unicode文字列判定。
現在の文字列がUnicodeで合法かどうかを判定。
Returns:
Unicodeとして正しければtrue、不正ならfalse。
History:
1.100
  • 新規作成。
const size_t countCharacter();
文字列長取得。
現在のUnicode文字列長を取得。 length()と違い文字列の長さを取得する。
Returns:
文字列長。
In:
文字列がUnicodeとして正しいこと。
History:
1.100
  • 新規作成。
const Text dup();
現在の文字列をコピー。
Returns:
コピーされた文字列。
const tstring idup();
文字列のimmutableなコピー。
Returns:
文字列のtstring。
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進数の最大値を表す文字。 [0-9A-Za-z]。
Returns:
n進数。
Throws:
失敗時にNeGuiException。
Note:
一応公開してるけどユーザー側で使うことはまず無い。
Text toNumeral(T : int, BASE = int)(in T number , in BASE n = 16, in size_t Increment = BUFFER.INCREMENT);
Text toNumeral(T : int, BASE = tchar)(in T number , in BASE c = 'F', in size_t Increment = BUFFER.INCREMENT);
数値をn進数に変換。
Params:
number
変換する数値。
n
変換するn進数。
c
n進数の最大値を表す文字。
Returns:
変換した文字列。
In:
n <= 2 とか。
History:
1.110
  • sourceテンプレートちまちま。
1.100
  • 新規作成。
T toNumeral10(T : int, BASE = int)(in Text Numeral , BASE n );
T toNumeral10(T : int, BASE = tchar)(in Text Numeral , BASE c );
n進数から10進数へ変換。
Params:
number
変換する数値の文字列。
n
n進数。
c
n進数の最大値を表す文字。
History:
1.110
  • sourceテンプレートちまちま。
Text sort();
ソート。
Text reverse();
反転。
const string toString();
死んでしまえ。
History:
1.00β14
  • 空の場合に若干変更
string toString();
History:
1.00β19
  • 新規作成。
const string str();
UTF-8文字列取得。
toStringとかconst toStringとかtext8で共通して使用。
History:
1.090
  • source名前変更(text8 -> str)。
1.00β19
  • 新規作成。
alias text8;
UTF-8文字列。
alias text16;
UTF-16文字列。
const dstring text32();
UTF-32文字列。
const(T)* toStringz(T = char)();
C形式文字列へ変換。
Returns:
終端0文字列。 それっぽいのはText.ptrを使用すべき。
History:
1.110
  • programテンプレートへ変更。
const Text opCat(in Text Value );
連結。
Text opCatAssign(in Text Value );
自身へ連結。
Text opCall(T : dchar)(in T arg );
文字からTextを生成。
Params:
arg
変換する文字。
Examples:
 Text t;

 t = Text('a');
 assert(t == Text("a"));
 t = Text('あ');
 assert(t == Text("あ"));
History:
1.110
  • sourceテンプレート変更(isSomeChar -> T: dchar)。
Text opCall(T)(in T* arg );
C形式文字列ポインタからText生成。
Params:
arg
変換する文字列へのポインタ。 0終端でなかった場合に死ぬ(日頃の行いでは大丈夫かも)。
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生成。
Params:
arg
変換するクラス。 ITextを継承していること。
Text opCall(T)(ref const T arg );
構造体からText生成。
Params:
arg
変換するクラス。 toTextを持っていること。
Text opCall(T : Text)(ref const T arg );
TextからText生成。
ただのコピー。
Params:
arg
変換するText。 arg.dup()を内部で呼び出し。
Text opCall(T)(in T arg );
引数からText生成。
Params:
arg
何か。
Note:
引数属性がinなのでObject.toStringはできない。
クラスを変換する場合はITextを継承したクラスにしてText!(IText)を使用するか、 Text(String, T...)を使用する。
Text opCall(String, T...)(in String SrcFormat , T Args );
書式からText生成。
Params:
SrcFormat
書式。
Args
変換する方々。
String
SrcFormatの文字列型。
  • Text, tsring
  • string
  • wstring
  • dstring
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 );
[start .. end ]
History:
1.00β17
  • bug事前条件が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 );
文字列比較。
Params:
Text text
比較する文字列。
History:
1.00β11
  • 新規作成。
const int icmp(in Text text );
文字列比較。
大文字小文字を区別しない。
Params:
Text text
比較する文字列。
History:
1.100
  • source名前変更(cmpi -> icmp)。
1.00β11
  • 新規作成。
const Text chomp(in Text Delimiter = (Text).init);
文字列からDelimiter削除。
Params:
Text Delimiter
取り去る文字列。 Text.initならCR,LF,CRLF、
Returns:
処理後の文字列。
Note:
まんまstd.string.chomp
History:
1.100
  • source引数変更
const Text stripl();
先頭空白文字削除。
Returns:
処理後の文字列。
History:
1.063
  • bug全部ホワイトスペースでアウト。
1.010
  • source属性変更。
const Text stripr();
末尾空白文字削除。
Returns:
処理後の文字列。
History:
1.063
  • bug全部ホワイトスペースでアウト。
1.010
  • source属性変更。
const Text strip();
両端空白文字削除。
Returns:
処理後の文字列。
History:
1.010
  • source属性変更。
enum CASE_SENSITIVE;
大文字・小文字の区別。
YES
区別する。
NO
区別しない。
enum START;
開始点。
HEAD
先頭から。
TAIL
末尾がら。
const size_t count(in tchar c );
文字列カウント。
Params:
tchar c
調べる文字。
Returns:
見つかった文字の数。
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 );
文字列カウント。
Params:
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
  • bug保持している文字列長が0でRange violation。
1.00β14
  • 新規作成。
enum FILL;
埋めもの。
History:
1.110
  • 新規作成。
LEFT
左。
CENTER
中心。
RIGHT
右。
Text fillRaw(FILL Fill , tchar c , size_t Width );
文字で埋める。
Textそのものに作用。
Params:
FILL Fill
元の文字列の配置。
tchar c
埋める文字。
size_t Width
最終的なサイズ。 FillがFILL.CENTERでWidthが奇数の場合、元の文字列は左寄り。
Returns:
埋められた文字列。 Widthが文字列より少ない場合は元の文字列。
History:
1.110
  • 新規作成。
const Text fill(FILL Fill , tchar c , size_t Width );
文字で埋める。
Params:
FILL Fill
元の文字列の配置。
tchar c
埋める文字。
size_t Width
最終的なサイズ。 FillがFILL.CENTERでWidthが奇数の場合、元の文字列は左寄り。
Returns:
埋められた文字列。 Widthが文字列より少ない場合は元の文字列。
History:
1.110
  • 新規作成。
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
  • source属性変更。
  • bug保持している文字列長が0でRange violation。
  • bug一致しない場合に戻り値がある。
1.00β14
  • 新規作成。
const Text[] splitLines();
改行分割。
Note:
std.string.splitlines。
History:
1.110
  • 名前, splitlines, splitLines
1.100
  • 新規作成。
const Text[] splitWhites();
空白分割。
History:
1.110
  • 新規作成。
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 );
文字列を繰り返す。
Params:
Text Src
対象の文字列。
size_t Repeat
繰り返す回数。
Returns:
Src * Repeatの文字列。
History:
1.100
  • programRepeatが一回の場合にSrcを返すのではなくSrcのコピーを返す用に変更。
1.00β14
  • 新規作成。
static Text repeat(tchar c , size_t Repeat );
文字を繰り返す。
Params:
tchar c
繰り返す文字。
size_t Repeat
繰り返す回数。
Returns:
c * Repeatの文字列。
History:
1.100
  • 新規作成。
const Text repeat(size_t Repeat );
現在の文字列を繰り返す。
Params:
size_t Repeat
繰り返す回数。
Returns:
現在の文字列 * Repeatの文字列。
History:
1.050
  • 新規作成。
Text quot(T)(in T left , in T right );
History:
1.061
  • source属性変更
Text quot(T)(in T arg );
History:
1.061
  • source属性変更
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
  • features引数がnull時にnullを返すように変更。
abstract interface IText;

template IsText(T)
History:
1.110
  • 新規作成。
abstract interface ITitleText;
History:
1.100
  • sourcepackage変更(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
  • source名前変更(GetNoneDouble -> GetUnique)。
1.090
  • 新規作成というかnemuxi.gui.window.dialog.settingdialog.groupdialogから独立。
struct TEXTNULLLIST;
NULL結合+終端NULL二つの文字列郡を作成。 Windowsへの橋渡し用。
BUGS:
汎用性を持たせるべき。
History:
1.100
  • 新規作成。