Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
string.qh File Reference
#include "nil.qh"
#include "sort.qh"
#include "oo.qh"
Include dependency graph for string.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DAYS_UP_TO_EPOCH   719469
#define DEC_TO_HEXDIGIT(d)
#define endsWith(this, suffix)
#define EVAL_PAR(...)
#define HEXDIGIT_TO_DEC(d)
#define HEXDIGIT_TO_DEC_RAW(d)
#define IS_DIGIT(d)
#define IS_HEXDIGIT(d)
#define mmsst(tm, compact)
#define mmssth(tm, compact)
#define PAGE_TEXT   _page_text
#define PAGE_TEXT_INIT()
#define PAR(...)
 Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprintf.
#define PAR_1(msg)
#define PAR_2(msg, a1)
#define PAR_3(msg, a1, a2)
#define PAR_4(msg, a1, a2, a3)
#define PAR_5(msg, a1, a2, a3, a4)
#define PAR_6(msg, a1, a2, a3, a4, a5)
#define PAR_7(msg, a1, a2, a3, a4, a5, a6)
#define PAR_8(msg, a1, a2, a3, a4, a5, a6, a7)
#define PAR_9(msg, a1, a2, a3, a4, a5, a6, a7, a8)
#define startsWith(haystack, needle)
#define strcpy(this, s)
#define strfree(this)
#define strhasword(s, w)
#define VM_TEMPSTRING_MAXSIZE   16383

Functions

ERASEABLE void _shufflewords_swapfunc (float i, float j, entity pass)
ERASEABLE int buf_load (string pFilename)
ERASEABLE void buf_save (float buf, string pFilename)
ERASEABLE string car (string s)
 returns first word
string CCR (string input)
 color code replace, place inside of sprintf and parse the string
ERASEABLE string cdr (string s)
 returns all but first word
ERASEABLE vector checkColorCode (string theText, int text_len, int pos, bool check_at_the_end)
ERASEABLE string clockedtime_tostring (int tm, bool hundredths, bool compact)
ERASEABLE string ColorTranslateRGB (string s)
ERASEABLE string cons (string a, string b)
ERASEABLE string cons_mid (string a, string mid, string b)
ERASEABLE int days_up_to_date (int Y, int M, int D)
ERASEABLE string format_time (float seconds)
ERASEABLE string fstrunzone (string s)
 unzone the string, and return it as tempstring.
ERASEABLE string ftos_decimals (float number, int decimals)
 converts a number to a string with the indicated number of decimals
ERASEABLE string ftos_decimals_percentage (float number, int decimals)
 converts a percentage to a string with the indicated number of decimals
ERASEABLE string ftos_mindecimals (float number)
 Converts a number to a string with the minimum number of decimals It assumes that an extreme accuracy of the input number is not needed and reduces the max number of decimals to 4 in order to hide minor representation errors that can easily happen even with small numbers, e.g.: x = 32.1; sprintf("%f", x): "32.099998" x = 4; x += 0.01; x += 0.01; sprintf("%f", x): "4.020001" Reducing the max number of decimals to 5 is not enough to hide most errors.
ERASEABLE bool isCaretEscaped (string theText, float pos)
ERASEABLE bool isInvisibleString (string s)
ERASEABLE bool isValidColorCodeValue (string theText, int cc_len, int tag_start)
ERASEABLE string seconds_tostring (float seconds)
ERASEABLE string shufflewords (string str)
ERASEABLE bool startsWithNocase (string haystack, string needle)
ERASEABLE string strftime_s ()
float stringwidth_colors (string s, vector theSize)
float stringwidth_nocolors (string s, vector theSize)
ERASEABLE string strwords (string s, int w)
ERASEABLE string substring_range (string s, float b, float e)
ERASEABLE string swapwords (string str, float i, float j)
ERASEABLE int u8_strsize (string s)
ERASEABLE string unescape (string in)
ERASEABLE int vercmp (string v1, string v2)
ERASEABLE int vercmp_recursive (string v1, string v2)

Variables

noref string _endsWith_suffix
string _shufflewords_str
string autocvar_hud_colorset_background = "7"
string autocvar_hud_colorset_foreground_1 = "2"
string autocvar_hud_colorset_foreground_2 = "3"
string autocvar_hud_colorset_foreground_3 = "4"
string autocvar_hud_colorset_foreground_4 = "1"
string autocvar_hud_colorset_kill_1 = "1"
string autocvar_hud_colorset_kill_2 = "3"
string autocvar_hud_colorset_kill_3 = "4"
int ColorTranslateMode
const string DIGITS = "0123456789"
const string HEXDIGITS = "0123456789ABCDEF0123456789abcdef"
const string HEXDIGITS_MINSET = "0123456789ABCDEFabcdef"

Macro Definition Documentation

◆ DAYS_UP_TO_EPOCH

#define DAYS_UP_TO_EPOCH   719469

Definition at line 85 of file string.qh.

Referenced by strftime_s().

◆ DEC_TO_HEXDIGIT

#define DEC_TO_HEXDIGIT ( d)
Value:
string substring(string s, float start, float length)
const string HEXDIGITS_MINSET
Definition string.qh:568

Definition at line 572 of file string.qh.

Referenced by rgb_to_hexcolor().

◆ endsWith

#define endsWith ( this,
suffix )
Value:
#define strlen
noref string _endsWith_suffix
Definition string.qh:244

Definition at line 245 of file string.qh.

Referenced by spawnfunc().

◆ EVAL_PAR

#define EVAL_PAR ( ...)
Value:
__VA_ARGS__

Definition at line 650 of file string.qh.

