public class IRCParser extends Object
Note: Probably this class is unimportant for you. It's used by the
IRCConnection to parse incoming lines. Nevertheless I declared
it as public because you might want to use it to parse IRC
command-shortcuts like MSG instead of PRIVMSG in
your client.
The following text goes on with the description of the class and what it
does.
According with RFC1459 it divides the line into a prefix, a command and its parameters.
The prefix is only given if a line starts with a : (colon)
and is used to indicate from where the line is send.
The next word in the line (if no prefix exists it is the first, else the second word) is the command. The command is eiter a valid IRC command or a three-digit number which represents a numeric reply or a numeric error.
The parameters are divided into a middle and a trailing part.
In the middle part one word means one parameter while the trailing part is
just one parameter independent from the amount of words in it.
If there is a " :" (space+colon) in the line, this point
means the beginning of the trailing.
If there is no such space+colon, the trailing is just the last word.
All words behind the space+colon mean just one parameter.
If there is only one parameter given (the parameter is the first, the last
and the only one), the parameter is available as trailing (with
getTrailing), not as middle!
One line may have up to 15 parameters. Therefore up to 14 are middle and one is the trailing.
The line may have up to 510 characters plus the CR-LF (carriage return - line feed) which trails the incoming line.
The following extract of the RFC1459 shows the message format in BNF:
<message> ::=
[':' <prefix> <SPACE> ] <command> <params>
<crlf>
<prefix> ::=
<servername> | <nick>
[ '!' <username> ] [ '@' <host> ]
<command> ::=
<letter> { <letter> } | <number> <number>
<number>
<SPACE> ::=
' ' { ' ' }
<params> ::=
<SPACE> [ ':' <trailing> | <middle> <params> ]
<middle> ::=
<Any *non-empty* sequence of octets not including SPACE or NUL or CR or
LF, the first of which may not be ':'>
<trailing> ::=
<Any, possibly *empty*, sequence of octets not including NUL or CR or
LF>
<crlf> ::=
CR LF
DefaultIRCConnection| Constructor and Description |
|---|
IRCParser(String line)
Parses the line after erasing all mIRC color codes.
|
IRCParser(String line,
boolean stripColors)
The main constructor.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getCommand()
Returns the line's command.
|
String |
getHost()
Returns the host of the person who sent the line.
|
String |
getLine()
Returns the unparsed line.
|
String |
getMiddle()
Returns the line's middle.
|
String |
getNick()
Returns the nickname of the person who sent the line
or the servername of the server which sent the line.
|
String |
getParameter(int i)
Get one parameter of the line.
|
int |
getParameterCount()
Gets count of parameters.
|
String |
getParameters()
Returns the line's parameters which consists of the middle and the
trailing.
|
String |
getParametersFrom(int i)
Grabs the line's parameters from the
ith to the last
parameter (including the ith). |
String |
getParametersTo(int i)
Grabs the line's parameters from the first to the
ith
parameters (including the ith). |
String |
getPrefix()
Returns the line's prefix.
|
String |
getServername()
Returns the servername of the server which sent the line
or the nickname of the person who sent the line.
|
String |
getTrailing()
Returns the line's trailing.
|
IRCUser |
getUser()
Returns a new
IRCUser object. |
String |
getUsername()
Returns the username of the person who sent the line.
|
String |
toString()
Generates a
String with some information about the instance of
IRCParser. |
public IRCParser(String line)
IRCParser(line, false).line - The line which will be parsed.public IRCParser(String line, boolean stripColors)
line - The line which will be parsed.stripColors - If true, mIRC color codes are parsed out
by using IRCUtil.stripColorsAndCTCPDelimiters(StringBuilder) method.public String getPrefix()
"" is
returned; but in fact there's always a prefix.public String getCommand()
public String getMiddle()
public String getTrailing()
public String getLine()
IRCUtil.stripColorsAndCTCPDelimiters(StringBuilder), the colors are not included in here.public String getParameters()
public String getNick()
<servername> | <nick>
[ '!' <username> ] [ '@' <host> ]
If no prefix is given in the whole line, null is returned.
Note: This method is totally equal to getServername!
Note: There is also the method getUser which returns
an IRCUser object which holds the nickname, username and host.
By the way, the getUser uses the getNick,
getUsername and getHost methods to create this
object.null is returned.getServername(),
getUsername(),
getHost(),
getUser()public String getServername()
<servername> | <nick>
[ '!' <username> ] [ '@' <host> ]
If no prefix is given in the whole line, null is returned.
Note: This method is totally equal to getNick!
Note: There is also the method getUser which returns
an IRCUser object which holds the nickname, username and host.
By the way, the getUser uses the getNick,
getUsername and getHost methods to create this
object.public String getUsername()
<servername> | <nick>
[ '!' <username> ] [ '@' <host> ]
If the username is not specified, this method returns null.
Note: There is also the method getUser which returns
an IRCUser object which holds the nickname, username and host.
By the way, the getUser uses the getNick,
getUsername and getHost methods to create this
object.public String getHost()
<servername> | <nick>
[ '!' <username> ] [ '@' <host> ]
If the host is not specified, this method returns null.
Note: There is also the method getUser which returns
an IRCUser object which holds the nickname, username and host.
By the way, the getUser uses the getNick,
getUsername and getHost methods to create this
object.null if it's not given.getNick(),
getUsername(),
getUser()public IRCUser getUser()
IRCUser object.
This method is equal to new IRCUser(IRCParser.getNick(),
IRCParser.getUsername(), IRCParser.getHost()). See those methods to
learn which value they return if they are not set.IRCUser object with exactly those values which
are returned by the getNick, getUsername
and getHost methods.getNick(),
getUsername(),
getHost()public int getParameterCount()
parameters isn't initialized yet, it calls
initParameters to do that.public String getParameter(int i)
parameters isn't initialized yet, it calls
initParameters to do that.i - The index of the parameter you want to get. The index starts with
1 and not with 0.ith parameter. If i is out of bounds,
"" is returned.public String getParametersFrom(int i)
ith to the last
parameter (including the ith).
If parameters isn't initialized yet, it calls
initParameters to do that.i - The index of the first parameter you want to get.ith.
If i is out of bounds, "" is returned.public String getParametersTo(int i)
ith
parameters (including the ith).
If parameters isn't initialized yet, it calls
initParameters to do that.i - The index of the last parameter you want to get.ith. If i is out of bounds,
"" is returned.Copyright © 2006–2015. All rights reserved.