out.fill('0');
unsigned per = 16;
- bool was_zeros = false, did_star = false;
+ char last_row_char = '\0';
+ bool was_same = false, did_star = false;
for (unsigned o=0; o<length(); o += per) {
+ if (o == 0) {
+ last_row_char = (*this)[o];
+ }
+
if (o + per < length()) {
- bool row_is_zeros = true;
+ bool row_is_same = true;
for (unsigned i=0; i<per && o+i<length(); i++) {
- if ((*this)[o+i]) {
- row_is_zeros = false;
+ char current_char = (*this)[o+i];
+ if (current_char != last_row_char) {
+ if (i == 0) {
+ last_row_char = current_char;
+ was_same = false;
+ did_star = false;
+ } else {
+ row_is_same = false;
+ }
}
}
- if (row_is_zeros) {
- if (was_zeros) {
+ if (row_is_same) {
+ if (was_same) {
if (!did_star) {
out << "\n*";
did_star = true;
}
continue;
}
- was_zeros = true;
+ was_same = true;
} else {
- was_zeros = false;
+ was_same = false;
did_star = false;
}
}