@Test public void testMakePongIfPing() { String[][] cases = { {null, ""}, {null, "PONG"}, {null, "PINGU"}, {null, " PING"}, {null, " :abc PING"}, {null, "PING:def"}, {null, "abc WHAT PING"}, {null, "STOPPING"}, {null, ":nick!user@host PRIVMSG #chan :PING"}, {"PONG", "PING"}, {"PONG", ":prefix PING"}, {"PONG ", ":pre PING "}, {"pong", "ping"}, {"pONg", "pINg"}, {"PONG abc def", "PING abc def"}, {"PONG :hello world", "PING :hello world"}, {"PONG two :three four", ":one PING two :three four"}, {"PONG PONG PING", "PING PONG PING"}, {"pong PIng", ":PING ping PIng"}, }; for (String[] cs : cases) assertEquals(cs[0], makePong(cs[1])); }
static byte[] makePongIfPing(byte[] line) { int i = 0; if (line.length >= 1 && line[i] == ':') { i++; while (i < line.length && line[i] != ' ') i++; while (i < line.length && line[i] == ' ') i++; } byte[] reply = null; if (line.length - i >= 4 && (line[i + 0] & 0xDF) == 'P' && (line[i + 1] & 0xDF) == 'I' && (line[i + 2] & 0xDF) == 'N' && (line[i + 3] & 0xDF) == 'G' && (line.length - i == 4 || line[i + 4] == ' ')) { reply = Arrays.copyOfRange(line, i, line.length); reply[1] += 'O' - 'I'; } return reply; }
MamircConnector { static byte[] makePongIfPing(byte[] line) { int i = 0; if (line.length >= 1 && line[i] == ':') { i++; while (i < line.length && line[i] != ' ') i++; while (i < line.length && line[i] == ' ') i++; } byte[] reply = null; if (line.length - i >= 4 && (line[i + 0] & 0xDF) == 'P' && (line[i + 1] & 0xDF) == 'I' && (line[i + 2] & 0xDF) == 'N' && (line[i + 3] & 0xDF) == 'G' && (line.length - i == 4 || line[i + 4] == ' ')) { reply = Arrays.copyOfRange(line, i, line.length); reply[1] += 'O' - 'I'; } return reply; } }
MamircConnector { static byte[] makePongIfPing(byte[] line) { int i = 0; if (line.length >= 1 && line[i] == ':') { i++; while (i < line.length && line[i] != ' ') i++; while (i < line.length && line[i] == ' ') i++; } byte[] reply = null; if (line.length - i >= 4 && (line[i + 0] & 0xDF) == 'P' && (line[i + 1] & 0xDF) == 'I' && (line[i + 2] & 0xDF) == 'N' && (line[i + 3] & 0xDF) == 'G' && (line.length - i == 4 || line[i + 4] == ' ')) { reply = Arrays.copyOfRange(line, i, line.length); reply[1] += 'O' - 'I'; } return reply; } MamircConnector(BackendConfiguration config); }
MamircConnector { static byte[] makePongIfPing(byte[] line) { int i = 0; if (line.length >= 1 && line[i] == ':') { i++; while (i < line.length && line[i] != ' ') i++; while (i < line.length && line[i] == ' ') i++; } byte[] reply = null; if (line.length - i >= 4 && (line[i + 0] & 0xDF) == 'P' && (line[i + 1] & 0xDF) == 'I' && (line[i + 2] & 0xDF) == 'N' && (line[i + 3] & 0xDF) == 'G' && (line.length - i == 4 || line[i + 4] == ' ')) { reply = Arrays.copyOfRange(line, i, line.length); reply[1] += 'O' - 'I'; } return reply; } MamircConnector(BackendConfiguration config); static void main(String[] args); }
MamircConnector { static byte[] makePongIfPing(byte[] line) { int i = 0; if (line.length >= 1 && line[i] == ':') { i++; while (i < line.length && line[i] != ' ') i++; while (i < line.length && line[i] == ' ') i++; } byte[] reply = null; if (line.length - i >= 4 && (line[i + 0] & 0xDF) == 'P' && (line[i + 1] & 0xDF) == 'I' && (line[i + 2] & 0xDF) == 'N' && (line[i + 3] & 0xDF) == 'G' && (line.length - i == 4 || line[i + 4] == ' ')) { reply = Arrays.copyOfRange(line, i, line.length); reply[1] += 'O' - 'I'; } return reply; } MamircConnector(BackendConfiguration config); static void main(String[] args);  }