X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fcounting.qh;h=c084b5efe3a417b557202228d2b19ad98bf06a41;hb=c05104bde1e758c4022f9755f02f177aa0476134;hp=11c06822edfd73767f86dc721219ce552429554f;hpb=63560c3eeed26980676e412a4dd7863f2edcc922;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/counting.qh b/qcsrc/lib/counting.qh index 11c06822e..c084b5efe 100644 --- a/qcsrc/lib/counting.qh +++ b/qcsrc/lib/counting.qh @@ -61,33 +61,31 @@ _("CI_THI^%d seconds"), /* third */ \ _("CI_MUL^%d seconds")) /* multi */ -[[eraseable]] +// returns 1st, 2nd, 3rd, nth ordinal number from a cardinal number (integer) +ERASEABLE string count_ordinal(int interval) { // This function is designed primarily for the English language, it's impossible // 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]] +ERASEABLE string count_fill(float interval, string zeroth, string first, string second, string third, string multi) { // This function is designed primarily for the English language, it's impossible @@ -118,7 +116,7 @@ string count_fill(float interval, string zeroth, string first, string second, st return ""; } -[[eraseable]] +ERASEABLE string process_time(float outputtype, float seconds) { float tmp_hours = 0, tmp_minutes = 0, tmp_seconds = 0; @@ -166,42 +164,37 @@ string process_time(float outputtype, float seconds) if (tmp_minutes) { - output = sprintf( - "%s%s", + output = strcat( count_minutes(tmp_minutes), - ((output != "") ? sprintf(", %s", output) : "")); + ((output != "") ? strcat(", ", output) : "")); } if (tmp_hours) { - output = sprintf( - "%s%s", + output = strcat( count_hours(tmp_hours), - ((output != "") ? sprintf(", %s", output) : "")); + ((output != "") ? strcat(", ", output) : "")); } if (tmp_days) { - output = sprintf( - "%s%s", + output = strcat( count_days(tmp_days), - ((output != "") ? sprintf(", %s", output) : "")); + ((output != "") ? strcat(", ", output) : "")); } if (tmp_weeks) { - output = sprintf( - "%s%s", + output = strcat( count_weeks(tmp_weeks), - ((output != "") ? sprintf(", %s", output) : "")); + ((output != "") ? strcat(", ", output) : "")); } if (tmp_years) { - output = sprintf( - "%s%s", + output = strcat( count_years(tmp_years), - ((output != "") ? sprintf(", %s", output) : "")); + ((output != "") ? strcat(", ", output) : "")); } return output; @@ -217,9 +210,8 @@ string process_time(float outputtype, float seconds) if (tmp_days) { output = sprintf( - "%s%s", count_days(tmp_days), - ((output != "") ? sprintf(", %s", output) : "")); + ((output != "") ? strcat(", ", output) : "")); } return output;