From 680955c4d214098f1eb599fa9b1a173d70d32fd0 Mon Sep 17 00:00:00 2001 From: yukihane Date: Mon, 12 Sep 2011 12:52:23 +0900 Subject: [PATCH] =?utf8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF?= =?utf8?q?=E3=83=AA=E3=83=B3=E3=82=B0.=20PMD=E8=AD=A6=E5=91=8A=E9=99=A4?= =?utf8?q?=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- frontend/src/saccubus/conv/NicoXMLReader.java | 62 +++++++++++++-------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/frontend/src/saccubus/conv/NicoXMLReader.java b/frontend/src/saccubus/conv/NicoXMLReader.java index 5960feb..a3c87e6 100644 --- a/frontend/src/saccubus/conv/NicoXMLReader.java +++ b/frontend/src/saccubus/conv/NicoXMLReader.java @@ -46,57 +46,57 @@ public class NicoXMLReader extends DefaultHandler { if (word == null || word.length() <= 0) { return null; } - String tmp[] = word.split(" "); + final String tmp[] = word.split(" "); String tmp2[] = new String[tmp.length]; int tmp_index = 0; int index; for (index = 0; index < tmp.length && tmp_index < tmp.length; index++) { if (tmp[tmp_index].startsWith("/")) { - String str = tmp[tmp_index]; + final StringBuilder str = new StringBuilder(tmp[tmp_index]); for (tmp_index++; tmp_index < tmp.length; tmp_index++) { - str += " " + tmp[tmp_index]; + str.append(" ").append(tmp[tmp_index]); if (tmp[tmp_index].endsWith("/")) { tmp_index++; break; } } - tmp2[index] = str; + tmp2[index] = str.toString(); } else if (tmp[tmp_index].startsWith("\"")) { - String str = tmp[tmp_index]; + final StringBuilder str = new StringBuilder(tmp[tmp_index]); for (tmp_index++; tmp_index < tmp.length; tmp_index++) { - str += " " + tmp[tmp_index]; + str.append(" ").append(tmp[tmp_index]); if (tmp[tmp_index].endsWith("\"")) { tmp_index++; break; } } - tmp2[index] = str; + tmp2[index] = str.toString(); } else { tmp2[index] = tmp[tmp_index]; tmp_index++; } } - String elt[] = new String[index]; + final String elt[] = new String[index]; System.arraycopy(tmp2, 0, elt, 0, index); - String reg = ""; + final StringBuilder reg = new StringBuilder(); for (int i = 0; i < elt.length; i++) { - String e = elt[i]; + final String e = elt[i]; System.out.println(e); if (i > 0) { - reg += "|"; + reg.append("|"); } - if (e.indexOf("/") == 0 && e.lastIndexOf("/") == e.length() - 1) { - reg += "(" + e.substring(1, e.length() - 1) + ")"; - } else if (e.indexOf("\"") == 0 - && e.lastIndexOf("\"") == e.length() - 1) { - reg += "(" + Pattern.quote(e.substring(1, e.length() - 1)) - + ")"; + if (e.indexOf('/') == 0 && e.lastIndexOf('/') == e.length() - 1) { + reg.append("(").append(e.substring(1, e.length() - 1)).append(")"); + } else if (e.indexOf('\"') == 0 + && e.lastIndexOf('\"') == e.length() - 1) { + reg.append("(").append(Pattern.quote(e.substring(1, e.length() - 1))) + .append(")"); } else { - reg += "(.*(" + Pattern.quote(e) + ")+.*)"; + reg.append("(.*(").append(Pattern.quote(e)).append(")+.*)"); } } System.out.println("reg:" + reg); - return Pattern.compile(reg); + return Pattern.compile(reg.toString()); } private static boolean match(Pattern pat, String word) { @@ -126,27 +126,27 @@ public class NicoXMLReader extends DefaultHandler { * Attributes */ @Override - public void startElement(String uri, String localName, String qName, - Attributes attributes) { - if (qName.toLowerCase().equals("chat")) { + public void startElement(final String uri, final String localName, final String qName, + final Attributes attributes) { + if (qName.equalsIgnoreCase("chat")) { // System.out.println("----------"); item = new Chat(); item_kicked = false; //マイメモリ削除対象 - String deleted = attributes.getValue("deleted"); - if(deleted != null && deleted.toLowerCase().equals("1")){ + final String deleted = attributes.getValue("deleted"); + if(deleted != null && deleted.equalsIgnoreCase("1")){ item_kicked = true; return; } item.setDate(attributes.getValue("date")); - String mail = attributes.getValue("mail"); + final String mail = attributes.getValue("mail"); if (match(NG_Word, mail)) { item_kicked = true; return; } item.setMail(mail); item.setNo(attributes.getValue("no")); - String user_id = attributes.getValue("user_id"); + final String user_id = attributes.getValue("user_id"); if (match(NG_ID, user_id)) { item_kicked = true; return; @@ -167,15 +167,15 @@ public class NicoXMLReader extends DefaultHandler { * int */ @Override - public void characters(char[] ch, int offset, int length) { - char input[] = (new String(ch, offset, length)).toCharArray(); + public void characters(final char[] ch, final int offset, final int length) { + final char input[] = (new String(ch, offset, length)).toCharArray(); for (int i = 0; i < input.length; i++) { if (!Character.isDefined(input[i])) { input[i] = '?'; } } if (item != null) { - String com = new String(input); + final String com = new String(input); if (match(NG_Word, com)) { item_kicked = true; return; @@ -194,8 +194,8 @@ public class NicoXMLReader extends DefaultHandler { * String */ @Override - public void endElement(String uri, String localName, String qName) { - if (qName.toLowerCase().equals("chat")) { + public void endElement(final String uri, final String localName, final String qName) { + if (qName.equalsIgnoreCase("chat")) { if (!item_kicked) { Packet.addChat(item); } -- 2.11.0