--- deliantra/server/include/shstr.h 2007/04/23 16:07:00 1.14
+++ deliantra/server/include/shstr.h 2008/12/28 06:59:27 1.23
@@ -1,3 +1,24 @@
+/*
+ * This file is part of Deliantra, the Roguelike Realtime MMORPG.
+ *
+ * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
+ *
+ * Deliantra is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * The authors can be reached via e-mail to
+ */
+
#ifndef SHSTR_H__
#define SHSTR_H__
@@ -5,6 +26,8 @@
#include "util.h"
+extern size_t shstr_alloc;
+
extern int buf_overflow (const char *buf1, const char *buf2, int bufsize);
struct shstr
@@ -33,6 +56,14 @@
return length (s);
}
+ // returns wether this shared string begins with the given prefix,
+ // used mainly for searched when users give only the start of a name.
+ bool begins_with (const char *prefix) const
+ {
+ int plen = strlen (prefix);
+ return !strncasecmp (s, prefix, plen) && length () >= plen;
+ }
+
static const char *find (const char *s);
static const char *intern (const char *s);
@@ -87,17 +118,17 @@
return *this;
}
- bool operator ==(const shstr &b)
- {
- return s == b.s;
- }
-
bool operator !=(const shstr &b)
{
return !(*this == b);
}
};
+inline bool operator ==(const shstr &a, const shstr &b)
+{
+ return a.s == b.s;
+}
+
inline int strlen (const shstr &sh)
{
return sh.length ();
@@ -136,6 +167,14 @@
{
}
+ shstr_cmp (const shstr &sh)
+ : s (sh.s)
+ {
+ }
+
+ // this is used for informational messages and the like
+ const char *operator &() const { return s; }
+
shstr_cmp &operator =(const shstr_cmp sh) { s = sh.s; return *this; }
operator const char *() const { return s; }
};
@@ -150,7 +189,11 @@
return b == a;
}
-extern const shstr undead_name; /* Used in hit_player() in main.c */
+extern const shstr shstr_null;
+
+#define def(str) extern const shstr shstr_ ## str;
+# include "shstrinc.h"
+#undef def
#endif