[pulseaudio-commits] r1673 - in /branches/lennart/src/pulsecore: core-util.c core-util.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu Aug 16 06:46:33 PDT 2007


Author: lennart
Date: Thu Aug 16 15:46:32 2007
New Revision: 1673

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1673&root=3Dpulseaudio&vi=
ew=3Drev
Log:
add pa_truncate_utf8() function for truncating a string and guaranteeing it=
 stays valid UTF8 afterwards

Modified:
    branches/lennart/src/pulsecore/core-util.c
    branches/lennart/src/pulsecore/core-util.h

Modified: branches/lennart/src/pulsecore/core-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
core-util.c?rev=3D1673&root=3Dpulseaudio&r1=3D1672&r2=3D1673&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/core-util.c (original)
+++ branches/lennart/src/pulsecore/core-util.c Thu Aug 16 15:46:32 2007
@@ -78,6 +78,7 @@
 =

 #include <pulse/xmalloc.h>
 #include <pulse/util.h>
+#include <pulse/utf8.h>
 =

 #include <pulsecore/core-error.h>
 #include <pulsecore/winsock.h>
@@ -1223,3 +1224,20 @@
 =

     return ret;
 }
+
+/* Truncate the specified string, but guarantee that the string
+ * returned still validates as UTF8 */
+char *pa_truncate_utf8(char *c, size_t l) {
+    pa_assert(c);
+    pa_assert(pa_utf8_valid(c));
+
+    if (strlen(c) <=3D l)
+        return c;
+
+    c[l] =3D 0;
+
+    while (l > 0 && !pa_utf8_valid(c))
+        c[--l] =3D 0;
+    =

+    return c;
+}

Modified: branches/lennart/src/pulsecore/core-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
core-util.h?rev=3D1673&root=3Dpulseaudio&r1=3D1672&r2=3D1673&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/core-util.h (original)
+++ branches/lennart/src/pulsecore/core-util.h Thu Aug 16 15:46:32 2007
@@ -94,4 +94,6 @@
 =

 int pa_snprintf(char *str, size_t size, const char *format, ...);
 =

+char *pa_truncate_utf8(char *c, size_t l);
+
 #endif




More information about the pulseaudio-commits mailing list