Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Jauslin <ian.jauslin@roma1.infn.it>2015-06-14 00:52:45 +0000
committerIan Jauslin <ian.jauslin@roma1.infn.it>2015-06-14 00:52:45 +0000
commitaa0f3ae2988d372b190b9bde2e75a6d17e744e93 (patch)
tree14482245c2fca27fcdad3078e97d0871352d52a7 /src/istring.c
Initial commitv1.2
Diffstat (limited to 'src/istring.c')
-rw-r--r--src/istring.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/istring.c b/src/istring.c
new file mode 100644
index 0000000..663c06a
--- /dev/null
+++ b/src/istring.c
@@ -0,0 +1,99 @@
+/*
+Copyright 2015 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include <stdlib.h>
+#include "istring.h"
+
+char* str_concat(char* ptr, const char* str){
+ char* str_ptr=(char*)str;
+
+ while(*str_ptr!='\0'){
+ *ptr=*str_ptr;
+ ptr++;
+ str_ptr++;
+ }
+ *ptr='\0';
+ return(ptr);
+}
+
+int str_concat_memorysafe(char** str_out, int pos, const char* str, int* memory){
+ char* out_ptr;
+
+ if(str_len((char*)str)+pos>=*memory){
+ *memory=*memory+str_len((char*)str)+pos+1;
+ resize_str(str_out,*memory);
+ }
+ out_ptr=*str_out+pos;
+ str_concat(out_ptr,str);
+ return(0);
+}
+
+int resize_str(char** out, int memory){
+ char* tmp_str=calloc(memory,sizeof(char));
+ char* tmp_ptr=tmp_str;
+ char* out_ptr=*out;
+
+ for(;*out_ptr!='\0';out_ptr++,tmp_ptr++){
+ *tmp_ptr=*out_ptr;
+ }
+ *tmp_ptr='\0';
+
+ free(*out);
+ *out=tmp_str;
+ return(0);
+}
+
+char* str_addchar(char* ptr, const char c){
+ *ptr=c;
+ ptr++;
+ *ptr='\0';
+ return(ptr);
+}
+
+int str_len(char* str){
+ char* ptr=str;
+ int ret=0;
+ while(*ptr!='\0'){ret++;ptr++;}
+ return(ret);
+}
+
+int str_cmp(char* str1, char* str2){
+ char* ptr1=str1;
+ char* ptr2=str2;
+ while(*ptr1==*ptr2 && *ptr1!='\0' && *ptr2!='\0'){
+ ptr1++;
+ ptr2++;
+ }
+ if(*ptr1=='\0' && *ptr2=='\0'){
+ return(1);
+ }
+ else{
+ return(0);
+ }
+}
+
+
+int str_cpy_noalloc(char* input, char* output){
+ char* ptr;
+ char* out_ptr;
+
+ for(ptr=input,out_ptr=output;*ptr!='\0';ptr++,out_ptr++){
+ *out_ptr=*ptr;
+ }
+ *out_ptr='\0';
+ return(0);
+}
+