Created
September 24, 2017 05:45
-
-
Save vonKingsley/0b63fe714fcb5f9237dcbd0d080ff7d7 to your computer and use it in GitHub Desktop.
crystal string token binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lib LibStrToken | |
fun strtok( input : UInt8*, delim : UInt8*) : UInt8* | |
end | |
module Test | |
class Run | |
def string_token(str, del) | |
io = IO::Memory.new(str.size) | |
io << str | |
split_tok = [] of String | |
token = LibStrToken.strtok(io.to_s, del) | |
split_tok << String.new(token) | |
loop do | |
token = LibStrToken.strtok(nil, del) | |
break if token.null? | |
split_tok << String.new(token) | |
end | |
split_tok | |
end | |
end | |
end | |
puts Test::Run.new.string_token("This - is - split", " ") | |
puts Test::Run.new.string_token("This - is - split", "-") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment