forked from sergiotarxz/mangareader
Removing string manipulation functions from manga.c.
We now use the gobject MgUtilString for that.
This commit is contained in:
parent
923282f1d1
commit
dbf5a2ff32
17
include/openmg/util/string.h
Normal file
17
include/openmg/util/string.h
Normal 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
48
src/util/string.c
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user