]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add IS_HEXDIGIT macro and make use of it
authorterencehill <piuntn@gmail.com>
Thu, 1 Sep 2016 13:09:31 +0000 (15:09 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 1 Sep 2016 13:09:31 +0000 (15:09 +0200)
qcsrc/common/util.qc
qcsrc/lib/string.qh
qcsrc/menu/xonotic/colorpicker.qc

index 1c1278bfd538ddf3c6c8450bf5a7be7ed349655e..4afc151f32b8bc29c53a0dff1d764fa837e7ee47 100644 (file)
@@ -703,9 +703,9 @@ int skipIncompleteTag(string theText, float pos, int len)
        if(tag_start >= 0)
        {
                if(tag_start + 5 < len)
-               if(strstrofs("0123456789abcdefABCDEF", substring(theText, tag_start + 2, 1), 0) >= 0)
-               if(strstrofs("0123456789abcdefABCDEF", substring(theText, tag_start + 3, 1), 0) >= 0)
-               if(strstrofs("0123456789abcdefABCDEF", substring(theText, tag_start + 4, 1), 0) >= 0)
+               if(IS_HEXDIGIT(substring(theText, tag_start + 2, 1)))
+               if(IS_HEXDIGIT(substring(theText, tag_start + 3, 1)))
+               if(IS_HEXDIGIT(substring(theText, tag_start + 4, 1)))
                {
                        if(!isCaretEscaped(theText, tag_start))
                                return 5 - (pos - tag_start); // ^xRGB color code found
@@ -803,9 +803,9 @@ string find_last_color_code(string s)
 
                        if(i+4 <= len)
                        if(substring(s, i+1, 1) == "x")
-                       if(strstrofs("0123456789abcdefABCDEF", substring(s, i+2, 1), 0) >= 0)
-                       if(strstrofs("0123456789abcdefABCDEF", substring(s, i+3, 1), 0) >= 0)
-                       if(strstrofs("0123456789abcdefABCDEF", substring(s, i+4, 1), 0) >= 0)
+                       if(IS_HEXDIGIT(substring(s, i + 2, 1)))
+                       if(IS_HEXDIGIT(substring(s, i + 3, 1)))
+                       if(IS_HEXDIGIT(substring(s, i + 4, 1)))
                                return substring(s, i, 5);
                }
                i -= carets; // this also skips one char before the carets
index 2ade29691280beb373c05170f00b9e8d47667190..3207296a7dfdd19cdff4ef5dd6b47dddc5da6202 100644 (file)
@@ -339,7 +339,9 @@ int vercmp(string v1, string v2)
        return vercmp_recursive(v1, v2);
 }
 
+const string HEXDIGITS_MINSET = "0123456789ABCDEFabcdef";
 const string HEXDIGITS = "0123456789ABCDEF0123456789abcdef";
 #define HEXDIGIT_TO_DEC_RAW(d) (strstrofs(HEXDIGITS, (d), 0))
 #define HEXDIGIT_TO_DEC(d) ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)
-#define DEC_TO_HEXDIGIT(d) (substring(HEXDIGITS, (d), 1))
+#define DEC_TO_HEXDIGIT(d) (substring(HEXDIGITS_MINSET, (d), 1))
+#define IS_HEXDIGIT(d) (strstrofs(HEXDIGITS_MINSET, (d), 0) >= 0)
index b88d5d9a7d8f3973e5d828c0da66cac207db309a..b1e231c8bf246071b9158add7698830d38972738 100644 (file)
@@ -87,9 +87,9 @@ float XonoticColorpicker_mouseDrag(entity me, vector coords)
                                while (i - 5 - carets >= 0 && substring(me.controlledTextbox.text, i - 5 - carets, 1) == "^")
                                        ++carets;
                                if (carets & 1)
-                                       if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-3, 1), 0) >= 0)
-                                               if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-2, 1), 0) >= 0)
-                                                       if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-1, 1), 0) >= 0)
+                                       if(IS_HEXDIGIT(substring(me.controlledTextbox.text, i - 3, 1)))
+                                               if(IS_HEXDIGIT(substring(me.controlledTextbox.text, i - 2, 1)))
+                                                       if(IS_HEXDIGIT(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);