diff base/StringBits.h @ 1851:91056142abd0

Add function (cribbed from Rosegarden source) to check whether a string is valid UTF-8
author Chris Cannam
date Thu, 30 Apr 2020 14:45:24 +0100
parents 21c792334c2e
children bde22957545e
line wrap: on
line diff
--- a/base/StringBits.h	Wed Apr 29 13:25:19 2020 +0100
+++ b/base/StringBits.h	Thu Apr 30 14:45:24 2020 +0100
@@ -65,6 +65,15 @@
      * Comma-Separated Values (CSV) Files.
      */
     static QString joinDelimited(QVector<QString> row, QString delimiter);
+
+    /**
+     * Return true if the given byte array contains a valid UTF-8
+     * sequence, false if not. If isTruncated is true, the byte array
+     * will be treated as the prefix of a longer byte sequence, and
+     * any errors resulting from a multibyte code ending prematurely
+     * at the end of the array will be ignored.
+     */
+    static bool isValidUtf8(const std::string &bytes, bool isTruncated);
 };
 
 #endif