◆ HEXDIGIT_TO_DEC

#define HEXDIGIT_TO_DEC ( d)
Value:
((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)
#define HEXDIGIT_TO_DEC_RAW(d)
Definition string.qh:570

Definition at line 571 of file string.qh.

Referenced by InputBox_draw().

◆ HEXDIGIT_TO_DEC_RAW

#define HEXDIGIT_TO_DEC_RAW ( d)
Value:
(strstrofs(HEXDIGITS, (d), 0))
#define strstrofs
const string HEXDIGITS
Definition string.qh:569

Definition at line 570 of file string.qh.

◆ IS_DIGIT

#define IS_DIGIT ( d)
Value:
(strstrofs(DIGITS, (d), 0) >= 0)
const string DIGITS
Definition string.qh:575

Definition at line 576 of file string.qh.

Referenced by bot_cmd_eval(), find_last_color_code(), InputBox_draw(), isValidColorCodeValue(), translate_key(), and XonoticServerList_drawListBoxItem().

◆ IS_HEXDIGIT

#define IS_HEXDIGIT ( d)
Value:
(strstrofs(HEXDIGITS_MINSET, (d), 0) >= 0)

Definition at line 573 of file string.qh.

Referenced by find_last_color_code(), and isValidColorCodeValue().

◆ mmsst

#define mmsst ( tm,
compact )
Value:
clockedtime_tostring(tm, false, compact)
ERASEABLE string clockedtime_tostring(int tm, bool hundredths, bool compact)
Definition string.qh:148

Definition at line 176 of file string.qh.

◆ mmssth

#define mmssth ( tm,
compact )
Value:
clockedtime_tostring(tm, true, compact)

Definition at line 177 of file string.qh.

◆ PAGE_TEXT

#define PAGE_TEXT   _page_text

Definition at line 643 of file string.qh.

Referenced by PAR(), PAR(), PAR(), PAR(), PAR(), PAR(), PAR(), PAR(), PAR(), PAR(), PAR(), PAR(), PAR(), PAR(), and PAR().

◆ PAGE_TEXT_INIT

#define PAGE_TEXT_INIT ( )
Value:
string _page_text = ""

Definition at line 642 of file string.qh.

◆ PAR

#define PAR ( ...)
Value:
EVAL_PAR(OVERLOAD(PAR, __VA_ARGS__))
#define OVERLOAD(F,...)
Definition misc.qh:12
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:649
#define EVAL_PAR(...)
Definition string.qh:650

Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprintf.

Secondary arguments are optional format arguments for internal sprintf calls. This is to make translators' work easier: paragraphs are shorter than the whole page, sometimes they can be shared across pages (reducing translatable text) and don't require translators to check the whole text in the case of a paragraph update.

Definition at line 649 of file string.qh.

◆ PAR_1

#define PAR_1 ( msg)
Value:
_page_text = (_page_text == "" ? msg : strcat(_page_text, "\n\n", msg))
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

Definition at line 651 of file string.qh.

◆ PAR_2

#define PAR_2 ( msg,
a1 )
Value:
MACRO_BEGIN string _msg = sprintf(msg, a1); PAR_1(_msg); MACRO_END
#define MACRO_END
Definition macro.qh:7
#define MACRO_BEGIN
Definition macro.qh:6
#define PAR_1(msg)
Definition string.qh:651

Definition at line 652 of file string.qh.

◆ PAR_3

#define PAR_3 ( msg,
a1,
a2 )
Value:
MACRO_BEGIN string _msg = sprintf(msg, a1, a2); PAR_1(_msg); MACRO_END

Definition at line 653 of file string.qh.

◆ PAR_4

#define PAR_4 ( msg,
a1,
a2,
a3 )
Value:
MACRO_BEGIN string _msg = sprintf(msg, a1, a2, a3); PAR_1(_msg); MACRO_END

Definition at line 654 of file string.qh.

◆ PAR_5

#define PAR_5 ( msg,
a1,
a2,
a3,
a4 )
Value:
MACRO_BEGIN string _msg = sprintf(msg, a1, a2, a3, a4); PAR_1(_msg); MACRO_END

Definition at line 655 of file string.qh.

◆ PAR_6

#define PAR_6 ( msg,
a1,
a2,
a3,
a4,
a5 )
Value:
MACRO_BEGIN string _msg = sprintf(msg, a1, a2, a3, a4, a5); PAR_1(_msg); MACRO_END

Definition at line 656 of file string.qh.

◆ PAR_7

#define PAR_7 ( msg,
a1,
a2,
a3,
a4,
a5,
a6 )
Value:
MACRO_BEGIN string _msg = sprintf(msg, a1, a2, a3, a4, a5, a6); PAR_1(_msg); MACRO_END

Definition at line 657 of file string.qh.

◆ PAR_8

#define PAR_8 ( msg,
a1,
a2,
a3,
a4,
a5,
a6,
a7 )
Value:
MACRO_BEGIN string _msg = sprintf(msg, a1, a2, a3, a4, a5, a6, a7); PAR_1(_msg); MACRO_END

Definition at line 658 of file string.qh.

◆ PAR_9

#define PAR_9 ( msg,
a1,
a2,
a3,
a4,
a5,
a6,
a7,
a8 )
Value:
MACRO_BEGIN string _msg = sprintf(msg, a1, a2, a3, a4, a5, a6, a7, a8); PAR_1(_msg); MACRO_END

Definition at line 659 of file string.qh.

◆ startsWith

#define startsWith ( haystack,
needle )

◆ strcpy

