Last active
January 31, 2020 23:41
-
-
Save Sarverott/42d5a292a03b0c42ee61a5b168a1660b to your computer and use it in GitHub Desktop.
group of functions to make easier work with char* based strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef CHAR_STRING | |
#define CHAR_STRING | |
/* Sarverott 2020 */ | |
class charString{ | |
public: | |
static char* leftTrim(char* input, char trimmer=' '){ | |
int index=0; | |
int cutFlag=0; | |
bool cutting=false; | |
char* output=new char(); | |
while(input[cutFlag]!='\0'){ | |
if(cutting){ | |
output[index]=input[cutFlag]; | |
index++; | |
}else{ | |
if(input[cutFlag]!=trimmer){ | |
cutting=true; | |
continue; | |
} | |
} | |
cutFlag++; | |
} | |
output[index]='\0'; | |
return output; | |
} | |
static char* rightTrim(char* input, char trimmer=' '){ | |
int index=0; | |
int cutFlag=0; | |
char* output=new char(); | |
while(input[index]!='\0'){ | |
if(input[index]!=trimmer)cutFlag=index; | |
index++; | |
} | |
for(int i=0;i<=cutFlag;i++) output[i]=input[i]; | |
output[cutFlag+1]='\0'; | |
return output; | |
} | |
static char* trim(char *input, char trimmer=' '){ | |
return charString::rightTrim(charString::leftTrim(input, trimmer), trimmer); | |
} | |
static char* copyCharString(char* input){ | |
char* output=new char(); | |
int index=0; | |
while(input[index]!='\0') output[index++]=input[index]; | |
output[index]='\0'; | |
return output; | |
} | |
static char* concatCharStrings(char* firstInput, char* secondInput){ | |
char* output=new char(); | |
int mainIndex=0; | |
int firstIndex=0; | |
int secondIndex=0; | |
while(firstInput[firstIndex]!='\0') output[mainIndex++]=firstInput[firstIndex++]; | |
while(secondInput[secondIndex]!='\0') output[mainIndex++]=secondInput[secondIndex++]; | |
output[mainIndex]='\0'; | |
return output; | |
} | |
static int calculateString(char* input){ | |
int output=0; | |
while(input[output]!='\0')output++; | |
return output; | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment