Xonotic
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)   (substring(HEXDIGITS_MINSET, (d), 1))
 
#define endsWith(this, suffix)   (_endsWith_suffix = suffix, substring(this, -strlen(_endsWith_suffix), -1) == _endsWith_suffix)
 
#define HEXDIGIT_TO_DEC(d)   ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)
 
#define HEXDIGIT_TO_DEC_RAW(d)   (strstrofs(HEXDIGITS, (d), 0))
 
#define IS_DIGIT(d)   (strstrofs(DIGITS, (d), 0) >= 0)
 
#define IS_HEXDIGIT(d)   (strstrofs(HEXDIGITS_MINSET, (d), 0) >= 0)
 
#define mmsst(tm)   clockedtime_tostring(tm, false)
 
#define mmssth(tm)   clockedtime_tostring(tm, true)
 
#define startsWith(haystack, needle)   (strstrofs(haystack, needle, 0) == 0)
 
#define strcpy(this, s)
 
#define strfree(this)
 
#define strhasword(s, w)   (strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0)
 

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 More...
 
ERASEABLE string cdr (string s)
 returns all but first word More...
 
ERASEABLE vector checkColorCode (string theText, int text_len, int pos, bool check_at_the_end)
 
ERASEABLE string clockedtime_tostring (int tm, bool hundredths)
 
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. More...
 
ERASEABLE string ftos_decimals (float number, int decimals)
 converts a number to a string with the indicated number of decimals More...
 
ERASEABLE string ftos_mindecimals (float number)
 converts a number to a string with the minimum number of decimals More...
 
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 ()
 
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
 
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)    (substring(HEXDIGITS_MINSET, (d), 1))

Definition at line 503 of file string.qh.

Referenced by rgb_to_hexcolor().

◆ endsWith

#define endsWith (   this,
  suffix 
)    (_endsWith_suffix = suffix, substring(this, -strlen(_endsWith_suffix), -1) == _endsWith_suffix)

Definition at line 226 of file string.qh.

Referenced by spawnfunc(), and SUB_CalcAngleMoveEnt().

◆ HEXDIGIT_TO_DEC

#define HEXDIGIT_TO_DEC (   d)    ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)

Definition at line 502 of file string.qh.

Referenced by InputBox_draw().

◆ HEXDIGIT_TO_DEC_RAW

#define HEXDIGIT_TO_DEC_RAW (   d)    (strstrofs(HEXDIGITS, (d), 0))

Definition at line 501 of file string.qh.

◆ IS_DIGIT

#define IS_DIGIT (   d)    (strstrofs(DIGITS, (d), 0) >= 0)

◆ IS_HEXDIGIT

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

Definition at line 504 of file string.qh.

Referenced by find_last_color_code(), and isValidColorCodeValue().

◆ mmsst

#define mmsst (   tm)    clockedtime_tostring(tm, false)

Definition at line 157 of file string.qh.

◆ mmssth

#define mmssth (   tm)    clockedtime_tostring(tm, true)

Definition at line 158 of file string.qh.

◆ startsWith

#define startsWith (   haystack,
  needle 
)    (strstrofs(haystack, needle, 0) == 0)

◆ strcpy

#define strcpy (   this,
 
)
Value:
if (this) { \
strunzone(this); \
} \
this = strzone(s); \
MACRO_END
if(IS_DEAD(this))
Definition: impulse.qc:92

Definition at line 49 of file string.qh.

Referenced by Accuracy_LoadLevels(), bd_close_editor(), bd_do_next_match(), bd_move_dozer(), bd_set_next_match(), bd_set_nextlevel(), bot_custom_weapon_priority_setup(), bot_decodecommand(), centerprint_Add(), Cmd_Scoreboard_SetFields(), DamageText::DamageText_update(), GENERIC_COMMAND(), GetCvars_handleString(), GetCvars_handleString_Fixup(), getwelcomemessage(), HUD_Chat(), HUD_Main(), HUD_Panel_FirstInDrawQ(), HUD_Radar(), HUD_Weapons(), Label_draw(), Label_setText(), LoadPlayerSounds(), Local_Notification_sprintf(), LocalCommand_sendcvar(), m_goto(), m_tooltip(), Maplist_Init(), Model::Model ::model_precache(), Monster_Sounds_Load(), MUTATOR_HOOKFUNCTION(), NET_HANDLE(), OnlineBanList_Think(), PlayerPreThink(), 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(), Sound::Sound ::sound_precache(), spawnfunc(), swapInPriorityList(), UpdatePlayerSounds(), W_Model(), W_Reload(), waypoint_loadall(), waypoint_saveall(), WinningConditionHelper(), XonoticCampaignList_loadCvars(), XonoticCrosshairPreview_draw(), XonoticCvarList_setSelected(), XonoticMapInfoDialog_loadMapInfo(), XonoticMapList_keyDown(), XonoticMapList_refilter(), XonoticPlayerModelSelector_go(), XonoticScreenshotBrowserTab_loadPreviewScreenshot(), XonoticScreenshotImage_load(), XonoticScreenshotViewerDialog_loadScreenshot(), XonoticServerList_draw(), and XonoticServerList_setSelected().

◆ strfree

#define strfree (   this)
Value:
if (this) { \
strunzone(this); \
} \
this = string_null; \
MACRO_END
string string_null
Definition: nil.qh:9
if(IS_DEAD(this))
Definition: impulse.qc:92

Definition at line 56 of file string.qh.

Referenced by AdditionalServerInfo_OnGet(), bd_close_editor(), bd_editor_place(), bd_setup_pieces(), bd_unfill_recurse(), BGMScript_InitEntity(), bot_clientdisconnect(), c4_move(), CampaignFile_Unload(), centerprint_KillAll(), ClearPlayerSounds(), ClientDisconnect(), Cmd_Scoreboard_SetFields(), cvar_changes_init(), DamageText::DamageText ::~ DamageText(), DelayThink(), DemoList_Filter_Change(), end_minigame(), execute_next_frame(), func_ladder_think(), GameType_ConfigureSliders(), GENERIC_COMMAND(), GetCvars_handleString(), HUD_Crosshair(), HUDSkinList_Filter_Change(), HUDSkinList_SavedName_Change(), InputBox_setText(), ItemRemove(), Local_Notification_WOVA(), LocalCommand_sendcvar(), m_init_delayed(), m_tooltip(), MapList_StringFilterBox_Change(), MapVote_UnzoneStrings(), MUTATOR_HOOKFUNCTION(), MX_Say_(), NET_HANDLE(), nmm_kill_tiles(), pp_move(), pp_next_match(), ps_move(), ps_move_piece(), 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(), setZonedTooltip(), Shutdown(), SL_ProcessCategoryOverrides(), SoundList_Filter_Change(), STATIC_INIT(), trigger_push_findtarget(), ttt_next_match(), url_fclose(), url_multi_ready(), url_single_fopen(), url_URI_Get_Callback(), VoteReset(), XonoticCvarList_setSelected(), XonoticKeyBinder_destroy(), XonoticServerInfoDialog_loadServerInfo(), XonoticServerList_setSortOrder(), and XonoticToS_OnGet().

◆ strhasword

#define strhasword (   s,
 
)    (strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0)

Function Documentation

◆ _shufflewords_swapfunc()

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

Definition at line 301 of file string.qh.

References _shufflewords_str, ERASEABLE, and swapwords().

Referenced by shufflewords().

302 {
304 }
ERASEABLE string swapwords(string str, float i, float j)
Definition: string.qh:279
string _shufflewords_str
Definition: string.qh:299
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buf_load()

ERASEABLE int buf_load ( string  pFilename)

Definition at line 418 of file string.qh.

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

