some additional clever string functions More...
#include "string_addon.h"
Functions | |
void | r_trim (char *string, char sign) |
eleminates all leading signs which are equal to the given one | |
void | l_trim (char *string, char sign) |
eleminates all signs at the end of a string which are equal to the given one | |
void | trim (char *string, char sign) |
eleminates all signs of the given type at the end or at the beginning of a string | |
int8_t | split_string (char *string, char *splitted_string, char split_sign, uint8_t max_char2copy) |
functions which splits a string into two parts at the position of a certain character | |
int8_t | string_copy (char *string_source, char *string_dest, uint8_t ui_max_char) |
copy string A into string B and checks whether given borders |
some additional clever string functions
Target/Compiler: AVR_MEGA / GCC(WinAVR)
\
void l_trim | ( | char * | string, | |
char | sign | |||
) |
eleminates all signs at the end of a string which are equal to the given one
*string | - string to investigate | |
sign | - character which shall be eliminated |
This function eliminates all characters at the end of a string. The character which shall be eliminated and the string to be checked have to be addressed in the call.
void r_trim | ( | char * | string, | |
char | sign | |||
) |
eleminates all leading signs which are equal to the given one
*string | - string to investigate | |
sign | - character which shall be eliminated |
This function eliminates all leading characters in a string. The character which shall be eliminated and the string to be checked have to be addressed in the call.
int8_t split_string | ( | char * | string, | |
char * | splitted_string, | |||
char | split_sign, | |||
uint8_t | max_char2copy | |||
) |
functions which splits a string into two parts at the position of a certain character
char | *string - pointer onto string which shall be split | |
char | *splitted_string - part which have been splited from content of *string | |
char | split_sign - character to be used as split sign | |
uint8_t | max_char2Copy - |
This functions searches for a character given by the user via the parameter split_sign at the beginning of the given string-pointer. In the case the split_sign could not be found, the function returns -1. In the case the split_signs has been found, it copys the content of string into the string splitted_string till the point where the split_sign has been found. The return-value contains the index of the sign AFTER the split_sign. It is upto the user to delete the splitted content in string or to restart the function at the position in the return-value --------- example: sprintf( str_rcv_usart,"Gerhard ,12345,macht was ,er will"); iCnt = split_string(&str_rcv_usart[0],&spliter_string[0],',',20); iCnt += split_string(&str_rcv_usart[iCnt], &spliter_string[0],',',20); iCnt = split_string(&str_rcv_usart[iCnt], &spliter_string[0],',',5);
int8_t string_copy | ( | char * | string_source, | |
char * | string_dest, | |||
uint8_t | ui_max_char | |||
) |
copy string A into string B and checks whether given borders
*string_source | - string to copy | |
*string_dest | - string to copy into | |
max_no_char | - maximum number of characters to copy (limit of string_dest) |
This function copys the content of the string "source" into the string "dest". Doing this it checkes whether the amount of copied characters is less than the given amount in --- Testcode char str_rcv[10]=""; sprintf(str_rcv_usart,"Test"); iCnt=string_copy(&str_rcv_usart[0], &str_rcv[0], 10); sprintf(str_rcv_usart," 23456789"); iCnt=string_copy(&str_rcv_usart[0], &str_rcv[0], 10); sprintf(str_rcv_usart,"123456789AB"); iCnt=string_copy(&str_rcv_usart[0], &str_rcv[0], 10);
void trim | ( | char * | string, | |
char | sign | |||
) |
eleminates all signs of the given type at the end or at the beginning of a string
*string | - string to investigate | |
sign | - character which shall be eliminated |
This function eliminates all characters at the end and at the beginning of a string. The character which shall be eliminated and the string to be checked have to be addressed in the call. ------- Testcode sprintf(str_rcv_usart,"Gerhard "); trim(str_rcv_usart,' '); sprintf(str_rcv_usart," Gerhard "); trim(str_rcv_usart,' '); sprintf(str_rcv_usart,"Gerhard"); trim(str_rcv_usart,' ');