X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Funicode%2Funicodeformatter.cpp;h=f017fa2d55120af6c2996e5e5111a5e64198a2d5;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=c89cc7c65ceffdbb95927fc35b2e5413df9b4a11;hpb=56f67ecca96efc7b72d03c95c8c42cfb66e31468;p=fms.git diff --git a/src/unicode/unicodeformatter.cpp b/src/unicode/unicodeformatter.cpp index c89cc7c..f017fa2 100644 --- a/src/unicode/unicodeformatter.cpp +++ b/src/unicode/unicodeformatter.cpp @@ -2,7 +2,7 @@ #include "../../include/unicode/utfconversion.h" std::wstring UnicodeFormatter::m_unicodenewline=L"\n"; -wchar_t UnicodeFormatter::m_unicodewhitespace[]={0x0009,0x000A,0x000B,0x000C,0x000D, +std::wstring::value_type UnicodeFormatter::m_unicodewhitespace[]={0x0009,0x000A,0x000B,0x000C,0x000D, 0x0020,0x0085,0x00A0,0x1680,0x180E, 0x2000,0x2001,0x2002,0x2003,0x2004, 0x2005,0x2006,0x2007,0x2008,0x2009, @@ -11,8 +11,8 @@ wchar_t UnicodeFormatter::m_unicodewhitespace[]={0x0009,0x000A,0x000B,0x000C,0x0 const bool UnicodeFormatter::LineWrap(const std::string &utf8input, const int linelength, const std::string &ignorechars, std::string &utf8output) { - std::wstring wcstring; - std::wstring wcignorechars; + std::wstring wcstring=L""; + std::wstring wcignorechars=L""; if(UTFConversion::FromUTF8(utf8input,wcstring) && UTFConversion::FromUTF8(ignorechars,wcignorechars)) { @@ -26,33 +26,24 @@ const bool UnicodeFormatter::LineWrap(const std::string &utf8input, const int li if(ignorechars.size()==0 || wcstring.find_first_of(wcignorechars,currentpos)!=currentpos) { lastnewlinepos=wcstring.rfind(m_unicodenewline,currentpos+linelength); + whitespacepos=wcstring.find_last_of(m_unicodewhitespace,currentpos+linelength); // newline found within line length - we don't need to wrap if(lastnewlinepos!=std::wstring::npos && lastnewlinepos>=currentpos) { currentpos=lastnewlinepos+1; } - // newline doesn't exist at all - force one in - else if(lastnewlinepos==std::wstring::npos) + // whitespace found within line length - erase whitespace and insert newline + else if((lastnewlinepos=currentpos) { - wcstring.insert(currentpos+linelength,m_unicodenewline); - currentpos+=linelength+m_unicodenewline.length(); + wcstring.erase(whitespacepos,1); + wcstring.insert(whitespacepos,m_unicodenewline); + currentpos=whitespacepos+m_unicodenewline.length(); } + // whitespace or newline not found within line length - force newline at line length else { - whitespacepos=wcstring.find_last_of(m_unicodewhitespace,currentpos+linelength); - // whitespace found within line length - erase whitespace and insert newline - if(whitespacepos!=std::wstring::npos && whitespacepos>=currentpos) - { - wcstring.erase(whitespacepos,1); - wcstring.insert(whitespacepos,m_unicodenewline); - currentpos=whitespacepos+m_unicodenewline.length(); - } - // whitespace not found within line length - force newline at line length - else - { - wcstring.insert(currentpos+linelength,m_unicodenewline); - currentpos+=linelength+m_unicodenewline.length(); - } + wcstring.insert(currentpos+linelength,m_unicodenewline); + currentpos+=linelength+m_unicodenewline.length(); } } else