Skip to content

Commit

Permalink
use the latest okjson
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan R. Smith (ace hacker) committed Mar 12, 2012
1 parent 846ab49 commit 8a8d65f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
3 changes: 3 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 1.0.2
- update to latest okjson as the current has bugs

Version 1.0.1
- using OkJson instead of any sort of rubygem
- remove html from docs
Expand Down
55 changes: 40 additions & 15 deletions lib/queue_classic/okjson.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module QC
# Copyright 2011 Keith Rarick
# encoding: UTF-8
#
# Copyright 2011, 2012 Keith Rarick
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -261,6 +263,12 @@ def abbrev(s)
def unquote(q)
q = q[1...-1]
a = q.dup # allocate a big enough string
rubydoesenc = false
# In ruby >= 1.9, a[w] is a codepoint, not a byte.
if a.class.method_defined?(:force_encoding)
a.force_encoding('UTF-8')
rubydoesenc = true
end
r, w = 0, 0
while r < q.length
c = q[r]
Expand Down Expand Up @@ -298,7 +306,12 @@ def unquote(q)
end
end
end
w += ucharenc(a, w, uchar)
if rubydoesenc
a[w] = '' << uchar
w += 1
else
w += ucharenc(a, w, uchar)
end
else
raise Error, "invalid escape char #{q[r]} in \"#{q}\""
end
Expand All @@ -308,6 +321,8 @@ def unquote(q)
# Copy anything else byte-for-byte.
# Valid UTF-8 will remain valid UTF-8.
# Invalid UTF-8 will remain invalid UTF-8.
# In ruby >= 1.9, c is a codepoint, not a byte,
# in which case this is still what we want.
a[w] = c
r += 1
w += 1
Expand Down Expand Up @@ -442,6 +457,10 @@ def strenc(s)
t = StringIO.new
t.putc(?")
r = 0

# In ruby >= 1.9, s[r] is a codepoint, not a byte.
rubydoesenc = s.class.method_defined?(:encoding)

while r < s.length
case s[r]
when ?" then t.print('\\"')
Expand All @@ -456,21 +475,13 @@ def strenc(s)
case true
when Spc <= c && c <= ?~
t.putc(c)
when true
when rubydoesenc
u = c.ord
surrenc(t, u)
else
u, size = uchardec(s, r)
r += size - 1 # we add one more at the bottom of the loop
if u < 0x10000
t.print('\\u')
hexenc4(t, u)
else
u1, u2 = unsubst(u)
t.print('\\u')
hexenc4(t, u1)
t.print('\\u')
hexenc4(t, u2)
end
else
# invalid byte; skip it
surrenc(t, u)
end
end
r += 1
Expand All @@ -480,6 +491,20 @@ def strenc(s)
end


def surrenc(t, u)
if u < 0x10000
t.print('\\u')
hexenc4(t, u)
else
u1, u2 = unsubst(u)
t.print('\\u')
hexenc4(t, u1)
t.print('\\u')
hexenc4(t, u2)
end
end


def hexenc4(t, u)
t.putc(Hex[(u>>12)&0xf])
t.putc(Hex[(u>>8)&0xf])
Expand Down
2 changes: 1 addition & 1 deletion queue_classic.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'queue_classic'
s.email = '[email protected]'
s.version = '1.0.1'
s.version = '1.0.2'
s.date = '2011-08-22'
s.description = "queue_classic is a queueing library for Ruby apps. (Rails, Sinatra, Etc...) queue_classic features asynchronous job polling, database maintained locks and no ridiculous dependencies. As a matter of fact, queue_classic only requires pg."
s.summary = "postgres backed queue"
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# queue_classic
v1.0.0

v1.0.2

queue_classic is a PostgreSQL-backed queueing library that is focused on
concurrent job locking, minimizing database load & providing a simple &
Expand Down

0 comments on commit 8a8d65f

Please sign in to comment.