Skip to content

Commit

Permalink
support UTF-8 and ruby1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
ohac committed Apr 24, 2012
1 parent 9094544 commit a55a424
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/rencode.rb
@@ -1,3 +1,4 @@
# coding: utf-8
require 'rubygems'

module REncode
Expand Down Expand Up @@ -107,7 +108,7 @@ class DecodeError < StandardError
n = x[f, colon - f].to_i
raise DecodeError if x[f, 1] == '0' and colon != f+1
colon += 1
s = x[colon, n] # TODO support UTF-8
s = x[colon, n].force_encoding('UTF-8')
[s, colon+n]
end

Expand Down Expand Up @@ -168,7 +169,7 @@ class DecodeError < StandardError
def self.make_fixed_length_string_decoders()
STR_FIXED_COUNT.times do |i|
@decode_func[(STR_FIXED_START+i).chr] = lambda {|x, f|
s = x[f+1, i] # TODO support UTF-8
s = x[f+1, i].force_encoding('UTF-8')
[s, f+1+i]
}
end
Expand Down Expand Up @@ -267,11 +268,11 @@ class EncodeError < StandardError
end

encode_string = lambda do |x, r|
# TODO support UTF-8
if x.size < STR_FIXED_COUNT
r << (STR_FIXED_START + x.size).chr << x
size = x.unpack('C*').size
if size < STR_FIXED_COUNT
r << (STR_FIXED_START + size).chr << x
else
r << x.size.to_s << ':' << x
r << size.to_s << ':' << x
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/torrentsync.rb
@@ -1,3 +1,4 @@
# coding: utf-8
require 'rubygems'
require 'nokogiri'
require 'net/http'
Expand Down

0 comments on commit a55a424

Please sign in to comment.