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)
 Returns 0 if pos is NOT in the middle or at the end of a color code otherwise it returns a vector with color code length as the first component and the offset from '^' position to pos as the second component e.g.: "j^2kl" | returns 0 if pos == 0 or 1 or 4 ^^ | returns '2 1' or '2 2' if pos == 2 or 3.
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)
 Returns the number of days since 0000-03-01 (March 1, year 0).
ERASEABLE string format_time (float seconds)
ERASEABLE string fstrunzone (string s)
 unzone the string, and return it as tempstring. Safe to be called on string_null
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)
 Returns true if the caret at position pos is escaped.
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 ()
 Returns the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
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"
 BG - White : neutral/unimportant text.
string autocvar_hud_colorset_foreground_1 = "2"
 F1 - Green : primary priority (important names, etc).
string autocvar_hud_colorset_foreground_2 = "3"
 F2 - Yellow : secondary priority (items, locations, numbers, etc).
string autocvar_hud_colorset_foreground_3 = "4"
 F3 - Blue : tertiary priority or relatively inconsequential text.
string autocvar_hud_colorset_foreground_4 = "1"
 F4 - Red : notice/attention grabbing texting.
string autocvar_hud_colorset_kill_1 = "1"
 K1 - Red : "bad" or "dangerous" text (death messages against you, kill notifications, etc).
string autocvar_hud_colorset_kill_2 = "3"
 K2 - Yellow : similar to above, but less important... OR, a highlight out of above message type.
string autocvar_hud_colorset_kill_3 = "4"
 K3 - Blue : "good" or "beneficial" text (you fragging someone, etc).
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 82 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:575

Definition at line 579 of file string.qh.

Referenced by rgb_to_hexcolor().

◆ endsWith

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

Definition at line 243 of file string.qh.

Referenced by spawnfunc().

◆ EVAL_PAR

#define EVAL_PAR ( ...)
Value:
__VA_ARGS__

Definition at line 658 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:577

Definition at line 578 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:576

Definition at line 577 of file string.qh.

◆ IS_DIGIT

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

Definition at line 583 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 580 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:145

Definition at line 173 of file string.qh.

◆ mmssth

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

Definition at line 174 of file string.qh.

◆ PAGE_TEXT

#define PAGE_TEXT   _page_text

Definition at line 651 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 650 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:657
#define EVAL_PAR(...)
Definition string.qh:658

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 657 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 659 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:659

Definition at line 660 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 661 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 662 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 663 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 664 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 665 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 666 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 667 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 51 of file string.qh.

51#define strcpy(this, s) MACRO_BEGIN \
52 if (this) \
53 strunzone(this); \
54 this = strzone(s); \
55MACRO_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(), strcpy(), UpdatePlayerSounds(), W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(), W_Reload(), waypoint_loadall(), waypoint_saveall(), welcomeDialog_resetStrings(), WinningConditionHelper(), WriteByte(), XonoticCampaignList_loadCvars(), XonoticCrosshairPreview_draw(), XonoticCvarList_setSelected(), XonoticGuideDescription_setDescription(), XonoticGuideDescription_wrapDescription(), 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 57 of file string.qh.

57#define strfree(this) MACRO_BEGIN \
58 if (this) \
59 strunzone(this); \
60 this = string_null; \
61MACRO_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_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(), 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 320 of file string.qh.

321{
323}
string _shufflewords_str
Definition string.qh:318
ERASEABLE string swapwords(string str, float i, float j)
Definition string.qh:299

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

Referenced by shufflewords().

◆ buf_load()

ERASEABLE int buf_load ( string pFilename)

Definition at line 444 of file string.qh.

445{
446 int buf = buf_create();
447 if (buf < 0)
448 return -1;
449 int fh = fopen(pFilename, FILE_READ);
450 if (fh < 0)
451 {
452 buf_del(buf);
453 return -1;
454 }
455 string l;
456 for (int i = 0; (l = fgets(fh)); ++i)
457 bufstr_set(buf, i, l);
458 fclose(fh);
459 return buf;
460}
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 463 of file string.qh.

