Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: Ruby 1.9.3
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Text copied from http://redmine.ruby-lang.org/issues/4447. See that bug for details and MRI patch.

      Please add a String#byteslice() method to the Ruby 1.9 core API.

      Without that method, I am forced to inefficiently perform byte-based string slicing by (1) unpacking the entire string into an Array (with String#unpack or worse: my_string.bytes.to_a) then (2) slicing that Array and finally (3) joining the sliced Array into a string (with Array#pack or worse: my_array.map(&:chr).join), all as shown below:

      class String
        unless method_defined? :byteslice
          ##
          # Does the same thing as String#slice but
          # operates on bytes instead of characters.
          #
          def byteslice(*args)
            unpack('C*').slice(*args).pack('C*')
          end
        end
      end
      

      Thanks for your consideration.

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        Added in ee4a0561. Note that JRuby 1.6.x is never going beyond 1.9.2 compatibility and this is a 1.9.3 feature. JRuby 1.7 will be 1.9.3 compatible.

        Show
        Charles Oliver Nutter added a comment - Added in ee4a0561. Note that JRuby 1.6.x is never going beyond 1.9.2 compatibility and this is a 1.9.3 feature. JRuby 1.7 will be 1.9.3 compatible.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Charles Oliver Nutter
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: