validateInputLength function

String? validateInputLength(
  1. String input, {
  2. int maxChars = 100000,
  3. int maxLines = 10000,
})

Check if input exceeds length limits.

Implementation

String? validateInputLength(
  String input, {
  int maxChars = 100000,
  int maxLines = 10000,
}) {
  if (input.length > maxChars) {
    return 'Input too long: ${input.length} characters exceeds the $maxChars character limit.';
  }
  final lineCount = '\n'.allMatches(input).length + 1;
  if (lineCount > maxLines) {
    return 'Input has too many lines: $lineCount exceeds the $maxLines line limit.';
  }
  return null;
}