Skip to content

Instantly share code, notes, and snippets.

@hannahherbig
Created December 22, 2011 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannahherbig/1512257 to your computer and use it in GitHub Desktop.
Save hannahherbig/1512257 to your computer and use it in GitHub Desktop.
irc parser
module.exports = parse = (str) ->
origin = null
command = null
args = []
# pull out the origin if there is one
if str[0] is ':'
i = str.indexOf ' '
origin = str.slice 1, i
str = str.slice i + 1
# pull out the command
i = str.indexOf ' '
command = str.slice 0, i
str = str.slice i + 1
# get the args
i = str.indexOf ' :'
unless i is -1
args = (str.slice 0, i).split /\s+/
args.push str.slice i + 2
else
args = str.split /\s+/
args.origin = origin
args.command = command
args
// same as above just compiled like `coffee -bcp parse.coffee`
var parse;
module.exports = parse = function(str) {
var args, command, i, origin;
origin = null;
command = null;
args = [];
if (str[0] === ':') {
i = str.indexOf(' ');
origin = str.slice(1, i);
str = str.slice(i + 1);
}
i = str.indexOf(' ');
command = str.slice(0, i);
str = str.slice(i + 1);
i = str.indexOf(' :');
if (i !== -1) {
args = (str.slice(0, i)).split(/\s+/);
args.push(str.slice(i + 2));
} else {
args = str.split(/\s+/);
}
args.origin = origin;
args.command = command;
return args;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment