add end-of-file new line detects in segment
authorPeng Wu <alexepico@gmail.com>
Mon, 18 Jul 2011 09:32:50 +0000 (17:32 +0800)
committerPeng Wu <alexepico@gmail.com>
Mon, 18 Jul 2011 09:33:05 +0000 (17:33 +0800)
utils/segment/ngseg.cpp
utils/segment/spseg.cpp

index c4853df..1e3f6c5 100644 (file)
@@ -138,7 +138,9 @@ int main(int argc, char * argv[]){
     size_t size = 0;
     ssize_t read;
     while( (read = getline(&linebuf, &size, stdin)) != -1 ){
-        linebuf[strlen(linebuf) - 1] = '\0';
+        if ( '\n' ==  linebuf[strlen(linebuf) - 1] ) {
+            linebuf[strlen(linebuf) - 1] = '\0';
+        }
 
         //check non-ucs2 characters
         const glong num_of_chars = g_utf8_strlen(linebuf, -1);
index 905991f..cec5ba2 100644 (file)
@@ -176,7 +176,9 @@ int main(int argc, char * argv[]){
     size_t size = 0;
     ssize_t read;
     while( (read = getline(&linebuf, &size, stdin)) != -1 ){
-        linebuf[strlen(linebuf) - 1] = '\0';
+        if ( '\n' ==  linebuf[strlen(linebuf) - 1] ) {
+            linebuf[strlen(linebuf) - 1] = '\0';
+        }
 
         //check non-ucs2 characters
         const glong num_of_chars = g_utf8_strlen(linebuf, -1);