summaryrefslogtreecommitdiff
path: root/source3/lib/util_str.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-09-21 17:00:07 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:00:57 -0500
commitf18c9365caaad75c0f4c9e26b89327a75cfcb3e6 (patch)
treeb5db870641dd49feb5d167b55350ecaeabd1f247 /source3/lib/util_str.c
parentb3d18b12c23670b02f4f98e1afeb32f829050fb3 (diff)
downloadsamba-f18c9365caaad75c0f4c9e26b89327a75cfcb3e6.tar.gz
samba-f18c9365caaad75c0f4c9e26b89327a75cfcb3e6.tar.bz2
samba-f18c9365caaad75c0f4c9e26b89327a75cfcb3e6.zip
r18787: Fix the strlen_m and strlen_m_term code by merging
in (and using elsewhere) next_codepoint from Samba4. Jerry please test. Jeremy. (This used to be commit ece00b70a4621633f1ac9e576c4bbe332031de09)
Diffstat (limited to 'source3/lib/util_str.c')
-rw-r--r--source3/lib/util_str.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 4619d47388..414a87a562 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -1593,6 +1593,58 @@ void strupper_m(char *s)
}
/**
+ Count the number of UCS2 characters in a string. Normally this will
+ be the same as the number of bytes in a string for single byte strings,
+ but will be different for multibyte.
+**/
+
+size_t strlen_m(const char *s)
+{
+ size_t count = 0;
+
+ if (!s) {
+ return 0;
+ }
+
+ while (*s && !(((uint8_t)*s) & 0x80)) {
+ s++;
+ count++;
+ }
+
+ if (!*s) {
+ return count;
+ }
+
+ while (*s) {
+ size_t c_size;
+ codepoint_t c = next_codepoint(s, &c_size);
+ if (c < 0x10000) {
+ /* Unicode char fits into 16 bits. */
+ count += 1;
+ } else {
+ /* Double-width unicode char - 32 bits. */
+ count += 2;
+ }
+ s += c_size;
+ }
+
+ return count;
+}
+
+/**
+ Count the number of UCS2 characters in a string including the null
+ terminator.
+**/
+
+size_t strlen_m_term(const char *s)
+{
+ if (!s) {
+ return 0;
+ }
+ return strlen_m(s) + 1;
+}
+
+/**
Return a RFC2254 binary string representation of a buffer.
Used in LDAP filters.
Caller must free.