Req #73066 [NEW]: mb_at and mb_codepoint_at

From: Date: Mon, 12 Sep 2016 08:40:30 +0000
Subject: Req #73066 [NEW]: mb_at and mb_codepoint_at
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203971@lists.php.net to get a copy of this message
From:             masakielastic at gmail dot com
Operating system: 
PHP version:      Next Minor Version
Package:          mbstring related
Bug Type:         Feature/Change Request
Bug description:mb_at and mb_codepoint_at

Description:
------------
I propose mb_at and mb_codepoint_at.

string mb_at ( string $string , int $offset [, string $encoding =
mb_internal_encoding() ] )
int mb_codepoint_at ( string $string , int $offset [, string $encoding =
mb_internal_encoding() ] )

The one of usage of these functions is to iterate over all the chars in
string.

$str = "Cat!\u{1f431}";

$gen = (function($str) {
    for ($i = 0, $len = mb_strlen($str); $i < $len; ++$i) {
        yield mb_at($str, $i);
    }
})($str);

foreach ($gen as $char) {
    echo $char, PHP_EOL;
}

mb_codepoint_at is equivalent to the following code:

mb_ord(mb_substr($str, $i, 1));

str_at and str_codepoint_at are worthy of consideration.


-- 
Edit bug report at https://bugs.php.net/bug.php?id=73066&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=73066&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=73066&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=73066&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=73066&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=73066&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=73066&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=73066&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=73066&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=73066&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=73066&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=73066&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=73066&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=73066&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73066&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=73066&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=73066&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=73066&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73066&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=73066&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=73066&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#203971) next »