#include "oo.qh"
#ifdef CSQC
- float stringwidth_colors(string s, vector theSize)
- {
- return stringwidth_builtin(s, true, theSize);
- }
+float stringwidth_colors(string s, vector theSize)
+{
+ return stringwidth_builtin(s, true, theSize);
+}
- float stringwidth_nocolors(string s, vector theSize)
- {
- return stringwidth_builtin(s, false, theSize);
- }
+float stringwidth_nocolors(string s, vector theSize)
+{
+ return stringwidth_builtin(s, false, theSize);
+}
#endif
#ifdef MENUQC
- float stringwidth_colors(string s, vector theSize)
- {
- return stringwidth(s, true, theSize);
- }
+float stringwidth_colors(string s, vector theSize)
+{
+ return stringwidth(s, true, theSize);
+}
- float stringwidth_nocolors(string s, vector theSize)
- {
- return stringwidth(s, false, theSize);
- }
+float stringwidth_nocolors(string s, vector theSize)
+{
+ return stringwidth(s, false, theSize);
+}
#endif
ERASEABLE
seconds -= hours * 36000;
float minutes = floor(seconds / 600);
seconds -= minutes * 600;
- if (days > 0) return sprintf(_("%d days, %02d:%02d:%02d"), days, hours, minutes, seconds);
- else return sprintf(_("%02d:%02d:%02d"), hours, minutes, seconds);
+ if (days > 0) { return sprintf(_("%d days, %02d:%02d:%02d"), days, hours, minutes, seconds); } else { return sprintf(_("%02d:%02d:%02d"), hours, minutes, seconds); }
}
ERASEABLE
// background colors
input = strreplace("^BG", strcat("^", autocvar_hud_colorset_background), input);
- input = strreplace("^N", "^7", input); // "none"-- reset to white...
+ input = strreplace("^N", "^7", input); // "none"-- reset to white...
return input;
}
#endif
ERASEABLE
string fstrunzone(string s)
{
- if (!s) return s;
+ if (!s) { return s; }
string sc = strcat(s, "");
strunzone(s);
return sc;
string car(string s)
{
int o = strstrofs(s, " ", 0);
- if (o < 0) return s;
+ if (o < 0) { return s; }
return substring(s, 0, o);
}
string cdr(string s)
{
int o = strstrofs(s, " ", 0);
- if (o < 0) return string_null;
+ if (o < 0) { return string_null; }
return substring(s, o + 1, strlen(s) - (o + 1));
}
ERASEABLE
string cons(string a, string b)
{
- if (a == "") return b;
- if (b == "") return a;
+ if (a == "") { return b; }
+ if (b == "") { return a; }
return strcat(a, " ", b);
}
float n;
string s1, s2, s3, s4, s5;
float si, ei, sj, ej, s0, en;
- n = tokenizebyseparator(str, " "); // must match g_maplist processing in ShuffleMaplist and "shuffle"
+ n = tokenizebyseparator(str, " "); // must match g_maplist processing in ShuffleMaplist and "shuffle"
si = argv_start_index(i);
sj = argv_start_index(j);
ei = argv_end_index(i);
ERASEABLE
string unescape(string in)
{
- in = strzone(in); // but it doesn't seem to be necessary in my tests at least
+ in = strzone(in); // but it doesn't seem to be necessary in my tests at least
int len = strlen(in);
string str = "";
- for (int i = 0; i < len; ++i)
- {
+ for (int i = 0; i < len; ++i) {
string s = substring(in, i, 1);
- if (s == "\\")
- {
+ if (s == "\\") {
s = substring(in, i + 1, 1);
- if (s == "n") str = strcat(str, "\n");
- else if (s == "\\") str = strcat(str, "\\");
- else str = strcat(str, substring(in, i, 2));
+ if (s == "n") { str = strcat(str, "\n"); } else if (s == "\\") {
+ str = strcat(str, "\\");
+ } else { str = strcat(str, substring(in, i, 2)); }
++i;
continue;
}
string strwords(string s, int w)
{
int endpos = 0;
- for ( ; w && endpos >= 0; --w)
+ for ( ; w && endpos >= 0; --w) {
endpos = strstrofs(s, " ", endpos + 1);
- if (endpos < 0) return s;
+ }
+ if (endpos < 0) { return s; }
return substring(s, 0, endpos);
}
int u8_strsize(string s)
{
int l = 0;
- for (int i = 0, c; (c = str2chr(s, i)) > 0; ++i, ++l)
- {
+ for (int i = 0, c; (c = str2chr(s, i)) > 0; ++i, ++l) {
l += (c >= 0x80);
l += (c >= 0x800);
l += (c >= 0x10000);
{
s = strdecolorize(s);
bool utf8 = cvar("utf8_enable");
- for (int i = 0, n = strlen(s); i < n; ++i)
- {
+ for (int i = 0, n = strlen(s); i < n; ++i) {
int c = str2chr(s, i);
- switch (c)
- {
+ switch (c) {
case 0:
case 32: // space
break;
case 192: // charmap space
- if (!utf8) break;
+ if (!utf8) { break; }
return false;
case 160: // space in unicode fonts
case 0xE000 + 192: // utf8 charmap space
- if (utf8) break;
+ if (utf8) { break; }
default:
return false;
}
int buf_load(string pFilename)
{
int buf = buf_create();
- if (buf < 0) return -1;
+ if (buf < 0) { return -1; }
int fh = fopen(pFilename, FILE_READ);
- if (fh < 0)
- {
+ if (fh < 0) {
buf_del(buf);
return -1;
}
string l;
- for (int i = 0; (l = fgets(fh)); ++i)
+ for (int i = 0; (l = fgets(fh)); ++i) {
bufstr_set(buf, i, l);
+ }
fclose(fh);
return buf;
}
void buf_save(float buf, string pFilename)
{
int fh = fopen(pFilename, FILE_WRITE);
- if (fh < 0) error(strcat("Can't write buf to ", pFilename));
+ if (fh < 0) { error(strcat("Can't write buf to ", pFilename)); }
int n = buf_getsize(buf);
- for (int i = 0; i < n; ++i)
+ for (int i = 0; i < n; ++i) {
fputs(fh, strcat(bufstr_get(buf, i), "\n"));
+ }
fclose(fh);
}
string ftos_decimals(float number, int decimals)
{
// inhibit stupid negative zero
- if (number == 0) number = 0;
+ if (number == 0) { number = 0; }
return sprintf("%.*f", decimals, number);
}
string ftos_mindecimals(float number)
{
// inhibit stupid negative zero
- if (number == 0) number = 0;
+ if (number == 0) { number = 0; }
return sprintf("%.7g", number);
}
float r;
r = stof(s1) - stof(s2);
- if (r != 0) return r;
+ if (r != 0) { return r; }
r = strcasecmp(s1, s2);
- if (r != 0) return r;
+ if (r != 0) { return r; }
- if (dot1 == -1) return (dot2 == -1) ? 0 : -1;
- else return (dot2 == -1) ? 1 : vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
+ if (dot1 == -1) { return (dot2 == -1) ? 0 : -1; } else { return (dot2 == -1) ? 1 : vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999)); }
}
ERASEABLE
int vercmp(string v1, string v2)
{
- if (strcasecmp(v1, v2) == 0) return 0; // early out check
-
+ if (strcasecmp(v1, v2) == 0) {
+ return 0; // early out check
+ }
// "git" beats all
- if (v1 == "git") return 1;
- if (v2 == "git") return -1;
+ if (v1 == "git") { return 1; }
+ if (v2 == "git") { return -1; }
return vercmp_recursive(v1, v2);
}