Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
rt.aApply
This code handles decoding UTF strings for foreach loops.
License:
Authors:
Walter Bright
Source rt/aApply.d
- alias
dg_t= int delegate(void* c); - Delegate type corresponding to transformed loop bodyThe parameter is a pointer to the current char, wchar or dcharReturns:non-zero when a break statement is hit
- int
_aApplycd1(scope const(char)[]aa, dg_tdg);
int_aApplywd1(scope const(wchar)[]aa, dg_tdg);
int_aApplycw1(scope const(char)[]aa, dg_tdg);
int_aApplywc1(scope const(wchar)[]aa, dg_tdg);
int_aApplydc1(scope const(dchar)[]aa, dg_tdg);
int_aApplydw1(scope const(dchar)[]aa, dg_tdg); - Loop over a string while changing the UTF encodingThere are 6 combinations of conversions between char, wchar, and dchar, and 2 of each of those. The naming convention is as follows: aApply{c,d,w}{c,d,w}{1,2} The first letter corresponds to the input string encoding, and the second letter corresponds to the target character type.
- c = char
- w = wchar
- d = dchar
Examples:void main() { string str; wtring wstr; dstring dstr; foreach (dchar c; str) {} // _aApplycd1 foreach (wchar c; dstr) {} // _aApplydw1 foreach (i, wchar c; str) {} // _aApplycw2 foreach (wchar w; wstr) {} // no conversion }
Parameters:const(char)[] aainput string dg_t dgforeach body transformed into a delegate, similar to opApply Returns:non-zero when the loop was exited through a break - alias
dg2_t= int delegate(void* i, void* c); - Delegate type corresponding to transformed loop bodyParameters are pointers to a size_t loop index, and the current char, wchar or dchar.Returns:non-zero when a break statement is hit
- int
_aApplycd2(scope const(char)[]aa, dg2_tdg);
int_aApplywd2(scope const(wchar)[]aa, dg2_tdg);
int_aApplycw2(scope const(char)[]aa, dg2_tdg);
int_aApplywc2(scope const(wchar)[]aa, dg2_tdg);
int_aApplydc2(scope const(dchar)[]aa, dg2_tdg);
int_aApplydw2(scope const(dchar)[]aa, dg2_tdg); - Variants of aApplyXXX that include a loop index.
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Mon Mar 31 10:28:08 2025