From f6506e34a84256f0620ee97559bf415c27b9974c Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 27 May 2009 11:39:43 +0000 Subject: Fixed error in linesplitter (utf8 characters fucked up pretty good) --- server/src/journal_commit.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'server/src') diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc index f74e54e..4992545 100644 --- a/server/src/journal_commit.cc +++ b/server/src/journal_commit.cc @@ -52,6 +52,11 @@ #include "template.h" #include "templateparser.h" +static inline bool iswhitespace(char c) +{ + return c == ' ' || c == '\n' || c == '\t'; +} + /** * Remove all spaces, tabs and newline trailing the string. */ @@ -61,7 +66,9 @@ static std::string stripTrailingWhitepace(std::string str) ssize_t end = str.size() - 1; - while(end && str[end] <= ' ') { // Every below SPACE 0x20 is consideret whitespace. + while(end && iswhitespace(str[end]) + && (end>0 && str[end-1] & 0x80) == false // Make sure we are not in a utf8 character. + ) { end--; } end++; @@ -83,7 +90,9 @@ static std::string addNewlines(std::string str, size_t width) fraction += str[i]; - if(str[i] <= ' ') { + if(iswhitespace(str[i]) + && (i>0 && str[i-1] & 0x80) == false // Make sure we are not in a utf8 character. + ) { if(linelen + fraction.size() > width) { output[output.size() - 1] = '\n'; linelen = 0; -- cgit v1.2.3