boolean (@NotNull CharSequence s1, @NotNull CharSequence s2) { int index1 = 0; int index2 = 0; while (true) { boolean lastLine1 = false; boolean lastLine2 = false; int end1 = Strings.indexOf(s1, '\n', index1) + 1; int end2 = Strings.indexOf(s2, '\n', index2) + 1; if (end1 == 0) { end1 = s1.length(); lastLine1 = true; } if (end2 == 0) { end2 = s2.length(); lastLine2 = true; } if (lastLine1 ^ lastLine2) return false; CharSequence line1 = s1.subSequence(index1, end1); CharSequence line2 = s2.subSequence(index2, end2); if (!Strings.equalsTrimWhitespaces(line1, line2)) return false; index1 = end1; index2 = end2; if (lastLine1) return true; } }