+ if (strip_trailing_newline && length && input[length - 1] == '\n')
+ {
+ length--;
+ if (length && input[length - 1] == '\r')
+ length--;
+ }
+
+ if (!check_truncations)
+ check_segmentation (input, length, true);
+ else
+ {
+ size_t test_len;
+
+ for (test_len = 0; test_len <= length; test_len++)
+ {
+ char *copy = xmemdup (input, test_len);
+ check_segmentation (copy, test_len, false);
+ free (copy);
+ }
+ }
+ free (input);
+
+ return 0;
+}
+
+static void
+check_segmentation (const char *input, size_t length, bool print_segments)
+{
+ struct segmenter s;