aboutsummaryrefslogtreecommitdiff
path: root/src/inner_tools.c
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-02-06 11:27:59 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-02-06 11:27:59 +0300
commitfca83975899b01c62ede4258f175346b7039be3d (patch)
tree37c2bb8faf95de1252a97942a68183f795eb82a0 /src/inner_tools.c
parent8ef310a22a54dca7a80947f83f03bc296ab298dd (diff)
parent746c3f3076fe5994f08d729aa1b958465231b0c8 (diff)
downloadmagi-fca83975899b01c62ede4258f175346b7039be3d.tar
magi-fca83975899b01c62ede4258f175346b7039be3d.tar.xz
magi-fca83975899b01c62ede4258f175346b7039be3d.zip
Merge branch 'master' into test
Diffstat (limited to 'src/inner_tools.c')
-rw-r--r--src/inner_tools.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/inner_tools.c b/src/inner_tools.c
new file mode 100644
index 0000000..d958851
--- /dev/null
+++ b/src/inner_tools.c
@@ -0,0 +1,51 @@
+#include "inner_tools.h"
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+void magi_str_lowercase(char *str)
+{
+ if (!str) {
+ return;
+ }
+ for (; *str; ++str) {
+ *str = tolower(*str);
+ }
+}
+
+char *magi_str_create_copy(const char *first, int len)
+{
+ char *copy = magi_str_create(len);
+ if (copy) {
+ memcpy(copy, first, len);
+ }
+ return copy;
+}
+
+char *magi_str_create(int len)
+{
+ char *str = malloc(len + 1);
+ if (str) {
+ str[len] = 0;
+ }
+ return str;
+}
+
+int magi_str_add(char **dest, int *len, int *size, char c)
+{
+ if (!*dest) {
+ *dest = magi_str_create(1);
+ } else if (*len + 1 == *size) {
+ *size *= 2;
+ *dest = realloc(*dest, *size);
+ }
+ if (!*dest) {
+ return 0;
+ }
+ (*dest)[*len] = c;
+ ++*len;
+ (*dest)[*len] = 0;
+ return 1;
+}