X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fstring.qh;h=384188091d0c4b0c92917bacafd3253707be3fe6;hb=3654de311fe042687b432afccfd0f307eccdac7f;hp=8a984d67e4c7a54af18c69a2ddeb5028ee5119c9;hpb=cd82710e25e3b84401bf9b01b0bcd482d612c800;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 8a984d67e..384188091 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -16,7 +16,6 @@ } #endif -// TODO: macro string seconds_tostring(float sec) { float minutes = floor(sec / 60); @@ -104,6 +103,9 @@ bool startsWithNocase(string haystack, string needle) return strcasecmp(substring(haystack, 0, strlen(needle)), needle) == 0; } +noref string _endsWith_suffix; +#define endsWith(this, suffix) (_endsWith_suffix = suffix, substring(this, -strlen(_endsWith_suffix), -1) == _endsWith_suffix) + /** unzone the string, and return it as tempstring. Safe to be called on string_null */ string fstrunzone(string s) { @@ -279,16 +281,24 @@ void buf_save(float buf, string pFilename) /** * converts a number to a string with the indicated number of decimals - * works for up to 10 decimals! */ string ftos_decimals(float number, int decimals) { // inhibit stupid negative zero if (number == 0) number = 0; - // we have sprintf... return sprintf("%.*f", decimals, number); } +/** + * converts a number to a string with the minimum number of decimals + */ +string ftos_mindecimals(float number) +{ + // inhibit stupid negative zero + if (number == 0) number = 0; + return sprintf("%.7g", number); +} + int vercmp_recursive(string v1, string v2) { int dot1 = strstrofs(v1, ".", 0);