View source code Display the source code in std/utf.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.utf.decodeFront

decodeFront is a variant of decode which specifically decodes the first code point. Unlike decode, decodeFront accepts any input range of code units (rather than just a string or random access range). It also takes the range by ref and pops off the elements as it decodes them. If numCodeUnits is passed in, it gets set to the number of code units which were in the code point which was decoded.

Prototypes

dchar decodeFront(std.typecons.Flag!("useReplacementDchar").Flag useReplacementDchar, S)(
  S str,
  size_t numCodeUnits
)
if (!isSomeString!S && isInputRange!S && isSomeChar!(ElementType!S));

dchar decodeFront(std.typecons.Flag!("useReplacementDchar").Flag useReplacementDchar, S)(
  S str
)
if (isInputRange!S && isSomeChar!(ElementType!S));

Parameters

NameDescription
useReplacementDchar if invalid UTF, return replacementDchar rather than throwing
str input string or indexable Range
numCodeUnits set to number of code units processed

Returns

decoded character

Throws

UTFException if str.front is not the start of a valid UTF sequence. If an exception is thrown, then there is no guarantee as to the number of code units which were popped off, as it depends on the type of range being used and how many code units had to be popped off before the code point was determined to be invalid.

Authors

Walter Bright and Jonathan M Davis

License

Boost License 1.0.

Comments