Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rumoji
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
rumoji
Commits
0e7b372e
Commit
0e7b372e
authored
Aug 21, 2015
by
Andrew Cantino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement encode_io with Regex
parent
817ad703
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
41 deletions
+2
-41
lib/rumoji.rb
+2
-41
No files found.
lib/rumoji.rb
View file @
0e7b372e
...
...
@@ -17,39 +17,9 @@ module Rumoji
end
def
encode_io
(
readable
,
writeable
=
StringIO
.
new
(
""
))
previous_codepoints
=
[]
readable
.
each_codepoint
do
|
codepoint
|
possible_emoji
=
Emoji
.
select_by_codepoint
(
codepoint
)
sequence
=
if
possible_emoji
.
empty?
# If this codepoint is not part of an emoji
# just write it back out, along with any previously stored codepoints.
dump_codepoints_to_string
(
previous_codepoints
<<
codepoint
)
elsif
!
possible_emoji
.
any?
(
&
:multiple?
)
# If this codepoint is part of an emoji, but not one
# that contains multiple codepoints, write out the
# first possiblity's cheat code and the previously stored codepoints
dump_codepoints_to_string
(
previous_codepoints
)
<<
possible_emoji
.
first
.
code
else
# This codepoint is a part of an emoji with multiple
# codepoints, so push it onto the stack.
previous_codepoints
.
push
(
codepoint
)
# Check and see if this completes the emoji, otherwise,
# write out an empty string.
if
found
=
possible_emoji
.
find
{
|
e
|
e
.
codepoints
.
eql?
(
previous_codepoints
)
}
previous_codepoints
.
clear
and
found
.
code
else
""
end
end
writeable
.
write
sequence
readable
.
each_line
do
|
line
|
writeable
.
write
encode
(
line
)
end
# Write any remaining codepoints.
writeable
.
write
dump_codepoints_to_string
(
previous_codepoints
)
if
previous_codepoints
.
any?
writeable
end
...
...
@@ -59,13 +29,4 @@ module Rumoji
end
writeable
end
private
def
dump_codepoints_to_string
(
codepoints
)
codepoints
.
pack
(
"U*"
).
tap
do
codepoints
.
clear
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment