SRD Standelone programmation box: StringTools.h File Reference

| SRD Standelone programmation box 2.0 (16/11/15 10:00:00) Documentation of the SRD standelone programmation box

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Enumerations Enumerator Macros Pages
Functions
StringTools.h File Reference

Functions used to manipulate string. \ details All Right Reserved. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

void | StrTool_ClearString (char *str, unsigned short strLength)
| Clear a string (reset all char to '\0'). More...
unsigned short | StrTool_StringLength (char *str)
| Clear a string (reset all char to '\0'). More...
unsigned short | StrTool_StringCopy (char *stringDest, char *stringToCopy)
| copy a string. More...
unsigned short | StrTool_UnsignedLongToStringHex (unsigned long data, char *str)
| Convert an unsigned long in string coded as hexadecimal char. More...
unsigned short | StrTool_UnsignedLongToString (unsigned long data, char *str)
| Convert an unsigned long in string coded as decimal char. More...
unsigned short | StrTool_SignedLongToString (signed long data, char *str)
| Convert an signed long in string coded as decimal char. More...
unsigned long | StrTool_StringToUnsignedLong (char *str)
| Convert a string into a unsigned long. More...

## Detailed Description

Functions used to manipulate string. \ details All Right Reserved.

Author
  Thibaut LALUQUE 3D-Ouest

Date
  02/09/2014

Version
  1.0

Definition in file StringTools.h.

## Function Documentation

void StrTool_ClearString | ( | char * | str,
|  | unsigned short | strLength
| ) |  |

Clear a string (reset all char to '\0').

Parameters

  [in,out] | str | (char*) : pointer on the first char of the string to reset.
  [in] |  | strLength (unsigned short) : length of the string to reset.

Definition at line 66 of file StringTools.c.

Referenced by CR95HFWriteCommand(), and PowerManagerSendBatteryInfo().

66 {
67 while(strLength != 0) {
68 *str = '\0';
69 str++;
70 strLength--;
71 }
72 }

Here is the caller graph for this function:

unsigned short StrTool_SignedLongToString | ( | signed long | data,
|  | char * | str
| ) |  |

Convert an signed long in string coded as decimal char.

Parameters

  [in] | data | (signed long) : number to convert.
  [in,out] | str | (char*) : pointer on the string to put the conversion.

Returns
  (unsigned short) The number of char copied in the str string.

Definition at line 143 of file StringTools.c.

References StrTool_UnsignedLongToString().

Referenced by PowerManagerSendBatteryInfo().

143 {
144
145 if(data < 0) {
146 *str = '-';
147 data = -data;
148 StrTool_UnsignedLongToString(data, str++);
149 } else {
150 StrTool_UnsignedLongToString(data, str);
151 }
152 }
StrTool_UnsignedLongToString
unsigned short StrTool_UnsignedLongToString(unsigned long data, char *str)
Convert an unsigned long in string coded as decimal char.
Definition: StringTools.c:121

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned short StrTool_StringCopy | ( | char * | stringDest,
|  | char * | stringToCopy
| ) |  |

copy a string.

Parameters

  [out] | stringDest | (char*) : pointer on the paste string.
  [in] | stringToCopy | (char*) : pointer on the string to copy.

Returns
  (unsigned short) The length of the string copied.

Definition at line 84 of file StringTools.c.

84 {
85 unsigned short id = 0;
86
87 while(*(stringToCopy+id) != '\0') {
88 stringDest[id] = stringToCopy[id];
89 id++;
90 }
91 stringDest[id++] = '\0';
92 return id; //return the number of char copied
93 }

unsigned short StrTool_StringLength | ( | char * | str | ) |

Clear a string (reset all char to '\0').

Parameters

  [in] | str | (char*) : pointer on the string.

Returns
  (unsigned short) The length of the string.

Definition at line 74 of file StringTools.c.

74 {
75 unsigned short result = 0;
76
77 while(*(str+result) != '\0') {
78 result++;
79 }
80
81 return result;
82 }

unsigned long StrTool_StringToUnsignedLong | ( | char * | str | ) |

Convert a string into a unsigned long.

Parameters

  [in] | str | (char*) : pointer on the string containing the number to convert.

Returns
  (unsigned long) The string converted into a unsigned long.

Definition at line 155 of file StringTools.c.

155 {
156 unsigned long val = 0;
157 unsigned long facteur = 1;
158 unsigned short ptr = 0;
159
160 while( *(str+ptr) >= '0' && *(str+ptr) <= '9' ) {
161
162 val = val*facteur;
163
164 val += (*(str+ptr)) - '0';
165
166 facteur = 10;
167
168 ptr++;
169 }
170
171 return val;
172
173 }

unsigned short StrTool_UnsignedLongToString | ( | unsigned long | data,
|  | char * | str
| ) |  |

Convert an unsigned long in string coded as decimal char.

Parameters

  [in] | data | (unsigned long) : number to convert.
  [in,out] | str | (char*) : pointer on the string to put the conversion.

Returns
  (unsigned short) The number of char copied in the str string.

Definition at line 121 of file StringTools.c.

Referenced by StrTool_SignedLongToString().

121 {
122 char localStr[16] = {0};
123 unsigned char localPtr = 15;
124 unsigned char strPtr = 0;
125
126 do {
127 unsigned char digit = (unsigned char)(data % 10);
128 localStr[localPtr] = digit + '0';
129 data = data/10;
130 localPtr--;
131 } while(data != 0);
132
133 localPtr++;
134 while(localPtr < 16) {
135 *(str+strPtr) = localStr[localPtr];
136 localPtr++;
137 strPtr++;
138 }
139 *(str+strPtr) = '\0';
140 return strPtr;
141 }

Here is the caller graph for this function:

unsigned short StrTool_UnsignedLongToStringHex | ( | unsigned long | data,
|  | char * | str
| ) |  |

Convert an unsigned long in string coded as hexadecimal char.

Parameters

  [in] | data | (unsigned long) : number to convert.
  [in,out] | str | (char*) : pointer on the string to put the conversion.

Returns
  (unsigned short) The number of char copied in the str string.

Definition at line 95 of file StringTools.c.

95 {
96 char localStr[8] = {0};
97 unsigned char localPtr = 7;
98 unsigned char strPtr = 0;
99
100 do {
101 unsigned char digit = (unsigned char)(data & 0x0000000F);
102 if(digit < 10) {
103 localStr[localPtr] = digit + '0';
104 } else {
105 localStr[localPtr] = digit - 10 + 'A';
106 }
107 data = data>>4;
108 localPtr--;
109 } while(data != 0);
110
111 localPtr++;
112 while(localPtr < 8) {
113 *(str+strPtr) = localStr[localPtr];
114 localPtr++;
115 strPtr++;
116 }
117 *(str+strPtr) = '\0';
118 return strPtr;
119 }