]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_cmds.c
new menu QC builtin "stringwidth(string text, float handleColors)", does not do anyth...
[xonotic/darkplaces.git] / prvm_cmds.c
index 6276252c0f50d46d6e26786e75a896968b027956..1c7f42330487338afd692bd696363af5b07d9011 100644 (file)
@@ -1900,12 +1900,13 @@ void VM_strreplace(void)
        replace_len = (int)strlen(replace);
        subject_len = (int)strlen(subject);
 
+       si = 0;
        for (i = 0; i < subject_len; i++)
        {
                for (j = 0; j < search_len && i+j < subject_len; j++)
                        if (subject[i+j] != search[j])
                                break;
-               if (j == search_len)
+               if (j == search_len || i+j == subject_len)
                {
                // found it at offset 'i'
                        for (j = 0; j < replace_len && si < (int)sizeof(string) - 1; j++)
@@ -1949,12 +1950,13 @@ void VM_strireplace(void)
        replace_len = (int)strlen(replace);
        subject_len = (int)strlen(subject);
 
+       si = 0;
        for (i = 0; i < subject_len; i++)
        {
                for (j = 0; j < search_len && i+j < subject_len; j++)
                        if (tolower(subject[i+j]) != tolower(search[j]))
                                break;
-               if (j == search_len)
+               if (j == search_len || i+j == subject_len)
                {
                // found it at offset 'i'
                        for (j = 0; j < replace_len && si < (int)sizeof(string) - 1; j++)
@@ -2727,6 +2729,24 @@ void VM_drawcolorcodedstring(void)
 }
 /*
 =========
+VM_stringwidth
+
+float  stringwidth(string text, float allowColorCodes)
+=========
+*/
+void VM_stringwidth(void)
+{
+       const char  *string;
+       int colors;
+       VM_SAFEPARMCOUNT(2,VM_drawstring);
+
+       string = PRVM_G_STRING(OFS_PARM0);
+       colors = (int)PRVM_G_FLOAT(OFS_PARM1);
+
+       PRVM_G_FLOAT(OFS_RETURN) = DrawQ_String(0, 0, string, 0, 1, 1, 0, 0, 0, 0, 0, NULL, !colors); // 1x1 characters, don't actually draw
+}
+/*
+=========
 VM_drawpic
 
 float  drawpic(vector position, string pic, vector size, vector rgb, float alpha, float flag)