#define strcpy ( this,
s )
Value:
MACRO_BEGIN \
if (this) { \
strunzone(this); \
} \
this = strzone(s); \
string strzone(string s)

Definition at line 52 of file string.qh.

52#define strcpy(this, s) MACRO_BEGIN \
53 if (this) { \
54 strunzone(this); \
55 } \
56 this = strzone(s); \
57MACRO_END

Referenced by Accuracy_LoadLevels(), Announcer_Duel(), bd_do_next_match(), bd_move_dozer(), bd_server_event(), bd_set_next_match(), bd_set_nextlevel(), bot_custom_weapon_priority_setup(), bot_decodecommand(), centerprint_Add(), centerprint_SetDuelTitle(), centerprint_SetTitle(), Cmd_Scoreboard_SetFields(), CvarList_UpdateResults(), DamageText::DamageText_update(), Ent_WaypointSprite(), GameTypeVote_Finished(), GENERIC_COMMAND(), get_mi_min_max(), GetCvars_handleString(), GetCvars_handleString_Fixup(), HUD_Chat(), HUD_Main(), HUD_Mod_Race(), HUD_Panel_FirstInDrawQ(), HUD_Radar(), HUD_Vote(), HUD_Weapons(), ignore_add_player(), ignore_remove_player(), InitGameplayMode(), Label_draw(), Label_setText(), LoadPlayerSounds(), Local_Notification_sound(), LocalCommand_sendcvar(), m_goto(), m_tooltip(), Model::model_precache(), Monster_Sounds_Load(), MUTATOR_HOOKFUNCTION(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), NET_HANDLE(), net_handle_ServerWelcome(), OnlineBanList_Think(), PlayerFrame(), PlayerThink(), preMenuDraw(), ps_move_piece(), queue_to_execute_next_frame(), QuickMenu_Page_Load(), QuickMenu_Page_LoadEntry(), QuickMenu_skip_submenu(), race_checkAndWriteName(), race_deleteTime(), race_SendTime(), race_setTime(), sandbox_ObjectPort_Load(), Scoreboard_Draw(), SendWelcomeMessage(), Set_NextMap(), Sound::sound_precache(), spawnfunc(), StoreCheckpointSplits(), UpdatePlayerSounds(), W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(), W_Reload(), waypoint_loadall(), waypoint_saveall(), welcomeDialog_resetStrings(), WinningConditionHelper(), WriteByte(), XonoticCampaignList_loadCvars(), XonoticCrosshairPreview_draw(), XonoticCvarList_setSelected(), XonoticMapInfoDialog_loadMapInfo(), XonoticMapList_keyDown(), XonoticMapList_refilter(), XonoticPlayerModelSelector_go(), XonoticScreenshotBrowserTab_loadPreviewScreenshot(), XonoticScreenshotImage_load(), XonoticScreenshotViewerDialog_loadScreenshot(), XonoticServerList_draw(), XonoticServerList_setSelected(), XonoticTextBox_setText(), and XonoticWelcomeDialog_readInputArgs().

◆ strfree

#define strfree ( this)
Value:
MACRO_BEGIN \
if (this) { \
strunzone(this); \
} \
this = string_null; \
string string_null
Definition nil.qh:9

Definition at line 59 of file string.qh.

59#define strfree(this) MACRO_BEGIN \
60 if (this) { \
61 strunzone(this); \
62 } \
63 this = string_null; \
64MACRO_END

Referenced by DamageText::~DamageText(), DebugText3d::~DebugText3d(), Announcer_ClearTitle(), bd_editor_place(), bd_server_event(), bd_setup_pieces(), bd_unfill_recurse(), BGMScript_InitEntity(), bot_clientdisconnect(), c4_server_event(), CampaignFile_Unload(), centerprint_ClearTitle(), centerprint_KillAll(), ClearCheckpointSplits(), ClearPlayerSounds(), ClientDisconnect(), Cmd_Scoreboard_SetFields(), cvar_changes_init(), DemoList_Filter_Change(), end_minigame(), Ent_RemoveEntCS(), Ent_RemoveWaypointSprite(), EntryList_StringFilterBox_Change(), execute_next_frame(), GameType_ConfigureSliders(), GetCvars_handleString(), HUD_Crosshair(), HUD_Mod_Race(), HUDSkinList_Filter_Change(), HUDSkinList_SavedName_Change(), ignore_list_apply(), InputBox_setText(), ItemRemove(), LocalCommand_sendcvar(), m_init_delayed(), m_tooltip(), MapList_StringFilterBox_Change(), MapVote_Finished(), MapVote_Think(), MapVote_UnzoneStrings(), MUTATOR_HOOKFUNCTION(), MX_Say_(), Net_Flush(), NET_HANDLE(), NET_HANDLE(), Net_Notification_Remove(), nmm_kill_tiles(), PlayerStats_GameReport_FinalizePlayer(), PlayerStats_GameReport_Reset_All(), pp_move(), pp_server_event(), ps_move_piece(), ps_server_event(), QuickMenu_Close(), QuickMenu_Page_ClearEntry(), QuickMenu_skip_submenu(), race_CheckName(), race_ClearRecords(), rewrapCampaign(), sandbox_ObjectPort_Load(), sandbox_ObjectRemove(), Scoreboard_Rankings_Draw(), ScreenshotList_Filter_Change(), ServerList_Filter_Change(), Set_NextMap(), setZonedTooltip(), Shutdown(), SL_ProcessCategoryOverrides(), SoundList_Filter_Change(), StrafeHUD_UpdateSonarSound(), ttt_server_event(), url_fclose(), url_multi_ready(), url_single_fopen(), url_URI_Get_Callback(), VoteReset(), Welcome_Message_Show_Try(), XonoticCvarList_setSelected(), XonoticGuideDescription_setDescription(), XonoticKeyBinder_destroy(), XonoticServerInfoDialog_loadServerInfo(), XonoticServerList_setSortOrder(), and XonoticTextBox_destroy().

