codeLength

Returns the number of code units that are required to encode str in a string whose character type is C. This is particularly useful when slicing one string with the length of another and the two string types use different character types.

  1. ubyte codeLength(dchar c)
  2. size_t codeLength(InputRange input)
    size_t
    codeLength
    (
    C
    InputRange
    )
    (
    InputRange input
    )

Parameters

C

the character type to get the encoding length for

input InputRange

the input range to calculate the encoding length from

Return Value

Type: size_t

The number of code units in input when encoded to C

Examples

assert(codeLength!char("hello world") ==
       "hello world".length);
assert(codeLength!wchar("hello world") ==
       "hello world"w.length);
assert(codeLength!dchar("hello world") ==
       "hello world"d.length);

assert(codeLength!char(`プログラミング`) ==
       `プログラミング`.length);
assert(codeLength!wchar(`プログラミング`) ==
       `プログラミング`w.length);
assert(codeLength!dchar(`プログラミング`) ==
       `プログラミング`d.length);

string haystack = `Être sans la verité, ça, ce ne serait pas bien.`;
wstring needle = `Être sans la verité`;
assert(haystack[codeLength!char(needle) .. $] ==
       `, ça, ce ne serait pas bien.`);

Meta