add String#byteslice() method
-----------------------------

                 Key: JRUBY-5547
                 URL: http://jira.codehaus.org/browse/JRUBY-5547
             Project: JRuby
          Issue Type: Bug
          Components: Ruby 1.9.3
            Reporter: Charles Oliver Nutter
            Assignee: Thomas E Enebo


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:

{noformat}
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
{noformat}

Thanks for your consideration.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to