Skip to content

Commit

Permalink
Group all Encoding methods together in corelib/encoding.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 26, 2013
1 parent 0bc0dc1 commit 78a2cc6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
37 changes: 37 additions & 0 deletions corelib/encoding.rb
Expand Up @@ -120,4 +120,41 @@ def bytesize

class String
`def.encoding = #{Encoding::UTF_16LE}`

def bytes
each_byte.to_a
end

def bytesize
@encoding.bytesize(self)
end

def each_byte(&block)
return enum_for :each_byte unless block_given?

@encoding.each_byte(self, &block)

self
end

def encoding
@encoding
end

def force_encoding(encoding)
encoding = Encoding.find(encoding)

return self if encoding == @encoding

%x{
var result = new native_string(self);
result.encoding = encoding;
return result;
}
end

def getbyte(idx)
@encoding.getbyte(self, idx)
end
end
35 changes: 1 addition & 34 deletions corelib/string.rb
Expand Up @@ -142,14 +142,6 @@ def [](index, length = undefined)
}
end

def bytes
each_byte.to_a
end

def bytesize
@encoding.bytesize(self)
end

def capitalize
`self.charAt(0).toUpperCase() + self.substr(1).toLowerCase()`
end
Expand Down Expand Up @@ -235,14 +227,6 @@ def downcase
`self.toLowerCase()`
end

def each_byte(&block)
return enum_for :each_byte unless block_given?

@encoding.each_byte(self, &block)

self
end

def each_char(&block)
return enum_for :each_char unless block_given?

Expand Down Expand Up @@ -280,10 +264,6 @@ def empty?
`self.length === 0`
end

def encoding
@encoding
end

def end_with?(*suffixes)
%x{
for (var i = 0, length = suffixes.length; i < length; i++) {
Expand All @@ -301,21 +281,8 @@ def end_with?(*suffixes)
alias eql? ==
alias equal? ===

def force_encoding(encoding)
encoding = Encoding.find(encoding)

return self if encoding == @encoding

%x{
var result = new native_string(self);
result.encoding = encoding;
return result;
}
end

def getbyte(idx)
@encoding.getbyte(self, idx)
`self.charCodeAt(idx)`

This comment has been minimized.

Copy link
@meh

meh Oct 26, 2013

Member

Shouldn't this one be removed? It's wrong.

end

def gsub(pattern, replace = undefined, &block)
Expand Down

0 comments on commit 78a2cc6

Please sign in to comment.