464{
465 int fh = fopen(pFilename, FILE_WRITE);
466 if (fh < 0)
467 error(strcat("Can't write buf to ", pFilename));
468 int n = buf_getsize(buf);
469 for (int i = 0; i < n; ++i)
470 fputs(fh, strcat(bufstr_get(buf, i), "\n"));
471 fclose(fh);
472}
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 214 of file string.qh.

215{
216 // foreground/normal colors
217 input = strreplace("^F1", strcat("^", autocvar_hud_colorset_foreground_1), input);
218 input = strreplace("^F2", strcat("^", autocvar_hud_colorset_foreground_2), input);
219 input = strreplace("^F3", strcat("^", autocvar_hud_colorset_foreground_3), input);
220 input = strreplace("^F4", strcat("^", autocvar_hud_colorset_foreground_4), input);
221
222 // "kill" colors
223 input = strreplace("^K1", strcat("^", autocvar_hud_colorset_kill_1), input);
224 input = strreplace("^K2", strcat("^", autocvar_hud_colorset_kill_2), input);
225 input = strreplace("^K3", strcat("^", autocvar_hud_colorset_kill_3), input);
226
227 // background colors
228 input = strreplace("^BG", strcat("^", autocvar_hud_colorset_background), input);
229 input = strreplace("^N", "^7", input); // "none"-- reset to white...
230 return input;
231}
string autocvar_hud_colorset_foreground_1
F1 - Green : primary priority (important names, etc).
Definition string.qh:202
string autocvar_hud_colorset_kill_1
K1 - Red : "bad" or "dangerous" text (death messages against you, kill notifications,...
Definition string.qh:207
string autocvar_hud_colorset_kill_2
K2 - Yellow : similar to above, but less important... OR, a highlight out of above message type.
Definition string.qh:208
string autocvar_hud_colorset_foreground_3
F3 - Blue : tertiary priority or relatively inconsequential text.
Definition string.qh:204
string autocvar_hud_colorset_foreground_4
F4 - Red : notice/attention grabbing texting.
Definition string.qh:205
string autocvar_hud_colorset_background
BG - White : neutral/unimportant text.
Definition string.qh:211
string autocvar_hud_colorset_foreground_2
F2 - Yellow : secondary priority (items, locations, numbers, etc).
Definition string.qh:203
string autocvar_hud_colorset_kill_3
K3 - Blue : "good" or "beneficial" text (you fragging someone, etc).
Definition string.qh:209

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 )

Returns 0 if pos is NOT in the middle or at the end of a color code otherwise it returns a vector with color code length as the first component and the offset from '^' position to pos as the second component e.g.: "j^2kl" | returns 0 if pos == 0 or 1 or 4 ^^ | returns '2 1' or '2 2' if pos == 2 or 3.

Definition at line 616 of file string.qh.

617{
618 if (text_len == 0)
619 text_len = strlen(theText);
620 string tag_type = "^";
621 int cc_len = 2;
622 int tag_len = 1;
623
624 LABEL(check_color_tag)
625
626 int ofs = cc_len;
627 if (!check_at_the_end)
628 --ofs;
629 for (; ofs >= 1; --ofs)
630 {
631 if (!(pos >= ofs && text_len >= pos + (cc_len - ofs)))
632 continue;
633 if (substring(theText, pos - ofs, tag_len) == tag_type)
634 {
635 if (!isCaretEscaped(theText, pos - ofs) && isValidColorCodeValue(theText, cc_len, pos - ofs))
636 return eX * cc_len + eY * ofs;
637 }
638 }
639 if (cc_len == 2)
640 {
641 tag_type = "^x";
642 cc_len = 5;
643 tag_len = 2;
644 goto check_color_tag;
645 }
646 return '0 0 0';
647}
#define LABEL(id)
Definition compiler.qh:34
ERASEABLE bool isCaretEscaped(string theText, float pos)
Returns true if the caret at position pos is escaped.
Definition string.qh:587
ERASEABLE bool isValidColorCodeValue(string theText, int cc_len, int tag_start)
Definition string.qh:598
const vector eY
Definition vector.qh:44
const vector eX
Definition vector.qh:43

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 145 of file string.qh.

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

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

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 )

Returns the number of days since 0000-03-01 (March 1, year 0).

Starting counting from March, as the 1st month of the year, February becomes the 12th and last month, so its variable duration does not affect, given that the 29th is the last day of the period

