From: terencehill Date: Thu, 31 Dec 2020 13:30:14 +0000 (+0100) Subject: Reduce duplicated code in getWrappedLine and getWrappedLineLen X-Git-Tag: xonotic-v0.8.5~614 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=147171ca843f3e90a20480ea35498a81e5ea29e5;p=xonotic%2Fxonotic-data.pk3dir.git Reduce duplicated code in getWrappedLine and getWrappedLineLen --- diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index ee0eb1058..27aa5f3f2 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -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 {