utf8を一定文字数ごとに改行する。
その際、行頭に「、」や「。」がこないように改行をいれる。
バイト数チェックはjanssonライブラリのutf.hを使うべし。
https://github.com/akheron/jansson/blob/master/src/utf.h
aho.cpp
# include "utf.h"
//descriptionを17文字ずつ改行
//行数を返す
int TextHelper::descriptionR(std::string *description) {
int lines = 1;
int cnt = 0;
const char *c = description->c_str();
std::stringstream stream;
int32_t codePoint = 0;
char buf[4];
int size;
const char *next = utf8_iterate(c, &codePoint);
bool pass = false;
while (next[0] != '\0') {
ASSERT(!utf8_encode(codePoint, buf, &size), "not false");
c+= size;
for(int i = 0; i<size; i++){
stream << buf[i];
}
if (cnt++ > 16) {
next = utf8_iterate(c, &codePoint);
ASSERT(!utf8_encode(codePoint, buf, &size), "not false");
if(codePoint == 0x3001 || codePoint == 0x3002){
c+= size;
for(int i = 0; i<size; i++){
stream << buf[i];
}
}
cnt = 0;
stream << '\n';
lines++;
if(next[0]== '\0')goto __skip;
}
next = utf8_iterate(c, &codePoint);
}
ASSERT(!utf8_encode(codePoint, buf, &size), "not false2");
for(int i = 0; i<size; i++){
stream << buf[i];
}
__skip:
*description = stream.str();
return lines;
}