E:/Ablage_Gerhard/10_Hobby/Elektronik/30_Atmel/20_Prog/AVR_CMD_INTERFACE/string_addon.h File Reference

some additional clever string functions More...

#include <stdio.h>

Go to the source code of this file.

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

Detailed Description

some additional clever string functions

Target/Compiler: AVR_MEGA / GCC(WinAVR)

Author:
Gerhard Bruenner
Version:
V0.11
Date:
2009.10.31 - Created - GB
Bug:
none that I am aware so far

\


Function Documentation

void l_trim ( char *  string,
char  sign 
)

eleminates all signs at the end of a string which are equal to the given one

Parameters:
*string - string to investigate
sign - character which shall be eliminated
Returns:
void

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

Parameters:
*string - string to investigate
sign - character which shall be eliminated
Returns:
void

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

Parameters:
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 -
Returns:
<0 - error
-1 - to many signs to copy
0 - split char has not been found in string
>0 - index of *string after the split char found by the routine

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

Parameters:
*string_source - string to copy
*string_dest - string to copy into
max_no_char - maximum number of characters to copy (limit of string_dest)
Returns:
-1 - string could not be copied completly
0 - string copied

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

Parameters:
*string - string to investigate
sign - character which shall be eliminated
Returns:
void

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,' ');


Generated on Wed Nov 11 21:04:06 2009 for AVR_CMD_INTERFACE by  doxygen 1.6.1