summaryrefslogtreecommitdiff
path: root/src/common/wchar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/wchar.c')
-rw-r--r--src/common/wchar.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/common/wchar.c b/src/common/wchar.c
index 6e7d731e020..0636b8765ba 100644
--- a/src/common/wchar.c
+++ b/src/common/wchar.c
@@ -1911,6 +1911,11 @@ const pg_wchar_tbl pg_wchar_table[] = {
/*
* Returns the byte length of a multibyte character.
+ *
+ * Caution: when dealing with text that is not certainly valid in the
+ * specified encoding, the result may exceed the actual remaining
+ * string length. Callers that are not prepared to deal with that
+ * should use pg_encoding_mblen_bounded() instead.
*/
int
pg_encoding_mblen(int encoding, const char *mbstr)
@@ -1921,6 +1926,16 @@ pg_encoding_mblen(int encoding, const char *mbstr)
}
/*
+ * Returns the byte length of a multibyte character; but not more than
+ * the distance to end of string.
+ */
+int
+pg_encoding_mblen_bounded(int encoding, const char *mbstr)
+{
+ return strnlen(mbstr, pg_encoding_mblen(encoding, mbstr));
+}
+
+/*
* Returns the display length of a multibyte character.
*/
int