mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 22:21:09 +03:00
Added function count()
This commit is contained in:
parent
c12b96b726
commit
449025e4d7
1 changed files with 0 additions and 34 deletions
|
@ -1514,40 +1514,6 @@ unittest
|
|||
assert(lastSequence("1000\u20AC") == "\u20AC".length);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the total number of code points encoded in a string.
|
||||
|
||||
The input to this function MUST be validly encoded. This is enforced
|
||||
by the function's in-contract.
|
||||
|
||||
Supercedes: This function supercedes $(D std.utf.toUCSindex()).
|
||||
|
||||
Standards: Unicode 5.0, ASCII, ISO-8859-1, WINDOWS-1252
|
||||
|
||||
Params:
|
||||
s = the string to be counted
|
||||
*/
|
||||
uint count(E)(const(E)[] s)
|
||||
in
|
||||
{
|
||||
assert(isValid(s));
|
||||
}
|
||||
body
|
||||
{
|
||||
uint n = 0;
|
||||
while (s.length != 0)
|
||||
{
|
||||
EncoderInstance!(E).skip(s);
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
assert(count("\u20AC100") == 4);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the array index at which the (n+1)th code point begins.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue