summaryrefslogtreecommitdiff
path: root/src/str.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/str.c')
-rw-r--r--src/str.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/str.c b/src/str.c
new file mode 100644
index 0000000..46dc4a8
--- /dev/null
+++ b/src/str.c
@@ -0,0 +1,86 @@
+#include "str.h"
+#include "str_partial.h"
+#include <string.h>
+
+H_ATTR
+str_info
+_info_getter(str *s, UNUM n)
+{
+ return (str_info) { (NUM) *(s->data+n), 1 };
+}
+
+/* H_ATTR
+ * NUM
+ * _lenner(str *s)
+ * {
+ * return s->size;
+ * } */
+
+str *
+new_str(char *s, NUM size)
+{
+ str *str_pointer = MYALLOC(str, 1);
+
+ str_pointer->size = size;
+ str_pointer->data = s;
+ str_pointer->getter = _info_getter;
+ /* str_pointer->lenner = _lenner; */
+
+ return str_pointer;
+}
+
+void
+destroy_str(str *s, int flag)
+{
+ if (flag) free(s->data);
+
+ s->size = 0;
+
+ free(s);
+}
+
+H_ATTR
+str_info
+get_info(str *s, UNUM n)
+{
+ return s->getter(s, n);
+}
+
+H_ATTR
+NUM
+str_length(str *s)
+{
+ return s->size;
+}
+
+void
+change_str_content(str *s, char *str, NUM size)
+{
+ s->data = str;
+ s->size = size;
+}
+
+unsigned char
+copy_str(str *dest, str *source)
+{
+ if (str_length(dest) < str_length(source))
+ return 1;
+
+ dest->size = source->size;
+
+ memcpy(dest->data, source->data, source->size);
+
+ return 0;
+}
+
+char *
+get_data(str *s)
+{
+ return s->data;
+}
+
+void
+str_set_length(str *s, UNUM size)
+{
+ s->size = size;
+}