]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/util.qc
properly check the player name length as utf-8 octet count
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / util.qc
index 44f8751733aab62e96406a890da8cee451966806..83ea8e3e5827fedbc29f9f7534aec14f8865ca80 100644 (file)
@@ -1953,3 +1953,23 @@ float vercmp(string v1, string v2)
 
        return vercmp_recursive(v1, v2);
 }
+
+float u8_strsize(string s)
+{
+       float l, i, c;
+       l = 0;
+       for(i = 0; ; ++i)
+       {
+               c = str2chr(s, i);
+               if(c <= 0)
+                       break;
+               ++l;
+               if(c >= 0x80)
+                       ++l;
+               if(c >= 0x800)
+                       ++l;
+               if(c >= 0x10000)
+                       ++l;
+       }
+       return l;
+}