static sv_<ss_> split_string_to_clean_ui_pieces(const ss_ &s, size_t piece_len) { sv_<ss_> result; size_t start_from = 0; for(;;){ if(start_from >= s.size()) break; size_t start_from_instead = start_from; for(size_t i=start_from; i<s.size(); i++){ if((s[i] < 'a' || s[i] > 'z') && (s[i] < 'A' || s[i] > 'Z') && (s[i] < '0' || s[i] > '9')){ start_from_instead = i + 1; continue; } break; } if(start_from_instead >= s.size()){ result.push_back(s.substr(start_from)); break; } if(start_from_instead >= s.size() - piece_len){ result.push_back(s.substr(start_from_instead)); break; } size_t end_at = start_from_instead + piece_len; if(s.size() > end_at + 2 && end_at >= 3){ if(is_spacing(s[end_at-2]) && !is_spacing(s[end_at-1]) && !is_spacing(s[end_at]) && (is_spacing(s[end_at+1]) || is_spacing(s[end_at+2]))){ end_at = end_at - 1; } else if(is_spacing(s[end_at-3]) && !is_spacing(s[end_at-2]) && !is_spacing(s[end_at-1]) && !is_spacing(s[end_at]) && (is_spacing(s[end_at+1]) || is_spacing(s[end_at+2]))){ end_at = end_at - 2; } } result.push_back(s.substr(start_from_instead, end_at - start_from_instead)); start_from = end_at; } return result; }
static ss_ truncate(const ss_ &s, size_t len) { if(s.size() < len) return s; return s.substr(0, len); }