Removing string manipulation functions from manga.c.

We now use the gobject MgUtilString for that.
This commit is contained in:
sergiotarxz 2021-10-31 12:48:28 +01:00
parent 923282f1d1
commit dbf5a2ff32
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,17 @@
#pragma once
#include <glib-object.h>
G_BEGIN_DECLS;
#define MG_TYPE_UTIL_STRING mg_util_string_get_type()
G_DECLARE_FINAL_TYPE (MgUtilString, mg_util_string, MG, UTIL_STRING, GObject)
MgUtilString *mg_util_string_new ();
char *
mg_util_string_alloc_string(MgUtilString *self, size_t len);
void
mg_util_string_copy_substring(MgUtilString *self,
const char *origin, char *dest, size_t dest_len, size_t start,
size_t len);
G_END_DECLS

48
src/util/string.c Normal file
View File

@ -0,0 +1,48 @@
#include <stdio.h>
#include <glib-object.h>
#include <openmg/util/string.h>
struct _MgUtilString {
GObject parent_instance;
};
G_DEFINE_TYPE (MgUtilString, mg_util_string, G_TYPE_OBJECT)
static void
mg_util_string_class_init (MgUtilStringClass *class) {
}
static void
mg_util_string_init (MgUtilString *class) {
}
void
mg_util_string_copy_substring(MgUtilString *self,
const char *origin, char *dest, size_t dest_len, size_t start,
size_t len) {
size_t copying_offset = 0;
while (copying_offset < len) {
if (!(start+copying_offset <=dest_len)) {
fprintf(stderr, "Read attempt out of bounds.%ld %ld %ld\n", dest_len, start, len);
break;
}
dest[copying_offset] = origin[start+copying_offset];
copying_offset++;
}
dest[len] = '\0';
}
char *
mg_util_string_alloc_string(MgUtilString *self, size_t len) {
char * return_value = NULL;
return g_malloc (len + 1 * sizeof *return_value);
}
MgUtilString *
mg_util_string_new () {
MgUtilString *self = NULL;
self = MG_UTIL_STRING ((g_object_new (MG_TYPE_UTIL_STRING, NULL)));
return self;
}