]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reduce duplicated code in getWrappedLine and getWrappedLineLen
authorterencehill <piuntn@gmail.com>
Thu, 31 Dec 2020 13:30:14 +0000 (14:30 +0100)
committerterencehill <piuntn@gmail.com>
Thu, 31 Dec 2020 13:42:05 +0000 (14:42 +0100)
qcsrc/common/util.qc

index ee0eb1058575e45e14db2221683793684ef15b30..27aa5f3f2d22ae923dc485fe79744fe19fd7460d 100644 (file)
@@ -940,24 +940,20 @@ string getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunc
                take = cantake - 1;
                while(take > 0 && substring(s, take, 1) != " ")
                        --take;
-               if(take == 0)
-               {
-                       getWrappedLine_remaining = substring(s, cantake, strlen(s) - cantake);
-                       if(getWrappedLine_remaining == "")
-                               getWrappedLine_remaining = string_null;
-                       else if (tw("^7", theFontSize) == 0)
-                               getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, cantake)), getWrappedLine_remaining);
-                       return substring(s, 0, cantake);
-               }
-               else
+
+               int skip = 0;
+               if(take != 0)
                {
-                       getWrappedLine_remaining = substring(s, take + 1, strlen(s) - take);
-                       if(getWrappedLine_remaining == "")
-                               getWrappedLine_remaining = string_null;
-                       else if (tw("^7", theFontSize) == 0)
-                               getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, take)), getWrappedLine_remaining);
-                       return substring(s, 0, take);
+                       cantake = take;
+                       skip = 1;
                }
+
+               getWrappedLine_remaining = substring(s, cantake + skip, strlen(s) - cantake);
+               if(getWrappedLine_remaining == "")
+                       getWrappedLine_remaining = string_null;
+               else if (tw("^7", theFontSize) == 0)
+                       getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, cantake)), getWrappedLine_remaining);
+               return substring(s, 0, cantake);
        }
        else
        {
@@ -986,24 +982,20 @@ string getWrappedLineLen(float w, textLengthUpToLength_lenFunction_t tw)
                take = cantake - 1;
                while(take > 0 && substring(s, take, 1) != " ")
                        --take;
-               if(take == 0)
-               {
-                       getWrappedLine_remaining = substring(s, cantake, strlen(s) - cantake);
-                       if(getWrappedLine_remaining == "")
-                               getWrappedLine_remaining = string_null;
-                       else if (tw("^7") == 0)
-                               getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, cantake)), getWrappedLine_remaining);
-                       return substring(s, 0, cantake);
-               }
-               else
+
+               int skip = 0;
+               if(take != 0)
                {
-                       getWrappedLine_remaining = substring(s, take + 1, strlen(s) - take);
-                       if(getWrappedLine_remaining == "")
-                               getWrappedLine_remaining = string_null;
-                       else if (tw("^7") == 0)
-                               getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, take)), getWrappedLine_remaining);
-                       return substring(s, 0, take);
+                       cantake = take;
+                       skip = 1;
                }
+
+               getWrappedLine_remaining = substring(s, cantake + skip, strlen(s) - cantake);
+               if(getWrappedLine_remaining == "")
+                       getWrappedLine_remaining = string_null;
+               else if (tw("^7") == 0)
+                       getWrappedLine_remaining = strcat(find_last_color_code(substring(s, 0, cantake)), getWrappedLine_remaining);
+               return substring(s, 0, cantake);
        }
        else
        {