summaryrefslogtreecommitdiff
path: root/src/ecommon
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-11 00:42:56 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-11 02:09:45 +0300
commit82fca47fc7b00d8755c4333e0016bf555e46d0f8 (patch)
tree7afa440b66113e9fc24408f344e5340a90d83e8b /src/ecommon
parent64e7b33c9163e387c94f1a11de4e15435c35005c (diff)
downloadplugin-82fca47fc7b00d8755c4333e0016bf555e46d0f8.tar.gz
plugin-82fca47fc7b00d8755c4333e0016bf555e46d0f8.tar.bz2
plugin-82fca47fc7b00d8755c4333e0016bf555e46d0f8.tar.xz
plugin-82fca47fc7b00d8755c4333e0016bf555e46d0f8.zip
Add script command for convert craft string into craft object.
New script command: initcraft var$ Return value: craft object id.
Diffstat (limited to 'src/ecommon')
-rw-r--r--src/ecommon/struct/strutildata.h16
-rw-r--r--src/ecommon/utils/strutil.c53
-rw-r--r--src/ecommon/utils/strutil.h12
3 files changed, 81 insertions, 0 deletions
diff --git a/src/ecommon/struct/strutildata.h b/src/ecommon/struct/strutildata.h
new file mode 100644
index 0000000..fa9c11d
--- /dev/null
+++ b/src/ecommon/struct/strutildata.h
@@ -0,0 +1,16 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 - 2015 Evol developers
+
+#ifndef EVOL_MAP_STRUTILDATA
+#define EVOL_MAP_STRUTILDATA
+
+#include "common/db.h"
+
+struct strutil_data
+{
+ char *str;
+ VECTOR_DECL(char*) parts;
+ int len;
+};
+
+#endif // EVOL_MAP_STRUTILDATA
diff --git a/src/ecommon/utils/strutil.c b/src/ecommon/utils/strutil.c
new file mode 100644
index 0000000..d782b0a
--- /dev/null
+++ b/src/ecommon/utils/strutil.c
@@ -0,0 +1,53 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 - 2015 Evol developers
+
+#include "common/hercules.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "common/memmgr.h"
+#include "common/strlib.h"
+
+#include "ecommon/utils/strutil.h"
+
+#include "ecommon/struct/strutildata.h"
+
+struct strutil_data *strutil_split(const char *str,
+ const char separator,
+ const int len)
+{
+ if (!str || len < 1)
+ return NULL;
+ struct strutil_data *data = aCalloc(1, sizeof(struct strutil_data));
+ if (!data)
+ return NULL;
+ data->str = aStrdup(str);
+ VECTOR_INIT(data->parts);
+ VECTOR_ENSURE(data->parts, len + 1, 1);
+
+ data->len = sv->split(data->str,
+ strlen(data->str),
+ 0,
+ separator,
+ VECTOR_DATA(data->parts),
+ len + 1,
+ 0);
+ if (data->len < 1)
+ {
+ strutil_free(data);
+ return NULL;
+ }
+
+ return data;
+}
+
+void strutil_free(struct strutil_data *data)
+{
+ if (!data)
+ return NULL;
+ VECTOR_CLEAR(data->parts);
+ aFree(data->str);
+ aFree(data);
+}
diff --git a/src/ecommon/utils/strutil.h b/src/ecommon/utils/strutil.h
new file mode 100644
index 0000000..75d9f20
--- /dev/null
+++ b/src/ecommon/utils/strutil.h
@@ -0,0 +1,12 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 - 2015 Evol developers
+
+#ifndef EVOL_COMMON_UTILS_STRUTIL
+#define EVOL_COMMON_UTILS_STRUTIL
+
+struct strutil_data *strutil_split(const char *str,
+ const char separator,
+ const int len);
+void strutil_free(struct strutil_data *data);
+
+#endif // EVOL_COMMON_UTILS_STRUTIL