message: Fix duplicate BOM filtering
diff: @@ -117,6 +117,10 @@ inline UnicodeConverter::UnicodeConverter(const std::string & encoding) {
  // Fill/detect some signature/BOM info.
  {
  + // UTF-16/UCS-2/UTF-32/UCS-4 without byte order meta-info (*LE/*BE), are considered to be in local byte order by this driver!
  + // Note, that UCS-2 and UCS-4 with byte order meta-info are not recognised by ICU.
  + // BOM bytes on encodings with fully specified byte order meta-info are accepted.
  +
  // For those encodings for which force_non_empty_signature_to_prepend_detection is false,
  // encoded_signature_to_prepend_ will be chosen only if the converter generates one itself.
  bool force_non_empty_signature_to_prepend_detection = true;
  @@ -182,7 +186,7 @@ inline UnicodeConverter::UnicodeConverter(const std::string & encoding) {
  // Detect the signature generated by the converter. Inspired by the code of ICU's uconv utility.
  std::basic_string<UChar> pivot;
  - pivot.push_back(UChar(0xFEFF)); // Pivot's signature/BOM.
  + pivot.push_back(UChar(0xFEFF)); // Pivot's signature/BOM. May cause duplicate BOM on the outpot (which is tolerable here), but also may result in outputting BOM in cases when there wouldn't be one otherwise.
  pivot.push_back(UChar(0x61)); // 'a'
  auto detect_signature = [&] (auto char_tag) {
  @@ -399,7 +403,7 @@ inline void UnicodeConverter::convertToPivot(
  target_symbols_written += target - target_prev;
  - if (
  + while (
  trim_pivot_signature &&
  !pivot_signature_trimmed &&
  (target_symbols_written * sizeof(ConverterPivotWideCharType)) >= pivot_signatures_to_trim_max_size_
  @@ -408,7 +412,7 @@ inline void UnicodeConverter::convertToPivot(
  const auto consumed_symbols = consumePivotSignatureInPlace(pivot); // pivot is not shorter than pivot_signatures_to_trim_max_size_, so even 0 is valid.
  target_symbols_written -= consumed_symbols;
  target -= consumed_symbols;
  - pivot_signature_trimmed = true;
  + pivot_signature_trimmed = (consumed_symbols == 0); // This means we may try several times, and stop only when all possible duplicate leading signatures are consumed.
  }
  if (error_code == U_BUFFER_OVERFLOW_ERROR) {
  @@ -510,7 +514,7 @@ inline void UnicodeConverter::convertFromPivot(
  target_symbols_written += target_bytes_appended / sizeof(CharType);
  - if (
  + while (
  trim_encoded_signature &&
  !encoded_signature_trimmed &&
  (target_symbols_written * sizeof(CharType)) >= encoded_signatures_to_trim_max_size_
  @@ -519,7 +523,7 @@ inline void UnicodeConverter::convertFromPivot(
  const auto consumed_symbols = consumeEncodedSignatureInPlace(encoded); // encoded is not shorter than encoded_signatures_to_trim_max_size_, so even 0 is valid.
  target_symbols_written -= consumed_symbols;
  target -= consumed_symbols * sizeof(CharType);
  - encoded_signature_trimmed = true;
  + encoded_signature_trimmed = (consumed_symbols == 0); // This means we may try several times, and stop only when all possible duplicate leading signatures are consumed.
  }
  if (error_code == U_BUFFER_OVERFLOW_ERROR) {
  