[nexuiz-commits] r8392 - trunk/data/qcsrc/common
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Mon Dec 14 10:56:14 EST 2009
Author: div0
Date: 2009-12-14 10:56:13 -0500 (Mon, 14 Dec 2009)
New Revision: 8392
Modified:
trunk/data/qcsrc/common/mapinfo.qc
trunk/data/qcsrc/common/util.qc
trunk/data/qcsrc/common/util.qh
Log:
moved ACL stuff to util.qc
Modified: trunk/data/qcsrc/common/mapinfo.qc
===================================================================
--- trunk/data/qcsrc/common/mapinfo.qc 2009-12-13 19:29:35 UTC (rev 8391)
+++ trunk/data/qcsrc/common/mapinfo.qc 2009-12-14 15:56:13 UTC (rev 8392)
@@ -1,66 +1,5 @@
// generic string stuff
-float startsWith(string haystack, string needle)
-{
- return substring(haystack, 0, strlen(needle)) == needle;
-}
-float startsWithNocase(string haystack, string needle)
-{
- return strcasecmp(substring(haystack, 0, strlen(needle)), needle) == 0;
-}
-string extractRestOfLine(string haystack, string needle)
-{
- if(startsWith(haystack, needle))
- return substring(haystack, strlen(needle), strlen(haystack) - strlen(needle));
- return string_null;
-}
-string car(string s)
-{
- float o;
- o = strstrofs(s, " ", 0);
- if(o < 0)
- return s;
- return substring(s, 0, o);
-}
-string cdr(string s)
-{
- float o;
- o = strstrofs(s, " ", 0);
- if(o < 0)
- return string_null;
- return substring(s, o + 1, strlen(s) - (o + 1));
-}
-float matchacl(string acl, string str)
-{
- string t, s;
- float r, d;
- r = 0;
- while(acl)
- {
- t = car(acl); acl = cdr(acl);
- d = 1;
- if(substring(t, 0, 1) == "-")
- {
- d = -1;
- t = substring(t, 1, strlen(t) - 1);
- }
- else if(substring(t, 0, 1) == "+")
- t = substring(t, 1, strlen(t) - 1);
- if(substring(t, -1, 1) == "*")
- {
- t = substring(t, 0, strlen(t) - 1);
- s = substring(s, 0, strlen(t));
- }
- else
- s = str;
- if(s == t)
- {
- r = d;
- }
- }
- return r;
-}
-
float _MapInfo_Cache_Active;
float _MapInfo_Cache_DB_NameToIndex;
float _MapInfo_Cache_Buf_IndexToMapData;
Modified: trunk/data/qcsrc/common/util.qc
===================================================================
--- trunk/data/qcsrc/common/util.qc 2009-12-13 19:29:35 UTC (rev 8391)
+++ trunk/data/qcsrc/common/util.qc 2009-12-14 15:56:13 UTC (rev 8392)
@@ -1733,3 +1733,59 @@
return sigma * sin(a) * b;
}
}
+
+string car(string s)
+{
+ float o;
+ o = strstrofs(s, " ", 0);
+ if(o < 0)
+ return s;
+ return substring(s, 0, o);
+}
+string cdr(string s)
+{
+ float o;
+ o = strstrofs(s, " ", 0);
+ if(o < 0)
+ return string_null;
+ return substring(s, o + 1, strlen(s) - (o + 1));
+}
+float matchacl(string acl, string str)
+{
+ string t, s;
+ float r, d;
+ r = 0;
+ while(acl)
+ {
+ t = car(acl); acl = cdr(acl);
+ d = 1;
+ if(substring(t, 0, 1) == "-")
+ {
+ d = -1;
+ t = substring(t, 1, strlen(t) - 1);
+ }
+ else if(substring(t, 0, 1) == "+")
+ t = substring(t, 1, strlen(t) - 1);
+ if(substring(t, -1, 1) == "*")
+ {
+ t = substring(t, 0, strlen(t) - 1);
+ s = substring(s, 0, strlen(t));
+ }
+ else
+ s = str;
+
+ if(s == t)
+ {
+ r = d;
+ }
+ }
+ return r;
+}
+float startsWith(string haystack, string needle)
+{
+ return substring(haystack, 0, strlen(needle)) == needle;
+}
+float startsWithNocase(string haystack, string needle)
+{
+ return strcasecmp(substring(haystack, 0, strlen(needle)), needle) == 0;
+}
Modified: trunk/data/qcsrc/common/util.qh
===================================================================
--- trunk/data/qcsrc/common/util.qh 2009-12-13 19:29:35 UTC (rev 8391)
+++ trunk/data/qcsrc/common/util.qh 2009-12-14 15:56:13 UTC (rev 8392)
@@ -202,3 +202,9 @@
float float2range01(float f);
float gsl_ran_gaussian(float sigma);
+
+string car(string s); // returns first word
+string cdr(string s); // returns all but first word
+float matchacl(string acl, string str); // matches str against ACL acl (with entries +foo*, +foo, +*foo, +*foo*, and same with - for forbidding)
+float startsWith(string haystack, string needle);
+float startsWithNocase(string haystack, string needle);
More information about the nexuiz-commits
mailing list