419 {
420  int buf = buf_create();
421  if (buf < 0) return -1;
422  int fh = fopen(pFilename, FILE_READ);
423  if (fh < 0)
424  {
425  buf_del(buf);
426  return -1;
427  }
428  string l;
429  for (int i = 0; (l = fgets(fh)); ++i)
430  bufstr_set(buf, i, l);
431  fclose(fh);
432  return buf;
433 }
const float FILE_READ
Definition: csprogsdefs.qc:231
#define buf_create
Definition: dpextensions.qh:63
+ Here is the call graph for this function:

◆ buf_save()

ERASEABLE void buf_save ( float  buf,
string  pFilename 
)

Definition at line 436 of file string.qh.

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

437 {
438  int fh = fopen(pFilename, FILE_WRITE);
439  if (fh < 0) error(strcat("Can't write buf to ", pFilename));
440  int n = buf_getsize(buf);
441  for (int i = 0; i < n; ++i)
442  fputs(fh, strcat(bufstr_get(buf, i), "\n"));
443  fclose(fh);
444 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
const float FILE_WRITE
Definition: csprogsdefs.qc:233
+ Here is the call graph for this function:

◆ car()

ERASEABLE string car ( string  s)

returns first word

Definition at line 240 of file string.qh.

References ERASEABLE, strstrofs, and substring().

Referenced by _MapInfo_Generate(), _MapInfo_Map_ApplyGametype(), _MapInfo_Map_ApplyGametypeEx(), _MapInfo_Parse_Settemp(), GameCommand_adminmsg(), GameCommand_moveplayer(), get_model_parameters(), GlobalSound_sample(), Local_Notification_sprintf(), MapInfo_Get_ByName_NoFallbacks(), matchacl(), PrecacheGlobalSound(), Process_Notif_Args(), STATIC_INIT_LATE(), and W_GetCycleWeapon().

241 {
242  int o = strstrofs(s, " ", 0);
243  if (o < 0) return s;
244  return substring(s, 0, o);
245 }
#define strstrofs
Definition: dpextensions.qh:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cdr()

ERASEABLE string cdr ( string  s)

returns all but first word

Definition at line 249 of file string.qh.

References ERASEABLE, string_null, strlen(), strstrofs, and substring().

Referenced by _MapInfo_Generate(), _MapInfo_Map_ApplyGametype(), _MapInfo_Map_ApplyGametypeEx(), _MapInfo_Parse_Settemp(), GameCommand_adminmsg(), GameCommand_moveplayer(), get_model_parameters(), GlobalSound_sample(), Local_Notification_sprintf(), MapInfo_Get_ByName_NoFallbacks(), matchacl(), PrecacheGlobalSound(), Process_Notif_Args(), STATIC_INIT_LATE(), and W_GetCycleWeapon().

250 {
251  int o = strstrofs(s, " ", 0);
252  if (o < 0) return string_null;
253  return substring(s, o + 1, strlen(s) - (o + 1));
254 }
string string_null
Definition: nil.qh:9
#define strstrofs
Definition: dpextensions.qh:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkColorCode()

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

Definition at line 540 of file string.qh.

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

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

541 {
542  if (text_len == 0)
543  text_len = strlen(theText);
544  string tag_type = "^";
545  int cc_len = 2;
546  int tag_len = 1;
547 
548  LABEL(check_color_tag)
549 
550  int ofs = cc_len;
551  if (!check_at_the_end)
552  ofs--;
553  for (; ofs >= 1; ofs--)
554  {
555  if (!(pos >= ofs && text_len >= pos + (cc_len - ofs)))
556  continue;
557  if(substring(theText, pos - ofs, tag_len) == tag_type)
558  {
559  if (!isCaretEscaped(theText, pos - ofs) && isValidColorCodeValue(theText, cc_len, pos - ofs))
560  return eX * cc_len + eY * ofs;
561  }
562  }
563  if (cc_len == 2)
564  {
565  tag_type = "^x";
566  cc_len = 5;
567  tag_len = 2;
568  goto check_color_tag;
569  }
570  return '0 0 0';
571 }
const vector eY
Definition: vector.qh:45
ERASEABLE bool isCaretEscaped(string theText, float pos)
Definition: string.qh:511
ERASEABLE bool isValidColorCodeValue(string theText, int cc_len, int tag_start)
Definition: string.qh:522
const vector eX
Definition: vector.qh:44
#define LABEL(id)
Definition: compiler.qh:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clockedtime_tostring()

ERASEABLE string clockedtime_tostring ( int  tm,
bool  hundredths 
)
Parameters
[in]tminteger clocked time in tenths or hundredths, CANNOT be negative
[in]hundredthsif true append hundredths too, otherwise only tenths
Returns
clocked time as "m:ss.t" or "m:ss.th" string (rounded)

Definition at line 144 of file string.qh.

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

145 {
146  if (tm < 0)
147  return strcat("0:00:0", hundredths ? "0" : "");
148  int acc = hundredths ? 6000 : 600;
149  int seconds = floor(tm + 0.5);
150  int minutes = floor(seconds / acc);
151  seconds -= minutes * acc;
152  // NOTE: the start digit of s is a placeholder and won't be displayed
153  string s = ftos(acc * 10 + seconds);
154  return strcat(ftos(minutes), ":", substring(s, 1, 2), ".", substring(s, 3, hundredths ? 2 : 1));
155 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:

◆ ColorTranslateRGB()

ERASEABLE string ColorTranslateRGB ( string  s)

Definition at line 177 of file string.qh.

References ColorTranslateMode, and strcat().

Referenced by CSQC_Parse_Print(), and Scoreboard_Rankings_Draw().

178 {
179  return (ColorTranslateMode & 1) ? strdecolorize(s) : s;
180 }
int ColorTranslateMode
Definition: string.qh:174
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cons()

ERASEABLE string cons ( string  a,
string  b 
)

Definition at line 257 of file string.qh.

References ERASEABLE, and strcat().

Referenced by _json_parse_pair(), Gametype::Gametype ::gametype_init(), GenericCommand_addtolist(), GenericCommand_maplist(), GenericCommand_removefromlist(), Map_MarkAsRecent(), Say(), spawnfunc(), W_Apply_Weaponreplace(), waypoint_loadall(), and waypoint_saveall().

258 {
259  if (a == "") return b;
260  if (b == "") return a;
261  return strcat(a, " ", b);
262 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cons_mid()

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

Definition at line 265 of file string.qh.

References ERASEABLE, and strcat().

Referenced by XonoticMutatorsDialog_toString().

266 {
267  if (a == "") return b;
268  if (b == "") return a;
269  return strcat(a, mid, b);
270 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ days_up_to_date()

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

Definition at line 67 of file string.qh.

References floor().

Referenced by strftime_s().

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 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ format_time()

ERASEABLE string format_time ( float  seconds)

Definition at line 161 of file string.qh.

References floor().

162 {
163  seconds = floor(seconds + 0.5);
164  float days = floor(seconds / 864000);
165  seconds -= days * 864000;
166  float hours = floor(seconds / 36000);
167  seconds -= hours * 36000;
168  float minutes = floor(seconds / 600);
169  seconds -= minutes * 600;
170  if (days > 0) return sprintf(_("%d days, %02d:%02d:%02d"), days, hours, minutes, seconds);
171  else return sprintf(_("%02d:%02d:%02d"), hours, minutes, seconds);
172 }
+ Here is the call graph for this function:

◆ fstrunzone()

ERASEABLE string fstrunzone ( string  s)

unzone the string, and return it as tempstring.

Safe to be called on string_null

Definition at line 230 of file string.qh.

References ERASEABLE, strcat(), and strunzone().

231 {
232  if (!s) return s;
233  string sc = strcat(s, "");
234  strunzone(s);
235  return sc;
236 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:

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

References ERASEABLE.

Referenced by DrawDomItem(), HUD_Physics(), HUD_Score(), HUD_StrafeHUD(), MakeRaceString(), MUTATOR_HOOKFUNCTION(), Slider_valueToText(), waypoint_save_links(), and waypoint_saveall().

451 {
452  // inhibit stupid negative zero
453  if (number == 0) number = 0;
454  return sprintf("%.*f", decimals, number);
455 }
int int number
Definition: impulse.qc:89
+ Here is the caller graph for this function:

◆ ftos_mindecimals()

ERASEABLE string ftos_mindecimals ( float  number)

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

Definition at line 461 of file string.qh.

References ERASEABLE.

Referenced by XonoticCheckBox_saveCvars(), and XonoticSlider_saveCvars().

462 {
463  // inhibit stupid negative zero
464  if (number == 0) number = 0;
465  return sprintf("%.7g", number);
466 }
int int number
Definition: impulse.qc:89
+ Here is the caller graph for this function:

◆ isCaretEscaped()

ERASEABLE bool isCaretEscaped ( string  theText,
float  pos 
)

Definition at line 511 of file string.qh.

References ERASEABLE, and substring().

Referenced by checkColorCode(), and XonoticColorpicker_mouseDrag().

512 {
513  // count all the previous carets
514  int carets = 0;
515  while(pos - carets >= 1 && substring(theText, pos - carets - 1, 1) == "^")
516  ++carets;
517  // if number of previous carets is odd then this carets is escaped
518  return (carets & 1);
519 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isInvisibleString()

ERASEABLE bool isInvisibleString ( string  s)

Definition at line 369 of file string.qh.

References cvar(), ERASEABLE, str2chr, and strlen().

Referenced by PlayerPreThink().

370 {
371  s = strdecolorize(s);
372  bool utf8 = cvar("utf8_enable");
373  for (int i = 0, n = strlen(s); i < n; ++i)
374  {
375  int c = str2chr(s, i);
376  switch (c)
377  {
378  case 0:
379  case 32: // space
380  break;
381  case 192: // charmap space
382  if (!utf8) break;
383  return false;
384  case 0xE000: // invisible char of the utf8 quake charmap
385  case 0xE00A: // invisible char of the utf8 quake charmap
386  case 0xE0A0: // invisible char of the utf8 quake charmap
387  case 0xE020: // invisible char of the utf8 quake charmap
388  case 0x00A0: // NO-BREAK SPACE
389  //case 0x1680: // OGHAM SPACE MARK
390  case 0x180E: // MONGOLIAN VOWEL SEPARATOR
391  case 0x2000: // EN QUAD
392  case 0x2001: // EM QUAD
393  case 0x2002: // EN SPACE
394  case 0x2003: // EM SPACE
395  case 0x2004: // THREE-PER-EM SPACE
396  case 0x2005: // FOUR-PER-EM SPACE
397  case 0x2006: // SIX-PER-EM SPACE
398  case 0x2007: // FIGURE SPACE
399  case 0x2008: // PUNCTUATION SPACE
400  case 0x2009: // THIN SPACE
401  case 0x200A: // HAIR SPACE
402  case 0x200B: // ZERO WIDTH SPACE
403  case 0x202F: // NARROW NO-BREAK SPACE
404  case 0x205F: // MEDIUM MATHEMATICAL SPACE
405  case 0x3000: // IDEOGRAPHIC SPACE
406  case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE
407  if (utf8) break;
408  default:
409  return false;
410  }
411  }
412  return true;
413 }
#define str2chr
Definition: dpextensions.qh:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidColorCodeValue()

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

Definition at line 522 of file string.qh.

References ERASEABLE, IS_DIGIT, IS_HEXDIGIT, and substring().

Referenced by checkColorCode().

523 {
524  if (cc_len == 2)
525  return IS_DIGIT(substring(theText, tag_start + 1, 1));
526  if (cc_len == 5)
527  return (IS_HEXDIGIT(substring(theText, tag_start + 2, 1))
528  && IS_HEXDIGIT(substring(theText, tag_start + 3, 1))
529  && IS_HEXDIGIT(substring(theText, tag_start + 4, 1)));
530  return false;
531 }
#define IS_DIGIT(d)
Definition: string.qh:507
#define IS_HEXDIGIT(d)
Definition: string.qh:504
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

References ERASEABLE, and floor().

Referenced by formatmessage(), and HUD_Timer().

124 {
125  bool negative = false;
126  if (seconds < 0)
127  {
128  negative = true;
129  seconds = -seconds;
130  if (floor(seconds) != seconds)
131  seconds += 1; // 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 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shufflewords()

ERASEABLE string shufflewords ( string  str)

Definition at line 307 of file string.qh.

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

Referenced by GenericCommand_maplist(), and ShuffleMaplist().

308 {
309  _shufflewords_str = str;
310  int n = tokenizebyseparator(str, " ");
312  str = _shufflewords_str;
314  return str;
315 }
string string_null
Definition: nil.qh:9
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:301
#define NULL
Definition: post.qh:17
#define tokenizebyseparator
Definition: dpextensions.qh:21
string _shufflewords_str
Definition: string.qh:299
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startsWithNocase()

ERASEABLE bool startsWithNocase ( string  haystack,
string  needle 
)

Definition at line 220 of file string.qh.

References strcasecmp, strlen(), and substring().

Referenced by MapInfo_FindName().

221 {
222  return strcasecmp(substring(haystack, 0, strlen(needle)), needle) == 0;
223 }
#define strcasecmp
Definition: dpextensions.qh:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strftime_s()

ERASEABLE string strftime_s ( )

Definition at line 91 of file string.qh.

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

Referenced by IntermissionThink(), and spawnfunc().

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 }
ERASEABLE int days_up_to_date(int Y, int M, int D)
Definition: string.qh:67
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define DAYS_UP_TO_EPOCH
Definition: string.qh:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strwords()

ERASEABLE string strwords ( string  s,
int  w 
)

Definition at line 343 of file string.qh.

References strstrofs, and substring().

Referenced by Map_MarkAsRecent().

344 {
345  int endpos = 0;
346  for ( ; w && endpos >= 0; --w)
347  endpos = strstrofs(s, " ", endpos + 1);
348  if (endpos < 0) return s;
349  return substring(s, 0, endpos);
350 }
#define strstrofs
Definition: dpextensions.qh:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ substring_range()

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

Definition at line 273 of file string.qh.

References ERASEABLE, and substring().

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

274 {
275  return substring(s, b, e - b);
276 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ swapwords()

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

Definition at line 279 of file string.qh.

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

Referenced by _shufflewords_swapfunc().

280 {
281  float n;
282  string s1, s2, s3, s4, s5;
283  float si, ei, sj, ej, s0, en;
284  n = tokenizebyseparator(str, " "); // must match g_maplist processing in ShuffleMaplist and "shuffle"
285  si = argv_start_index(i);
286  sj = argv_start_index(j);
287  ei = argv_end_index(i);
288  ej = argv_end_index(j);
289  s0 = argv_start_index(0);
290  en = argv_end_index(n - 1);
291  s1 = substring_range(str, s0, si);
292  s2 = substring_range(str, si, ei);
293  s3 = substring_range(str, ei, sj);
294  s4 = substring_range(str, sj, ej);
295  s5 = substring_range(str, ej, en);
296  return strcat(s1, s4, s3, s2, s5);
297 }
spree_inf s1 s2 s3loc s2 s1
Definition: all.inc:265
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 s2loc s1 s2 f1 f1points s1 s2
Definition: all.inc:438
ERASEABLE string substring_range(string s, float b, float e)
Definition: string.qh:273
#define argv_end_index
Definition: dpextensions.qh:30
#define argv_start_index
Definition: dpextensions.qh:27
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define tokenizebyseparator
Definition: dpextensions.qh:21
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ u8_strsize()

ERASEABLE int u8_strsize ( string  s)

Definition at line 355 of file string.qh.

References ERASEABLE, and str2chr.

Referenced by InputBox_enterText().

356 {
357  int l = 0;
358  for (int i = 0, c; (c = str2chr(s, i)) > 0; ++i, ++l)
359  {
360  l += (c >= 0x80);
361  l += (c >= 0x800);
362  l += (c >= 0x10000);
363  }
364  return l;
365 }
#define str2chr
Definition: dpextensions.qh:45
+ Here is the caller graph for this function:

◆ unescape()

ERASEABLE string unescape ( string  in)

Definition at line 318 of file string.qh.

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

319 {
320  in = strzone(in); // but it doesn't seem to be necessary in my tests at least
321 
322  int len = strlen(in);
323  string str = "";
324  for (int i = 0; i < len; ++i)
325  {
326  string s = substring(in, i, 1);
327  if (s == "\\")
328  {
329  s = substring(in, i + 1, 1);
330  if (s == "n") str = strcat(str, "\n");
331  else if (s == "\\") str = strcat(str, "\\");
332  else str = strcat(str, substring(in, i, 2));
333  ++i;
334  continue;
335  }
336  str = strcat(str, s);
337  }
338  strunzone(in);
339  return str;
340 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:

◆ vercmp()

ERASEABLE int vercmp ( string  v1,
string  v2 
)

Definition at line 488 of file string.qh.

References strcasecmp, and vercmp_recursive().

Referenced by PlayerPreThink(), and UpdateNotification_URI_Get_Callback().

489 {
490  if (strcasecmp(v1, v2) == 0) return 0; // early out check
491 
492  // "git" beats all
493  if (v1 == "git") return 1;
494  if (v2 == "git") return -1;
495 
496  return vercmp_recursive(v1, v2);
497 }
ERASEABLE int vercmp_recursive(string v1, string v2)
Definition: string.qh:469
#define strcasecmp
Definition: dpextensions.qh:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vercmp_recursive()

ERASEABLE int vercmp_recursive ( string  v1,
string  v2 
)

Definition at line 469 of file string.qh.

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

Referenced by vercmp().

470 {
471  int dot1 = strstrofs(v1, ".", 0);
472  int dot2 = strstrofs(v2, ".", 0);
473  string s1 = (dot1 == -1) ? v1 : substring(v1, 0, dot1);
474  string s2 = (dot2 == -1) ? v2 : substring(v2, 0, dot2);
475 
476  float r;
477  r = stof(s1) - stof(s2);
478  if (r != 0) return r;
479 
480  r = strcasecmp(s1, s2);
481  if (r != 0) return r;
482 
483  if (dot1 == -1) return (dot2 == -1) ? 0 : -1;
484  else return (dot2 == -1) ? 1 : vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
485 }
spree_inf s1 s2 s3loc s2 s1
Definition: all.inc:265
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 s2loc s1 s2 f1 f1points s1 s2
Definition: all.inc:438
ERASEABLE int vercmp_recursive(string v1, string v2)
Definition: string.qh:469
#define strstrofs
Definition: dpextensions.qh:42
#define strcasecmp
Definition: dpextensions.qh:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ _endsWith_suffix

noref string _endsWith_suffix

Definition at line 225 of file string.qh.

◆ _shufflewords_str

string _shufflewords_str

Definition at line 299 of file string.qh.

Referenced by _shufflewords_swapfunc(), and shufflewords().

◆ ColorTranslateMode

int ColorTranslateMode

Definition at line 174 of file string.qh.

Referenced by ColorTranslateRGB(), and CSQC_UpdateView().

◆ DIGITS

const string DIGITS = "0123456789"

Definition at line 506 of file string.qh.

◆ HEXDIGITS

const string HEXDIGITS = "0123456789ABCDEF0123456789abcdef"

Definition at line 500 of file string.qh.

◆ HEXDIGITS_MINSET

const string HEXDIGITS_MINSET = "0123456789ABCDEFabcdef"

Definition at line 499 of file string.qh.