◆ strhasword

#define strhasword ( s,
w )

◆ VM_TEMPSTRING_MAXSIZE

#define VM_TEMPSTRING_MAXSIZE   16383

Definition at line 8 of file string.qh.

Referenced by cvar_changes_init().

Function Documentation

◆ _shufflewords_swapfunc()

ERASEABLE void _shufflewords_swapfunc ( float i,
float j,
entity pass )

Definition at line 319 of file string.qh.

320{
322}
string _shufflewords_str
Definition string.qh:317
ERASEABLE string swapwords(string str, float i, float j)
Definition string.qh:298

References _shufflewords_str, entity(), pass, and swapwords().

Referenced by shufflewords().

◆ buf_load()

ERASEABLE int buf_load ( string pFilename)

Definition at line 437 of file string.qh.

438{
439 int buf = buf_create();
440 if (buf < 0) return -1;
441 int fh = fopen(pFilename, FILE_READ);
442 if (fh < 0)
443 {
444 buf_del(buf);
445 return -1;
446 }
447 string l;
448 for (int i = 0; (l = fgets(fh)); ++i)
449 bufstr_set(buf, i, l);
450 fclose(fh);
451 return buf;
452}
const float FILE_READ
#define buf_create
string fgets(float fhandle)
void fclose(float fhandle)
float fopen(string filename, float mode)

References buf_create, fclose(), fgets(), FILE_READ, and fopen().

◆ buf_save()

ERASEABLE void buf_save ( float buf,
string pFilename )

Definition at line 455 of file string.qh.

456{
457 int fh = fopen(pFilename, FILE_WRITE);
458 if (fh < 0) error(strcat("Can't write buf to ", pFilename));
459 int n = buf_getsize(buf);
460 for (int i = 0; i < n; ++i)
461 fputs(fh, strcat(bufstr_get(buf, i), "\n"));
462 fclose(fh);
463}
const float FILE_WRITE
void fputs(float fhandle, string s)
#define error
Definition pre.qh:6

References error, fclose(), FILE_WRITE, fopen(), fputs(), and strcat().

◆ car()

◆ CCR()

string CCR ( string input)

color code replace, place inside of sprintf and parse the string

Definition at line 216 of file string.qh.

217{
218 // foreground/normal colors
219 input = strreplace("^F1", strcat("^", autocvar_hud_colorset_foreground_1), input);
220 input = strreplace("^F2", strcat("^", autocvar_hud_colorset_foreground_2), input);
221 input = strreplace("^F3", strcat("^", autocvar_hud_colorset_foreground_3), input);
222 input = strreplace("^F4", strcat("^", autocvar_hud_colorset_foreground_4), input);
223
224 // "kill" colors
225 input = strreplace("^K1", strcat("^", autocvar_hud_colorset_kill_1), input);
226 input = strreplace("^K2", strcat("^", autocvar_hud_colorset_kill_2), input);
227 input = strreplace("^K3", strcat("^", autocvar_hud_colorset_kill_3), input);
228
229 // background colors
230 input = strreplace("^BG", strcat("^", autocvar_hud_colorset_background), input);
231 input = strreplace("^N", "^7", input); // "none"-- reset to white...
232 return input;
233}
string autocvar_hud_colorset_foreground_1
Definition string.qh:204
string autocvar_hud_colorset_kill_1
Definition string.qh:209
string autocvar_hud_colorset_kill_2
Definition string.qh:210
string autocvar_hud_colorset_foreground_3
Definition string.qh:206
string autocvar_hud_colorset_foreground_4
Definition string.qh:207
string autocvar_hud_colorset_background
Definition string.qh:213
string autocvar_hud_colorset_foreground_2
Definition string.qh:205
string autocvar_hud_colorset_kill_3
Definition string.qh:211

References autocvar_hud_colorset_background, autocvar_hud_colorset_foreground_1, autocvar_hud_colorset_foreground_2, autocvar_hud_colorset_foreground_3, autocvar_hud_colorset_foreground_4, autocvar_hud_colorset_kill_1, autocvar_hud_colorset_kill_2, autocvar_hud_colorset_kill_3, and strcat().

Referenced by centerprint_SetTitle(), hash_replace(), net_handle_ServerWelcome(), notif_arg_frag_ping(), notif_arg_frag_stats(), and notif_arg_spree_inf().

◆ cdr()

◆ checkColorCode()

ERASEABLE vector checkColorCode ( string theText,
int text_len,
int pos,
bool check_at_the_end )

Definition at line 609 of file string.qh.

610{
611 if (text_len == 0)
612 text_len = strlen(theText);
613 string tag_type = "^";
614 int cc_len = 2;
615 int tag_len = 1;
616
617 LABEL(check_color_tag)
618
619 int ofs = cc_len;
620 if (!check_at_the_end)
621 ofs--;
622 for (; ofs >= 1; --ofs)
623 {
624 if (!(pos >= ofs && text_len >= pos + (cc_len - ofs)))
625 continue;
626 if(substring(theText, pos - ofs, tag_len) == tag_type)
627 {
628 if (!isCaretEscaped(theText, pos - ofs) && isValidColorCodeValue(theText, cc_len, pos - ofs))
629 return eX * cc_len + eY * ofs;
630 }
631 }
632 if (cc_len == 2)
633 {
634 tag_type = "^x";
635 cc_len = 5;
636 tag_len = 2;
637 goto check_color_tag;
638 }
639 return '0 0 0';
640}
#define LABEL(id)
Definition compiler.qh:34
ERASEABLE bool isCaretEscaped(string theText, float pos)
Definition string.qh:580
ERASEABLE bool isValidColorCodeValue(string theText, int cc_len, int tag_start)
Definition string.qh:591
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44

