From: terencehill Date: Thu, 1 Sep 2016 13:35:03 +0000 (+0200) Subject: IS_DIGIT X-Git-Tag: xonotic-v0.8.2~625 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e2897355e6cd1ca18e9ab1547e188eab316ce79d;p=xonotic%2Fxonotic-data.pk3dir.git IS_DIGIT --- diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 4afc151f3..87636d24e 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -798,7 +798,7 @@ string find_last_color_code(string s) if (carets & 1) { if(i+1 <= len) - if(strstrofs("0123456789", substring(s, i+1, 1), 0) >= 0) + if(IS_DIGIT(substring(s, i+1, 1))) return substring(s, i, 2); if(i+4 <= len) diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 3207296a7..617891d8b 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -345,3 +345,6 @@ const string HEXDIGITS = "0123456789ABCDEF0123456789abcdef"; #define HEXDIGIT_TO_DEC(d) ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10) #define DEC_TO_HEXDIGIT(d) (substring(HEXDIGITS_MINSET, (d), 1)) #define IS_HEXDIGIT(d) (strstrofs(HEXDIGITS_MINSET, (d), 0) >= 0) + +const string DIGITS = "0123456789"; +#define IS_DIGIT(d) (strstrofs(DIGITS, (d), 0) >= 0) diff --git a/qcsrc/menu/xonotic/colorpicker.qc b/qcsrc/menu/xonotic/colorpicker.qc index b1e231c8b..357276e16 100644 --- a/qcsrc/menu/xonotic/colorpicker.qc +++ b/qcsrc/menu/xonotic/colorpicker.qc @@ -70,7 +70,7 @@ float XonoticColorpicker_mouseDrag(entity me, vector coords) while (i - 2 - carets >= 0 && substring(me.controlledTextbox.text, i - 2 - carets, 1) == "^") ++carets; if (carets & 1) - if(strstrofs("0123456789", substring(me.controlledTextbox.text, i-1, 1), 0) >= 0) + if(IS_DIGIT(substring(me.controlledTextbox.text, i-1, 1))) { me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0); diff --git a/qcsrc/menu/xonotic/serverlist.qc b/qcsrc/menu/xonotic/serverlist.qc index c8346fff8..cd3d702ab 100644 --- a/qcsrc/menu/xonotic/serverlist.qc +++ b/qcsrc/menu/xonotic/serverlist.qc @@ -961,7 +961,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is isv6 = true; me.seenIPv6 += 1; } - else if(strstrofs("0123456789", substring(s, 0, 1), 0) >= 0) + else if(IS_DIGIT(substring(s, 0, 1))) { isv4 = true; me.seenIPv4 += 1; diff --git a/qcsrc/server/bot/default/scripting.qc b/qcsrc/server/bot/default/scripting.qc index fa273410e..e8355575e 100644 --- a/qcsrc/server/bot/default/scripting.qc +++ b/qcsrc/server/bot/default/scripting.qc @@ -587,16 +587,12 @@ const int CMD_CONDITION_false_BLOCK = 8; float bot_cmd_eval(entity this, string expr) { // Search for numbers - if(strstrofs("0123456789", substring(expr, 0, 1), 0) >= 0) - { + if(IS_DIGIT(substring(expr, 0, 1))) return stof(expr); - } // Search for cvars if(substring(expr, 0, 5)=="cvar.") - { return cvar(substring(expr, 5, strlen(expr))); - } // Search for fields switch(expr)