diff src/alice/test/codesegment/local/wordcount/WordCount.java @ 243:c70cd1b2caca

remove word_count bug
author sugi
date Wed, 08 May 2013 15:43:49 +0900
parents 3bcaf12cf877
children a560b92bfd72
line wrap: on
line diff
--- a/src/alice/test/codesegment/local/wordcount/WordCount.java	Tue Apr 16 18:26:07 2013 +0900
+++ b/src/alice/test/codesegment/local/wordcount/WordCount.java	Wed May 08 15:43:49 2013 +0900
@@ -25,9 +25,9 @@
 	    int line_num = 0;
 	    
 		for (int i = r.start; i < r.end; i++) {
-			if ((char)buf.get(i) == 0x20) { // 空白                                                                                                                                       
+			if ((char)buf.get(i) == 0x20) { // 空白                                                                                                                                
 				word_flag = 1;
-			} else if ((char)buf.get(i) == 0x0A) { // 改行                                                                                                                                
+			} else if ((char)buf.get(i) == 0x0A) { // 改行
 				line_num += 1;
 				word_flag = 1;
 			} else {
@@ -35,7 +35,14 @@
 				word_flag = 0;
 			}
 		}
-
+		word_num += word_flag;
+		if (!r.flag){
+			if (((char)buf.get(r.end-1) == 0x0A||(char)buf.get(r.end-1) == 0x20) &&
+					((char)buf.get(r.end) == 0x0A||(char)buf.get(r.end) == 0x20)){
+				word_num--;
+			}
+		}
+		
 		Result result = new Result(line_num,word_num);
 		ods.put("result", result);
 	}