From c87e5cef11df74817926d4cd097bbb49796684d3 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 18 Jul 2011 17:32:50 +0800 Subject: add end-of-file new line detects in segment --- utils/segment/ngseg.cpp | 4 +++- utils/segment/spseg.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/segment/ngseg.cpp b/utils/segment/ngseg.cpp index c4853df..1e3f6c5 100644 --- a/utils/segment/ngseg.cpp +++ b/utils/segment/ngseg.cpp @@ -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); diff --git a/utils/segment/spseg.cpp b/utils/segment/spseg.cpp index 905991f..cec5ba2 100644 --- a/utils/segment/spseg.cpp +++ b/utils/segment/spseg.cpp @@ -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); -- cgit