References eX, eY, isCaretEscaped(), isValidColorCodeValue(), LABEL, strlen, substring(), and vector.

Referenced by textLengthUpToLength(), textLengthUpToWidth(), and XonoticColorpicker_mouseDrag().

◆ clockedtime_tostring()

ERASEABLE string clockedtime_tostring ( int tm,
bool hundredths,
bool compact )
Parameters
[in]tminteger clocked time in tenths or hundredths, CANNOT be negative
[in]hundredthsif true append hundredths too, otherwise only tenths
[in]compactif true leading 0s are omitted (except the seconds unit digit)
Returns
clocked time as "m:ss.t" or "m:ss.th" string (rounded)

Definition at line 148 of file string.qh.

149{
150 if (tm < 0)
151 {
152 if (compact)
153 return strcat("0.0", hundredths ? "0" : "");
154 else
155 return strcat("0:00.0", hundredths ? "0" : "");
156 }
157 int acc = hundredths ? 6000 : 600;
158 tm = floor(tm + 0.5);
159 int minutes = floor(tm / acc);
160 int tm_without_minutes = tm - minutes * acc;
161 // NOTE: the start digit of s is a placeholder and won't be displayed
162 string s = ftos(acc * 10 + tm_without_minutes);
163 if (!compact || minutes > 0)
164 return strcat(ftos(minutes), ":", substring(s, 1, 2), ".", substring(s, 3, hundredths ? 2 : 1));
165
166 int ofs = 2, digits = 1;
167 if (tm_without_minutes >= 10 * (hundredths ? 100 : 10))
168 {
169 ofs = 1;
170 digits = 2;
171 }
172 return strcat(substring(s, ofs, digits), ".", substring(s, 3, hundredths ? 2 : 1));
173
174}
string ftos(float f)
float floor(float f)

References floor(), ftos(), strcat(), and substring().

◆ ColorTranslateRGB()

ERASEABLE string ColorTranslateRGB ( string s)

◆ cons()

◆ cons_mid()

ERASEABLE string cons_mid ( string a,
string mid,
string b )

Definition at line 284 of file string.qh.

285{
286 if (a == "") return b;
287 if (b == "") return a;
288 return strcat(a, mid, b);
289}

References strcat().

Referenced by _getcommandkey(), net_handle_ServerWelcome(), translate_weaponarena(), and XonoticKeyBinder_drawListBoxItem().

◆ days_up_to_date()

ERASEABLE int days_up_to_date ( int Y,
int M,
int D )

Definition at line 70 of file string.qh.

71{
72 int years = (M <= 2) ? Y - 1 : Y;
73
74 int leap_days = floor(years / 4) - floor(years / 100) + floor(years / 400);
75
76 // using these 2 formulas to save 2 arrays or switches (performance isn't important here)
77 int months = (M <= 2) ? (M + 9) : (M - 3); // 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
78 int leftover_days = (M <= 2) ? (M + 5) : floor(0.58 * M - 1.1); // 6, 7, 0, 1, 1, 2, 2, 3, 4, 4, 5, 5
79
80 int month_days = 30 * months + leftover_days;
81
82 return 365 * years + month_days + D + leap_days;
83}

References floor().

Referenced by strftime_s().

◆ format_time()

ERASEABLE string format_time ( float seconds)

Definition at line 180 of file string.qh.

181{
182 seconds = floor(seconds + 0.5);
183 float days = floor(seconds / 864000);
184 seconds -= days * 864000;
185 float hours = floor(seconds / 36000);
186 seconds -= hours * 36000;
187 float minutes = floor(seconds / 600);
188 seconds -= minutes * 600;
189 if (days > 0) return sprintf(_("%d days, %02d:%02d:%02d"), days, hours, minutes, seconds);
190 else return sprintf(_("%02d:%02d:%02d"), hours, minutes, seconds);
191}

References floor().

◆ fstrunzone()

ERASEABLE string fstrunzone ( string s)

unzone the string, and return it as tempstring.

Safe to be called on string_null

Definition at line 249 of file string.qh.

250{
251 if (!s) return s;
252 string sc = strcat(s, "");
253 strunzone(s);
254 return sc;
255}
void strunzone(string s)

References strcat(), and strunzone().

◆ ftos_decimals()

ERASEABLE string ftos_decimals ( float number,
int decimals )

converts a number to a string with the indicated number of decimals

Definition at line 469 of file string.qh.

470{
471 // inhibit stupid negative zero
472 if (number == 0) number = 0;
473 return sprintf("%.*f", decimals, number);
474}
int int number
Definition impulse.qc:89

References number.

Referenced by dialog_hudpanel_main_settings(), DrawDomItem(), formatStringSpecial(), HUD_Physics(), HUD_Score(), MakeRaceString(), MixedSlider_addRange(), MUTATOR_HOOKFUNCTION(), StrafeHUD_DrawJumpHeight(), StrafeHUD_DrawStartSpeed(), StrafeHUD_DrawStrafeEfficiency(), StrafeHUD_DrawVerticalAngle(), updateSensField(), waypoint_save_links(), waypoint_saveall(), and XonoticDecibelsSlider_valueToText().

◆ ftos_decimals_percentage()

