checkCharset static method

void checkCharset(
  1. String input,
  2. int max,
  3. String errorMessage
)

Check if input is only made of characters between 0 and the upper limit @param input the input @param max the upper limit for charset @param errorMessage the message to explain the error @throws WriterException exception highlighting the offending character and a suggestion to avoid the error

Implementation

static void checkCharset(String input, int max, String errorMessage) {
  for (int i = 0; i < input.length; i++) {
    if (input.codeUnitAt(i) > max) {
      throw WriterException(
        'Non-encodable character detected: ${input[i]} (Unicode: ${input.codeUnitAt(i)}) at position #$i - $errorMessage',
      );
    }
  }
}