View source code Display the source code in std/uni.d from which this page was generated on github. 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 local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.uni.normalize

Returns input string normalized to the chosen form. Form C is used by default.

For more information on normalization forms see the Normalization, normalization section.

Prototype

inout(C)[] normalize(std.uni.NormalizationForm norm, C)(
  inout(C)[] input
);

Note

In cases where the string in question is already normalized, it is returned unmodified and no memory allocation happens.

Example

// any encoding works
wstring greet = "Hello world";
assert(normalize(greet) is greet); // the same exact slice

// An example of a character with all 4 forms being different:
// Greek upsilon with acute and hook symbol (code point 0x03D3)
assert(normalize!NFC("ϓ") == "\u03D3");
assert(normalize!NFD("ϓ") == "\u03D2\u0301");
assert(normalize!NFKC("ϓ") == "\u038E");
assert(normalize!NFKD("ϓ") == "\u03A5\u0301");

Authors

Dmitry Olshansky

License

Boost License 1.0.

Comments