ERASEABLE string ftos_decimals_percentage ( float number,
int decimals )

converts a percentage to a string with the indicated number of decimals

Definition at line 480 of file string.qh.

481{
482 // inhibit stupid negative zero
483 if (number == 0) number = 0;
484 return sprintf(_("%.*f%%"), decimals, number * 100); // translatable percentage string
485}

References number.

Referenced by dialog_hudpanel_main_settings(), formatStringSpecial(), Scoreboard_AccuracyStats_Draw(), XonoticDecibelsSlider_valueToText(), XonoticLanguageList_drawListBoxItem(), XonoticScreenshotImage_draw(), and XonoticStatsList_getStats().

◆ ftos_mindecimals()

ERASEABLE string ftos_mindecimals ( float number)

Converts a number to a string with the minimum number of decimals It assumes that an extreme accuracy of the input number is not needed and reduces the max number of decimals to 4 in order to hide minor representation errors that can easily happen even with small numbers, e.g.: x = 32.1; sprintf("%f", x): "32.099998" x = 4; x += 0.01; x += 0.01; sprintf("%f", x): "4.020001" Reducing the max number of decimals to 5 is not enough to hide most errors.

Definition at line 497 of file string.qh.

498{
499 // inhibit stupid negative zero
500 if (fabs(number) < 0.0001)
501 return "0";
502
503 int rounded = rint(number);
504 if (fabs(number - rounded) < 0.0001)
505 return ftos(rounded);
506
507 string s = sprintf("%.4f", number);
508
509 // if the decimal part got lost (large numbers), return what we got
510 int dot_ofs = strstrofs(s, ".", 0);
511 if (dot_ofs < 0)
512 return s;
513
514 // count trailing zeros that will need to be removed
515 string ch = "";
516 int i = 0;
517 for ( ; i < 4; ++i)
518 {
519 ch = substring(s, -1 - i, -1 - i);
520 if (ch != "0")
521 break;
522 }
523
524 // no trailing zeros, return what we got
525 // FLOAT_NAN falls under this case and returned as is ("-1.#IND")
526 if (i == 0)
527 return s;
528
529 // if we've found 4 trailing zeros (i == 4) assume the next char is a dot and remove it too
530 // ch == "." handles cases where the decimal part has less than 4 decimal digits (large numbers)
531 if (i == 4 || ch == ".")
532 ++i; // remove dot too
533
534 return substring(s, 0, -1 - i);
535}
float rint(float f)
float fabs(float f)

References fabs(), ftos(), number, rint(), strstrofs, and substring().

Referenced by dialog_hudpanel_main_settings(), gettooltip_dependency_string_numeric(), HUD_Panel_InputEvent(), HUD_Panel_SetPos(), HUD_Panel_SetPosSize(), XonoticCheckBox_saveCvars(), XonoticMixedSlider_saveCvars(), and XonoticSlider_saveCvars().

◆ isCaretEscaped()

ERASEABLE bool isCaretEscaped ( string theText,
float pos )

Definition at line 580 of file string.qh.

581{
582 // count all the previous carets
583 int carets = 0;
584 while(pos - carets >= 1 && substring(theText, pos - carets - 1, 1) == "^")
585 ++carets;
586 // if number of previous carets is odd then this carets is escaped
587 return (carets & 1);
588}

References substring().

Referenced by checkColorCode(), and XonoticColorpicker_mouseDrag().

◆ isInvisibleString()

ERASEABLE bool isInvisibleString ( string s)

Definition at line 387 of file string.qh.

388{
389 s = strdecolorize(s);
390 bool utf8 = cvar("utf8_enable");
391 for (int i = 0, n = strlen(s); i < n; ++i)
392 {
393 int c = str2chr(s, i);
394 switch (c)
395 {
396 case 0:
397 case 32: // space
398 break;
399 case 192: // charmap space
400 if (!utf8) break;
401 return false;
402 case 0xE000: // invisible char of the utf8 quake charmap
403 case 0xE00A: // invisible char of the utf8 quake charmap
404 case 0xE0A0: // invisible char of the utf8 quake charmap
405 case 0xE020: // invisible char of the utf8 quake charmap
406 case 0x00A0: // NO-BREAK SPACE
407 case 0x180E: // MONGOLIAN VOWEL SEPARATOR
408 case 0x2000: // EN QUAD
409 case 0x2001: // EM QUAD
410 case 0x2002: // EN SPACE
411 case 0x2003: // EM SPACE
412 case 0x2004: // THREE-PER-EM SPACE
413 case 0x2005: // FOUR-PER-EM SPACE
414 case 0x2006: // SIX-PER-EM SPACE
415 case 0x2007: // FIGURE SPACE
416 case 0x2008: // PUNCTUATION SPACE
417 case 0x2009: // THIN SPACE
418 case 0x200A: // HAIR SPACE
419 case 0x200B: // ZERO WIDTH SPACE
420 case 0x202F: // NARROW NO-BREAK SPACE
421 case 0x205F: // MEDIUM MATHEMATICAL SPACE
422 case 0x3000: // IDEOGRAPHIC SPACE
423 case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE
424 case 0xFFA0: // Halfwidth Hangul Filler
425 case 0x3164: // Hangul Filler
426 if (utf8) break;
427 default:
428 return false;
429 }
430 }
431 return true;
432}
#define str2chr
float cvar(string name)

References cvar(), str2chr, and strlen.

Referenced by PlayerFrame().

◆ isValidColorCodeValue()

ERASEABLE bool isValidColorCodeValue ( string theText,
int cc_len,
int tag_start )

