[英]Java - How to parse irc message to human readable
I am creating an irc client in Java. 我正在用Java创建一个irc客户端。 It work fine but the message from the server is a bit "messed-up" for example
:User1!webirc@1.9.com PRIVMSG #channel :test
. 它工作正常,但是来自服务器的消息有点“混乱”,例如
:User1!webirc@1.9.com PRIVMSG #channel :test
。 So i wanna know how to parse the irc message to human readable? 所以我想知道如何将irc消息解析为人类可读? Here is a regex that i found
^(:(\\\\S+) )?(\\\\S+)( (?!:)(.+?))?( :(.+))?$
for irc message. 这是我发现
^(:(\\\\S+) )?(\\\\S+)( (?!:)(.+?))?( :(.+))?$
的正则表达式。
The IRC Protocol is documented here: https://tools.ietf.org/html/rfc2812 IRC协议记录在这里: https : //tools.ietf.org/html/rfc2812
2.3.1 Message format in Augmented BNF
2.3.1增强BNF中的消息格式
The protocol messages must be extracted from the contiguous stream of octets.
协议消息必须从连续的八位字节流中提取。 The current solution is to designate two characters, CR and LF, as message separators.
当前的解决方案是指定两个字符CR和LF作为消息分隔符。 Empty messages are silently ignored, which permits use of the sequence CR-LF between messages without extra problems.
空消息将被静默忽略,这允许在消息之间使用序列CR-LF,而不会带来额外的问题。
The extracted message is parsed into the components , and list of parameters ().
提取的消息被解析为components和参数列表()。
The Augmented BNF representation for this is:
message = [ ":" prefix SPACE ] command [ params ] crlf
prefix = servername / ( nickname [ [ "!" user ] "@" host ] )
command = 1*letter / 3digit
params = *14( SPACE middle ) [ SPACE ":" trailing ]
=/ 14( SPACE middle ) [ SPACE [ ":" ] trailing ]
nospcrlfcl = %x01-09 / %x0B-0C / %x0E-1F / %x21-39 / %x3B-FF
; any octet except NUL, CR, LF, " " and ":"
middle = nospcrlfcl *( ":" / nospcrlfcl )
trailing = *( ":" / " " / nospcrlfcl )
SPACE = %x20 ; space character
crlf = %x0D %x0A ; "carriage return" "linefeed"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.