#include "util/buffer-shaper.h"
#include "locale/japanese.h"
#include <algorithm>
+#include <array>
/*!
* @brief 文字列を指定した最大長を目安として分割する
std::vector<std::string> result;
std::string line;
auto separate_pos = 0U;
+ std::array<bool, 2> is_kanji{}; // [0]:現在の文字 [1]:一つ前の文字
while (line.length() < sv.length()) {
- const auto is_kanji = _(iskanji(sv[line.length()]), false);
- auto ch = sv.substr(line.length(), is_kanji ? 2 : 1);
+ is_kanji[1] = is_kanji[0];
+ is_kanji[0] = _(iskanji(sv[line.length()]), false);
+ auto ch = sv.substr(line.length(), is_kanji[0] ? 2 : 1);
const auto is_newline = ch[0] == '\n';
if ((ch.length() == 1) && !isprint(ch[0])) {
}
if ((line.length() + ch.length() >= maxlen) || is_newline) {
- if ((ch[0] == ' ') || (line.length() >= separate_pos * 2) || (is_kanji && !is_kinsoku(ch))) {
+ if ((ch[0] == ' ') || (line.length() >= separate_pos * 2) || (is_kanji[0] && !is_kinsoku(ch))) {
sv.remove_prefix(line.length());
} else {
line.erase(separate_pos);
result.push_back(std::move(line));
line.clear();
separate_pos = 0;
+ is_kanji.fill(false);
continue;
}
- if ((ch[0] == ' ') || is_kanji) {
+ if ((ch[0] == ' ') || is_kanji[0] || is_kanji[1]) {
separate_pos = line.length();
}