Definition at line 591 of file string.qh.

592{
593 if (cc_len == 2)
594 return IS_DIGIT(substring(theText, tag_start + 1, 1));
595 if (cc_len == 5)
596 return (IS_HEXDIGIT(substring(theText, tag_start + 2, 1))
597 && IS_HEXDIGIT(substring(theText, tag_start + 3, 1))
598 && IS_HEXDIGIT(substring(theText, tag_start + 4, 1)));
599 return false;
600}
#define IS_DIGIT(d)
Definition string.qh:576
#define IS_HEXDIGIT(d)
Definition string.qh:573

References IS_DIGIT, IS_HEXDIGIT, and substring().

Referenced by checkColorCode().

◆ seconds_tostring()

ERASEABLE string seconds_tostring ( float seconds)
Parameters
[in]secondsnumber of seconds, can be negative too
Returns
time as "m:ss" string (floored)

Definition at line 126 of file string.qh.

127{
128 bool negative = false;
129 if (seconds < 0)
130 {
131 negative = true;
132 seconds = -seconds;
133 if (floor(seconds) != seconds)
134 seconds += 1; // make floor work in the other direction
135 }
136 int minutes = floor(seconds / 60);
137 seconds -= minutes * 60;
138 if (negative)
139 return sprintf("-%d:%02d", minutes, seconds);
140 return sprintf("%d:%02d", minutes, seconds);
141}

References floor().

Referenced by formatmessage(), HUD_CenterPrint(), HUD_Pickup(), and HUD_Timer().

◆ shufflewords()

ERASEABLE string shufflewords ( string str)

Definition at line 325 of file string.qh.

326{
327 _shufflewords_str = str;
328 int n = tokenizebyseparator(str, " ");
330 str = _shufflewords_str;
332 return str;
333}
#define tokenizebyseparator
#define NULL
Definition post.qh:14
ERASEABLE void shuffle(float n, swapfunc_t swap, entity pass)
Definition sort.qh:42
ERASEABLE void _shufflewords_swapfunc(float i, float j, entity pass)
Definition string.qh:319

References _shufflewords_str, _shufflewords_swapfunc(), NULL, shuffle(), string_null, and tokenizebyseparator.

◆ startsWithNocase()

ERASEABLE bool startsWithNocase ( string haystack,
string needle )

Definition at line 239 of file string.qh.

240{
241 return strcasecmp(substring(haystack, 0, strlen(needle)), needle) == 0;
242}
#define strcasecmp

References strcasecmp, strlen, and substring().

Referenced by MapInfo_FindName().

◆ strftime_s()

ERASEABLE string strftime_s ( )

Definition at line 94 of file string.qh.

95{
96 string date = strftime(false, "%Y-%m-%d %H:%M:%S");
97 int i, seconds = 0;
98 i =0; int Y = stof(substring(date, i, 4)); // years
99 i+=5; int M = stof(substring(date, i, 2)); // months
100 i+=3; int D = stof(substring(date, i, 2)); // days
101
102 i+=3; seconds += stof(substring(date, i, 2)) * 60 * 60; // hours
103 i+=3; seconds += stof(substring(date, i, 2)) * 60; // minutes
104 i+=3; seconds += stof(substring(date, i, 2)); // seconds
105
106 // doing so we loose precision
107 //seconds += (days_up_to_date(Y, M, D) - DAYS_UP_TO_EPOCH) * 24 * 60 * 60;
108 //return ftos(seconds);
109
110 int days_since_epoch = days_up_to_date(Y, M, D) - DAYS_UP_TO_EPOCH;
111 // use hundreds of seconds as unit to avoid precision loss
112 int hundreds_of_seconds = days_since_epoch * 24 * 6 * 6;
113 hundreds_of_seconds += floor(seconds / 100);
114
115 // tens of seconds and seconds
116 string seconds_str = ftos(seconds % 100);
117 if ((seconds % 100) < 10)
118 seconds_str = strcat("0", seconds_str);
119
120 return strcat(ftos(hundreds_of_seconds), seconds_str);
121}
float stof(string val,...)
#define DAYS_UP_TO_EPOCH
Definition string.qh:85
ERASEABLE int days_up_to_date(int Y, int M, int D)
Definition string.qh:70

References days_up_to_date(), DAYS_UP_TO_EPOCH, floor(), ftos(), stof(), strcat(), and substring().

Referenced by spawnfunc().

◆ stringwidth_colors()

◆ stringwidth_nocolors()

float stringwidth_nocolors ( string s,
vector theSize )

Definition at line 35 of file string.qh.

36 {
37 return stringwidth_builtin(s, false, theSize);
38 }

References vector.

Referenced by HUD_Pickup(), MapVote_FormatMapItem(), minigame_drawstring_trunc(), and minigame_drawstring_wrapped().

◆ strwords()

ERASEABLE string strwords ( string s,
int w )

Definition at line 361 of file string.qh.

362{
363 int endpos = 0;
364 for ( ; w && endpos >= 0; --w)
365 endpos = strstrofs(s, " ", endpos + 1);
366 if (endpos < 0) return s;
367 return substring(s, 0, endpos);
368}

References strstrofs, and substring().

Referenced by Map_MarkAsRecent().

◆ substring_range()

ERASEABLE string substring_range ( string s,
float b,
float e )

Definition at line 292 of file string.qh.

293{
294 return substring(s, b, e - b);
295}

References substring().

Referenced by DamageText::DamageText_update(), and swapwords().

◆ swapwords()

ERASEABLE string swapwords ( string str,
float i,
float j )

Definition at line 298 of file string.qh.