Definition at line 67 of file string.qh.

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

References floor().

Referenced by strftime_s().

◆ format_time()

ERASEABLE string format_time ( float seconds)

Definition at line 177 of file string.qh.

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

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 247 of file string.qh.

248{
249 if (!s)
250 return s;
251 string sc = strcat(s, "");
252 strunzone(s);
253 return sc;
254}
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 476 of file string.qh.

477{
478 // inhibit stupid negative zero
479 if (number == 0) number = 0;
480 return sprintf("%.*f", decimals, number);
481}
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 485 of file string.qh.

486{
487 if (number == 0)
488 number = 0; // inhibit stupid negative zero
489 return sprintf(_("%.*f%%"), decimals, number * 100); // translatable percentage string
490}

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 502 of file string.qh.

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

Returns true if the caret at position pos is escaped.

Definition at line 587 of file string.qh.

588{
589 // count all the previous carets
590 int carets = 0;
591 while (pos - carets >= 1 && substring(theText, pos - carets - 1, 1) == "^")
592 ++carets;
593 // if number of previous carets is odd then this carets is escaped
594 return (carets & 1);
595}

References substring().

Referenced by checkColorCode(), and XonoticColorpicker_mouseDrag().

◆ isInvisibleString()

ERASEABLE bool isInvisibleString ( string s)

Definition at line 392 of file string.qh.

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

599{
600 if (cc_len == 2)
601 return IS_DIGIT(substring(theText, tag_start + 1, 1));
602 if (cc_len == 5)
603 return (IS_HEXDIGIT(substring(theText, tag_start + 2, 1))
604 && IS_HEXDIGIT(substring(theText, tag_start + 3, 1))
605 && IS_HEXDIGIT(substring(theText, tag_start + 4, 1)));
606 return false;
607}
#define IS_DIGIT(d)
Definition string.qh:583
#define IS_HEXDIGIT(d)
Definition string.qh:580

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 123 of file string.qh.

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

References floor().

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

◆ shufflewords()

ERASEABLE string shufflewords ( string str)

Definition at line 326 of file string.qh.

327{
328 _shufflewords_str = str;
329 int n = tokenizebyseparator(str, " ");
331 str = _shufflewords_str;
333 return str;
334}
#define tokenizebyseparator
#define NULL
Definition post.qh:14
ERASEABLE void shuffle(float n, swapfunc_t swap, entity pass)
Definition sort.qh:40
ERASEABLE void _shufflewords_swapfunc(float i, float j, entity pass)
Definition string.qh:320

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

◆ startsWithNocase()

ERASEABLE bool startsWithNocase ( string haystack,
string needle )

Definition at line 237 of file string.qh.

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

References strcasecmp, strlen, and substring().

Referenced by MapInfo_FindName().

◆ strftime_s()

ERASEABLE string strftime_s ( )

Returns the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).

This function exists only as a replacement for strftime(false, "%s") which doesn't work on Windows (s is not supported) and at least in some linux systems doesn't return the correct result. NOTE: at the current date, the number (string) returned by both strftime(false, "%s") and strftime_s() is so high that can't be converted to int (with ftos) without precision loss

Definition at line 91 of file string.qh.

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

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 365 of file string.qh.

366{
367 int endpos = 0;
368 for (; w && endpos >= 0; --w)
369 endpos = strstrofs(s, " ", endpos + 1);
370 if (endpos < 0)
371 return s;
372 return substring(s, 0, endpos);
373}

References strstrofs, and substring().

Referenced by Map_MarkAsRecent().

◆ substring_range()

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

Definition at line 293 of file string.qh.

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

References substring().

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

◆ swapwords()

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

Definition at line 299 of file string.qh.

300{
301 string s1, s2, s3, s4, s5;
302 float si, ei, sj, ej, s0, en;
303 int n = tokenizebyseparator(str, " ");
304 si = argv_start_index(i);
305 sj = argv_start_index(j);
306 ei = argv_end_index(i);
307 ej = argv_end_index(j);
308 s0 = argv_start_index(0);
309 en = argv_end_index(n - 1);
310 s1 = substring_range(str, s0, si);
311 s2 = argv(i);
312 s3 = substring_range(str, ei, sj);
313 s4 = argv(j);
314 s5 = substring_range(str, ej, en);
315 return strcat(s1, s4, s3, s2, s5);
316}
#define argv_end_index
#define argv_start_index
string argv(float n)
spree_inf s1 s2 s3loc s2 s1
Definition all.inc:284
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:474
ERASEABLE string substring_range(string s, float b, float e)
Definition string.qh:293

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 378 of file string.qh.

