Add original string functions.
authorKoichi KAMICHI <kamichi@fonts.jp>
Tue, 20 Apr 2004 05:27:30 +0000 (05:27 +0000)
committerKoichi KAMICHI <kamichi@fonts.jp>
Tue, 20 Apr 2004 05:27:30 +0000 (05:27 +0000)
kagecgi/kagestr.c [new file with mode: 0755]
kagecgi/kagestr.h [new file with mode: 0755]

diff --git a/kagecgi/kagestr.c b/kagecgi/kagestr.c
new file mode 100755 (executable)
index 0000000..4d96b1e
--- /dev/null
@@ -0,0 +1,68 @@
+//kagestr.c
+//
+
+#include "sysdep.h"
+#include "kagestr.h"
+
+KGString* kg_string_new(char *initString){
+  KGString *tmp;
+  tmp = (KGString *)malloc(sizeof(KGString));
+  if(initString == NULL){
+    tmp->len = 0;
+    tmp->str = (char *)malloc(0);
+  }
+  else{
+    tmp->len = strlen(initString);
+    tmp->str = (char *)malloc(tmp->len + 1);
+    strcpy(tmp->str, initString);
+  }
+  return tmp;
+}
+
+KGString* kg_string_set_size(KGString *target, int newSize){
+  target->len = newSize;
+  target->str = (char *)realloc((char *)target->str, target->len + 1);
+  target->str[target->len] = '\0';
+  return target;
+}
+
+KGString* kg_string_append_len(KGString *target, char *appendString, int length){
+  target->len = target->len + length;
+  target->str = (char *)realloc((char *)target->str, target->len + 1);
+  strncat(target->str, appendString, length);
+  return target;
+}
+
+KGString* kg_string_append(KGString *target, char *appendString){
+  target->len = target->len + strlen(appendString);
+  target->str = (char *)realloc((char *)target->str, target->len + 1);
+  strcat(target->str, appendString);
+  return target;
+}
+
+KGString* kg_string_erase(KGString *target, int startPoint, int length){
+  char *tmp;
+  int oldLength;
+  oldLength = target->len;
+  target->len = target->len - length;
+  tmp = (char *)malloc(target->len + 1);
+  strncpy(tmp, target->str, startPoint);
+  tmp[startPoint] = '\0';
+  if(oldLength > startPoint + length) strcat(tmp, target->str + startPoint + length);
+  target->str = (char *)realloc((char *)target->str, target->len + 1);
+  strcpy(target->str, tmp);
+  free(tmp);
+  return target;
+}
+
+KGString* kg_string_assign(KGString *target, char *assignString){
+  target->len = strlen(assignString);
+  target->str = (char *)realloc((char *)target->str, target->len + 1);
+  strcpy(target->str, assignString);
+  return target;
+}
+
+  
+
+
+
diff --git a/kagecgi/kagestr.h b/kagecgi/kagestr.h
new file mode 100755 (executable)
index 0000000..5547b60
--- /dev/null
@@ -0,0 +1,22 @@
+//kagestr.h
+//
+
+#ifndef _KAGESTR_H_
+#define _KAGESTR_H_
+
+typedef char kgchar;
+
+typedef struct _KGString {
+  char *str;
+  int len;
+} KGString;
+
+KGString* kg_string_new(char*);
+KGString* kg_string_set_size(KGString*, int);
+KGString* kg_string_append_len(KGString*, char*, int);
+KGString* kg_string_append(KGString*, char*);
+KGString* kg_string_erase(KGString*, int, int);
+KGString* kg_string_assign(KGString*, char*);
+
+#endif
+