From 147171ca843f3e90a20480ea35498a81e5ea29e5 Mon Sep 17 00:00:00 2001 From: terencehill Date: Thu, 31 Dec 2020 14:30:14 +0100 Subject: [PATCH] Reduce duplicated code in getWrappedLine and getWrappedLineLen --- qcsrc/common/util.qc | 56 +++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) 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 { -- 2.39.2