5 float stringwidth_colors(string s, vector theSize)
7 return stringwidth(s, true, theSize);
10 float stringwidth_nocolors(string s, vector theSize)
12 return stringwidth(s, false, theSize);
19 string seconds_tostring(float sec)
21 float minutes = floor(sec / 60);
23 return sprintf("%d:%02d", minutes, sec);
26 int ColorTranslateMode;
28 string ColorTranslateRGB(string s)
30 return (ColorTranslateMode & 1) ? strdecolorize(s) : s;
33 // color code replace, place inside of sprintf and parse the string... defaults described as constants
34 // foreground/normal colors
35 string autocvar_hud_colorset_foreground_1 = "2"; // F1 - Green // primary priority (important names, etc)
36 string autocvar_hud_colorset_foreground_2 = "3"; // F2 - Yellow // secondary priority (items, locations, numbers, etc)
37 string autocvar_hud_colorset_foreground_3 = "4"; // F3 - Blue // tertiary priority or relatively inconsequential text
38 string autocvar_hud_colorset_foreground_4 = "1"; // F4 - Red // notice/attention grabbing texting
40 string autocvar_hud_colorset_kill_1 = "1"; // K1 - Red // "bad" or "dangerous" text (death messages against you, kill notifications, etc)
41 string autocvar_hud_colorset_kill_2 = "3"; // K2 - Yellow // similar to above, but less important... OR, a highlight out of above message type
42 string autocvar_hud_colorset_kill_3 = "4"; // K3 - Blue // "good" or "beneficial" text (you fragging someone, etc)
44 string autocvar_hud_colorset_background = "7"; // BG - White // neutral/unimportant text
46 /** color code replace, place inside of sprintf and parse the string */
47 string CCR(string input)
49 // See the autocvar declarations in util.qh for default values
51 // foreground/normal colors
52 input = strreplace("^F1", strcat("^", autocvar_hud_colorset_foreground_1), input);
53 input = strreplace("^F2", strcat("^", autocvar_hud_colorset_foreground_2), input);
54 input = strreplace("^F3", strcat("^", autocvar_hud_colorset_foreground_3), input);
55 input = strreplace("^F4", strcat("^", autocvar_hud_colorset_foreground_4), input);
58 input = strreplace("^K1", strcat("^", autocvar_hud_colorset_kill_1), input);
59 input = strreplace("^K2", strcat("^", autocvar_hud_colorset_kill_2), input);
60 input = strreplace("^K3", strcat("^", autocvar_hud_colorset_kill_3), input);
63 input = strreplace("^BG", strcat("^", autocvar_hud_colorset_background), input);
64 input = strreplace("^N", "^7", input); // "none"-- reset to white...
68 bool startsWith(string haystack, string needle)
70 return substring(haystack, 0, strlen(needle)) == needle;
73 bool startsWithNocase(string haystack, string needle)
75 return strcasecmp(substring(haystack, 0, strlen(needle)), needle) == 0;
78 /** unzone the string, and return it as tempstring. Safe to be called on string_null */
79 string fstrunzone(string s)
82 string sc = strcat(s, "");
89 int o = strstrofs(s, " ", 0);
91 return substring(s, 0, o);
96 int o = strstrofs(s, " ", 0);
97 if (o < 0) return string_null;
98 return substring(s, o + 1, strlen(s) - (o + 1));
101 string substring_range(string s, float b, float e)
103 return substring(s, b, e - b);
106 string swapwords(string str, float i, float j)
109 string s1, s2, s3, s4, s5;
110 float si, ei, sj, ej, s0, en;
111 n = tokenizebyseparator(str, " "); // must match g_maplist processing in ShuffleMaplist and "shuffle"
112 si = argv_start_index(i);
113 sj = argv_start_index(j);
114 ei = argv_end_index(i);
115 ej = argv_end_index(j);
116 s0 = argv_start_index(0);
117 en = argv_end_index(n-1);
118 s1 = substring_range(str, s0, si);
119 s2 = substring_range(str, si, ei);
120 s3 = substring_range(str, ei, sj);
121 s4 = substring_range(str, sj, ej);
122 s5 = substring_range(str, ej, en);
123 return strcat(s1, s4, s3, s2, s5);
126 string _shufflewords_str;
127 void _shufflewords_swapfunc(float i, float j, entity pass)
129 _shufflewords_str = swapwords(_shufflewords_str, i, j);
131 string shufflewords(string str)
133 _shufflewords_str = str;
134 int n = tokenizebyseparator(str, " ");
135 shuffle(n, _shufflewords_swapfunc, NULL);
136 str = _shufflewords_str;
137 _shufflewords_str = string_null;
141 string unescape(string in)
143 in = strzone(in); // but it doesn't seem to be necessary in my tests at least
145 int len = strlen(in);
147 for (int i = 0; i < len; ++i) {
148 string s = substring(in, i, 1);
150 s = substring(in, i + 1, 1);
152 str = strcat(str, "\n");
154 str = strcat(str, "\\");
156 str = strcat(str, substring(in, i, 2));
160 str = strcat(str, s);
166 string strwords(string s, int w)
169 for (; w && endpos >= 0; --w) endpos = strstrofs(s, " ", endpos + 1);
170 if (endpos < 0) return s;
171 return substring(s, 0, endpos);
174 bool strhasword(string s, string w)
176 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
179 int u8_strsize(string s)
182 for (int i = 0, c; (c = str2chr(s, i)) > 0; ++i, ++l)