379{
380 int l = 0;
381 for (int i = 0, c; (c = str2chr(s, i)) > 0; ++i, ++l)
382 {
383 l += (c >= 0x80);
384 l += (c >= 0x800);
385 l += (c >= 0x10000);
386 }
387 return l;
388}

References str2chr.

Referenced by InputBox_enterText().

◆ unescape()

ERASEABLE string unescape ( string in)

Definition at line 337 of file string.qh.

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

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

◆ vercmp()

ERASEABLE int vercmp ( string v1,
string v2 )

Definition at line 563 of file string.qh.

564{
565 if (strcasecmp(v1, v2) == 0)
566 return 0; // early out check
567
568 // "git" beats all
569 if (v1 == "git") return 1;
570 if (v2 == "git") return -1;
571
572 return vercmp_recursive(v1, v2);
573}
ERASEABLE int vercmp_recursive(string v1, string v2)
Definition string.qh:543

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 543 of file string.qh.

544{
545 int dot1 = strstrofs(v1, ".", 0);
546 int dot2 = strstrofs(v2, ".", 0);
547 string s1 = (dot1 == -1) ? v1 : substring(v1, 0, dot1);
548 string s2 = (dot2 == -1) ? v2 : substring(v2, 0, dot2);
549
550 float r = stof(s1) - stof(s2);
551 if (r != 0)
552 return r;
553 r = strcasecmp(s1, s2);
554 if (r != 0)
555 return r;
556
557 if (dot1 == -1)
558 return (dot2 == -1) ? 0 : -1;
559 return (dot2 == -1) ? 1 : vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
560}

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 242 of file string.qh.

◆ _shufflewords_str

string _shufflewords_str

Definition at line 318 of file string.qh.

Referenced by _shufflewords_swapfunc(), and shufflewords().

◆ autocvar_hud_colorset_background

string autocvar_hud_colorset_background = "7"

BG - White : neutral/unimportant text.

Definition at line 211 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_foreground_1

string autocvar_hud_colorset_foreground_1 = "2"

F1 - Green : primary priority (important names, etc).

Definition at line 202 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_foreground_2

string autocvar_hud_colorset_foreground_2 = "3"

F2 - Yellow : secondary priority (items, locations, numbers, etc).

Definition at line 203 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_foreground_3

string autocvar_hud_colorset_foreground_3 = "4"

F3 - Blue : tertiary priority or relatively inconsequential text.

Definition at line 204 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_foreground_4

string autocvar_hud_colorset_foreground_4 = "1"

F4 - Red : notice/attention grabbing texting.

Definition at line 205 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_kill_1

string autocvar_hud_colorset_kill_1 = "1"

K1 - Red : "bad" or "dangerous" text (death messages against you, kill notifications, etc).

Definition at line 207 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_kill_2

string autocvar_hud_colorset_kill_2 = "3"

K2 - Yellow : similar to above, but less important... OR, a highlight out of above message type.

Definition at line 208 of file string.qh.

Referenced by CCR().

◆ autocvar_hud_colorset_kill_3

string autocvar_hud_colorset_kill_3 = "4"

K3 - Blue : "good" or "beneficial" text (you fragging someone, etc).

Definition at line 209 of file string.qh.

Referenced by CCR().

◆ ColorTranslateMode

int ColorTranslateMode

Definition at line 191 of file string.qh.

Referenced by ColorTranslateRGB(), and CSQC_UpdateView().

◆ DIGITS

const string DIGITS = "0123456789"

Definition at line 582 of file string.qh.

◆ HEXDIGITS

const string HEXDIGITS = "0123456789ABCDEF0123456789abcdef"

Definition at line 576 of file string.qh.

◆ HEXDIGITS_MINSET

const string HEXDIGITS_MINSET = "0123456789ABCDEFabcdef"

Definition at line 575 of file string.qh.