Skip to content

Commit 4e00948

Browse files
committed
Improve the documentation and template constraints for std.utf.codeLength
1 parent 70ea6a1 commit 4e00948

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

std/utf.d

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2519,9 +2519,15 @@ ubyte codeLength(C)(dchar c) @safe pure nothrow @nogc
25192519
in a string whose character type is $(D C). This is particularly useful
25202520
when slicing one string with the length of another and the two string
25212521
types use different character types.
2522+
2523+
Params:
2524+
C = the character type to get the encoding length for
2525+
input = the input range to calculate the encoding length from
2526+
Returns:
2527+
The number of code units in `input` when encoded to `C`
25222528
+/
25232529
size_t codeLength(C, InputRange)(InputRange input)
2524-
if (isInputRange!InputRange && is(ElementType!InputRange : dchar))
2530+
if (isInputRange!InputRange && !isInfinite!InputRange && is(ElementType!InputRange : dchar))
25252531
{
25262532
alias EncType = Unqual!(ElementEncodingType!InputRange);
25272533
static if (isSomeString!InputRange && is(EncType == C) && is(typeof(input.length)))

0 commit comments

Comments
 (0)