299{
300 string s1, s2, s3, s4, s5;
301 float si, ei, sj, ej, s0, en;
302 int n = tokenizebyseparator(str, " ");
303 si = argv_start_index(i);
304 sj = argv_start_index(j);
305 ei = argv_end_index(i);
306 ej = argv_end_index(j);
307 s0 = argv_start_index(0);
308 en = argv_end_index(n - 1);
309 s1 = substring_range(str, s0, si);
310 s2 = argv(i);
311 s3 = substring_range(str, ei, sj);
312 s4 = argv(j);
313 s5 = substring_range(str, ej, en);
314 return strcat(s1, s4, s3, s2, s5);
315}
#define argv_end_index
#define argv_start_index
string argv(float n)
spree_inf s1 s2 s3loc s2 s1
Definition all.inc:281
spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2 f1points s1 s2
Definition all.inc:469
ERASEABLE string substring_range(string s, float b, float e)
Definition string.qh:292

References argv(), argv_end_index, argv_start_index, s1, s2, strcat(), substring_range(), and tokenizebyseparator.

Referenced by _shufflewords_swapfunc().

◆ u8_strsize()

ERASEABLE int u8_strsize ( string s)

Definition at line 373 of file string.qh.

374{
375 int l = 0;
376 for (int i = 0, c; (c = str2chr(s, i)) > 0; ++i, ++l)
377 {
378 l += (c >= 0x80);
379 l += (c >= 0x800);
380 l += (c >= 0x10000);
381 }
382 return l;
383}

References str2chr.

Referenced by InputBox_enterText().

◆ unescape()

ERASEABLE string unescape ( string in)

Definition at line 336 of file string.qh.

337{
338 in = strzone(in); // but it doesn't seem to be necessary in my tests at least
339
340 int len = strlen(in);
341 string str = "";
342 for (int i = 0; i < len; ++i)
343 {
344 string s = substring(in, i, 1);
345 if (s == "\\")
346 {
347 s = substring(in, i + 1, 1);
348 if (s == "n") str = strcat(str, "\n");
349 else if (s == "\\") str = strcat(str, "\\");
350 else str = strcat(str, substring(in, i, 2));
351 ++i;
352 continue;
353 }
354 str = strcat(str, s);
355 }
356 strunzone(in);
357 return str;
358}

References strcat(), strlen, strunzone(), strzone(), and substring().

◆ vercmp()

ERASEABLE int vercmp ( string v1,
string v2 )

Definition at line 557 of file string.qh.

558{
559 if (strcasecmp(v1, v2) == 0) return 0; // early out check
560
561 // "git" beats all
562 if (v1 == "git") return 1;
563 if (v2 == "git") return -1;
564
565 return vercmp_recursive(v1, v2);
566}
ERASEABLE int vercmp_recursive(string v1, string v2)
Definition string.qh:538

References strcasecmp, and vercmp_recursive().

Referenced by PlayerFrame(), and UpdateNotification_URI_Get_Callback().

◆ vercmp_recursive()

ERASEABLE int vercmp_recursive ( string v1,
string v2 )

Definition at line 538 of file string.qh.

539{
540 int dot1 = strstrofs(v1, ".", 0);
541 int dot2 = strstrofs(v2, ".", 0);
542 string s1 = (dot1 == -1) ? v1 : substring(v1, 0, dot1);
543 string s2 = (dot2 == -1) ? v2 : substring(v2, 0, dot2);
544
545 float r;
546 r = stof(s1) - stof(s2);
547 if (r != 0) return r;
548
549 r = strcasecmp(s1, s2);
550 if (r != 0) return r;
551
552 if (dot1 == -1) return (dot2 == -1) ? 0 : -1;
553 else return (dot2 == -1) ? 1 : vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
554}

References s1, s2, stof(), strcasecmp, strstrofs, substring(), and vercmp_recursive().

Referenced by vercmp(), and vercmp_recursive().

Variable Documentation

◆ _endsWith_suffix

noref string _endsWith_suffix

Definition at line 244 of file string.qh.

◆ _shufflewords_str

string _shufflewords_str

Definition at line 317 of file string.qh.

Referenced by _shufflewords_swapfunc(), and shufflewords().

◆ autocvar_hud_colorset_background

string autocvar_hud_colorset_background = "7"

Definition at line 213 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_foreground_1

string autocvar_hud_colorset_foreground_1 = "2"

Definition at line 204 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_foreground_2

string autocvar_hud_colorset_foreground_2 = "3"

Definition at line 205 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_foreground_3

string autocvar_hud_colorset_foreground_3 = "4"

Definition at line 206 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_foreground_4

string autocvar_hud_colorset_foreground_4 = "1"

Definition at line 207 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_kill_1

string autocvar_hud_colorset_kill_1 = "1"

Definition at line 209 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_kill_2

string autocvar_hud_colorset_kill_2 = "3"

Definition at line 210 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_kill_3

string autocvar_hud_colorset_kill_3 = "4"

Definition at line 211 of file string.qh.

Referenced by CCR().

◆ ColorTranslateMode

int ColorTranslateMode

Definition at line 193 of file string.qh.

Referenced by ColorTranslateRGB(), and CSQC_UpdateView().

◆ DIGITS

const string DIGITS = "0123456789"

Definition at line 575 of file string.qh.

◆ HEXDIGITS

const string HEXDIGITS = "0123456789ABCDEF0123456789abcdef"

Definition at line 569 of file string.qh.

◆ HEXDIGITS_MINSET

const string HEXDIGITS_MINSET = "0123456789ABCDEFabcdef"

Definition at line 568 of file string.qh.