From: terencehill Date: Sun, 11 Aug 2019 13:28:14 +0000 (+0200) Subject: Simplify and optimize count_ordinal X-Git-Tag: xonotic-v0.8.5~1403 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3f151f4a5037c6d7c9eb6812b9dc5b5b4c706872;p=xonotic%2Fxonotic-data.pk3dir.git Simplify and optimize count_ordinal --- diff --git a/qcsrc/lib/counting.qh b/qcsrc/lib/counting.qh index b38ba9d05..c084b5efe 100644 --- a/qcsrc/lib/counting.qh +++ b/qcsrc/lib/counting.qh @@ -61,6 +61,7 @@ _("CI_THI^%d seconds"), /* third */ \ _("CI_MUL^%d seconds")) /* multi */ +// returns 1st, 2nd, 3rd, nth ordinal number from a cardinal number (integer) ERASEABLE string count_ordinal(int interval) { @@ -68,23 +69,20 @@ string count_ordinal(int interval) // to accomodate all languages unless we do a specific function for each one... // and since that's not technically feasible/practical, this is all we've got folks. - // Basically, it just allows you to represent a number or count in different ways - // depending on the number... like, with count_ordinal you can provide integers - // and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way. - if (floor((interval % 100) / 10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block + int last2digits = interval % 100; + + // numbers ending with 11, 12 and 13 don't follow the standard pattern + if (last2digits < 4 || last2digits > 20) { - // otherwise, check normally for 1st,2nd,3rd insertions - switch (interval % 10) + switch (last2digits % 10) { case 1: return sprintf(_("%dst"), interval); case 2: return sprintf(_("%dnd"), interval); case 3: return sprintf(_("%drd"), interval); - default: return sprintf(_("%dth"), interval); } } - else { return sprintf(_("%dth"), interval); } - return ""; + return sprintf(_("%dth"), interval); } ERASEABLE