Menu

- Learn
- Documentation
  - Language Reference
  - Library Reference
  - Command-line Reference
  - Feature Overview
  - Articles
- Downloads
- Packages
- Community
  - Blog
  - Orgs using D
  - Twitter
  - Forums
  - IRC
  - Community Discord
  - Wiki
  - GitHub
  - Issues
  - Get involved
  - Contributors
  - Foundation
  - Security Team
  - Donate
  - Sponsors
- Resources
  - Tour
  - Books
  - Tutorials
  - Tools
  - Editors
  - IDEs
  - run.dlang.io
  - Visual D
  - Acknowledgments
  - D Style
  - Glossary
  - Sitemap

Search
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:
Boost License 1.0.
Authors:
Walter Bright

Source rt/aApply.d

alias `dg_t` = int delegate(void* c);
  Delegate type corresponding to transformed loop body
  The parameter is a pointer to the current char, wchar or dchar
  Returns:
  non-zero when a break statement is hit
int `_aApplycd1`(scope const(char)[] `aa`, dg_t `dg`);
int `_aApplywd1`(scope const(wchar)[] `aa`, dg_t `dg`);
int `_aApplycw1`(scope const(char)[] `aa`, dg_t `dg`);
int `_aApplywc1`(scope const(wchar)[] `aa`, dg_t `dg`);
int `_aApplydc1`(scope const(dchar)[] `aa`, dg_t `dg`);
int `_aApplydw1`(scope const(dchar)[] `aa`, dg_t `dg`);
  Loop over a string while changing the UTF encoding
  There 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
  The 1 variant only produces the character, the 2 variant also produces a loop index.
  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)[] `aa` | input string
  dg_t `dg` | foreach 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 body
  Parameters 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_t `dg`);
int `_aApplywd2`(scope const(wchar)[] `aa`, dg2_t `dg`);
int `_aApplycw2`(scope const(char)[] `aa`, dg2_t `dg`);
int `_aApplywc2`(scope const(wchar)[] `aa`, dg2_t `dg`);
int `_aApplydc2`(scope const(dchar)[] `aa`, dg2_t `dg`);
int `_aApplydw2`(scope const(dchar)[] `aa`, dg2_t `dg`);
  Variants of aApplyXXX that include a loop index.

Copyright © 1999-2023 by the D Language Foundation | Page generated by Ddoc on Fri Sep 15 21:14:04 2023