aboutsummarylogtreecommitdiffstats
path: root/string-tick.c
diff options
context:
space:
mode:
authorAntony Kellermann2018-02-26 10:19:10 -0500
committerAntony Kellermann2018-02-26 10:19:10 -0500
commitef7e041ff8170be8ed837fe8ba4378eed687463a (patch)
treebf502b9bfa9a5f2f2b00c4db7efde826cecc567c /string-tick.c
parent3e36a4fefbdfa9c3d14c4ebf0149a59df5461b2f (diff)
downloadaur-ef7e041ff8170be8ed837fe8ba4378eed687463a.tar.gz
Moved string manipulation functions to new c/h files, added them to Makefile, included header in other files
Diffstat (limited to 'string-tick.c')
-rw-r--r--string-tick.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/string-tick.c b/string-tick.c
new file mode 100644
index 000000000000..c5323f76afce
--- /dev/null
+++ b/string-tick.c
@@ -0,0 +1,47 @@
+#include "string-tick.h"
+
+String* api_string_init(void) {
+ String* pString = (String*) malloc(sizeof(String));
+ if (pString != NULL) {
+ pString->len = 0;
+ pString->data = (char*) malloc(sizeof(char));
+ if (pString->data == NULL) {
+ fprintf(stderr, "malloc() failed\n");
+ exit(EXIT_FAILURE);
+ }
+ pString->data[0] = '\0';
+ } else {
+ fprintf(stderr, "malloc() failed\n");
+ exit(EXIT_FAILURE);
+ }
+ return pString;
+}
+
+void strtolower(char* str) {
+ for (int i = 0; str[i] != '\0'; i++)
+ str[i] = (char) tolower(str[i]);
+}
+
+void strtoupper(char* str) {
+ for (int i = 0; str[i] != '\0'; i++)
+ str[i] = (char) toupper(str[i]);
+}
+
+char* strip_char(char* string, char c) {
+ size_t len = strlen(string);
+ int i, j;
+ for (i = 0, j = 0; j < (int) len; i++, j++) {
+ while (string[j] == c)
+ j++;
+ string[i] = string[j];
+ }
+ string[i] = '\0';
+ return string;
+}
+
+void api_string_destroy(String** phString) {
+ String* pString = *phString;
+ free(pString->data);
+ free(*phString);
+ *phString = NULL;
+} \ No newline at end of file