Project

General

Profile

Actions

Feature #12744

open

Add str.reverse_each_char and str.reverse_chars

Added by bouk (Bouke van der Bijl) over 5 years ago. Updated over 5 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:77230]

Description

This patch adds str.reverse_each and str.reverse_chars. It's currently not really possible to iterate a Ruby string in reverse while guaranteeing that you're not accidentally introducing an O(N^2) bug, without encoding to a fixed-length encoding like UTF-32. This is because variable-length encodings like UTF-8 requiring iterating over the whole string if you want to address characters by index.

The patch uses rb_enc_left_char_head to iterate over the string in reverse, so you can do so without allocating more memory.


Files

add-reverse-string-iteration.patch (5.91 KB) add-reverse-string-iteration.patch Patch bouk (Bouke van der Bijl), 09/09/2016 03:36 PM
Actions

Also available in: Atom PDF