cleaned version of TFT + Ethernet
Dependents: XPL-App4_cleanup XPL-App5
nihh_utils.cpp@0:9688737bf8cd, 2018-10-09 (annotated)
- Committer:
- richnash
- Date:
- Tue Oct 09 17:37:23 2018 +0000
- Revision:
- 0:9688737bf8cd
- Child:
- 1:e4a6f3f88b56
move to cli to explore D11 fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
richnash | 0:9688737bf8cd | 1 | |
richnash | 0:9688737bf8cd | 2 | // ----------------------------------------------------------- |
richnash | 0:9688737bf8cd | 3 | // MBED Headers |
richnash | 0:9688737bf8cd | 4 | //#include "mbed.h" |
richnash | 0:9688737bf8cd | 5 | //#include "string.h" |
richnash | 0:9688737bf8cd | 6 | //#include "stdlib.h" |
richnash | 0:9688737bf8cd | 7 | |
richnash | 0:9688737bf8cd | 8 | // ----------------------------------------------------------- |
richnash | 0:9688737bf8cd | 9 | // My Headers |
richnash | 0:9688737bf8cd | 10 | #include "nihh_utils.h" |
richnash | 0:9688737bf8cd | 11 | |
richnash | 0:9688737bf8cd | 12 | #define WHITESPACE_STR " \f\n\r\t\v" |
richnash | 0:9688737bf8cd | 13 | |
richnash | 0:9688737bf8cd | 14 | //****************************************************************************** |
richnash | 0:9688737bf8cd | 15 | // Remove whitespace characters from both ends of a copy of |
richnash | 0:9688737bf8cd | 16 | // '\0' terminated STRING and return the result. |
richnash | 0:9688737bf8cd | 17 | //****************************************************************************** |
richnash | 0:9688737bf8cd | 18 | char * UTILS_TrimString( char *pszString, char * pszResult ) |
richnash | 0:9688737bf8cd | 19 | { |
richnash | 0:9688737bf8cd | 20 | |
richnash | 0:9688737bf8cd | 21 | // Dont process a NULL pointer or a blank string |
richnash | 0:9688737bf8cd | 22 | if ((pszString!=NULL) && (*pszString!='\0')) |
richnash | 0:9688737bf8cd | 23 | { |
richnash | 0:9688737bf8cd | 24 | // setup the temp string |
richnash | 0:9688737bf8cd | 25 | char *ptr = pszString; |
richnash | 0:9688737bf8cd | 26 | |
richnash | 0:9688737bf8cd | 27 | // Skip leading spaces |
richnash | 0:9688737bf8cd | 28 | while ( *ptr == ' ' ) |
richnash | 0:9688737bf8cd | 29 | ++ptr; |
richnash | 0:9688737bf8cd | 30 | |
richnash | 0:9688737bf8cd | 31 | // copy the remainder of the string into the result string |
richnash | 0:9688737bf8cd | 32 | strcpy( pszResult, ptr ); |
richnash | 0:9688737bf8cd | 33 | |
richnash | 0:9688737bf8cd | 34 | // make sure there is something left ! |
richnash | 0:9688737bf8cd | 35 | if( *pszResult == '\0' ) |
richnash | 0:9688737bf8cd | 36 | { |
richnash | 0:9688737bf8cd | 37 | // bail because theres nothing left ! |
richnash | 0:9688737bf8cd | 38 | return pszResult; |
richnash | 0:9688737bf8cd | 39 | } |
richnash | 0:9688737bf8cd | 40 | else |
richnash | 0:9688737bf8cd | 41 | { |
richnash | 0:9688737bf8cd | 42 | // Move to the last character in the string |
richnash | 0:9688737bf8cd | 43 | for (ptr = pszResult; *ptr; ++ptr); |
richnash | 0:9688737bf8cd | 44 | |
richnash | 0:9688737bf8cd | 45 | // Loop through from the end of the string |
richnash | 0:9688737bf8cd | 46 | // while the char is one of WHITESPACE_STR |
richnash | 0:9688737bf8cd | 47 | for (--ptr; strchr (WHITESPACE_STR, *ptr); --ptr) |
richnash | 0:9688737bf8cd | 48 | { |
richnash | 0:9688737bf8cd | 49 | // this char is a WHITESPACE_STR so |
richnash | 0:9688737bf8cd | 50 | // overwrite it with the end of string char |
richnash | 0:9688737bf8cd | 51 | *ptr = '\0'; |
richnash | 0:9688737bf8cd | 52 | } |
richnash | 0:9688737bf8cd | 53 | } |
richnash | 0:9688737bf8cd | 54 | } |
richnash | 0:9688737bf8cd | 55 | else |
richnash | 0:9688737bf8cd | 56 | { |
richnash | 0:9688737bf8cd | 57 | // it was a null pointer or a blank string so set the result to blank |
richnash | 0:9688737bf8cd | 58 | strcpy( pszResult, "" ); |
richnash | 0:9688737bf8cd | 59 | } |
richnash | 0:9688737bf8cd | 60 | |
richnash | 0:9688737bf8cd | 61 | return pszResult; |
richnash | 0:9688737bf8cd | 62 | } |
richnash | 0:9688737bf8cd | 63 | |
richnash | 0:9688737bf8cd | 64 | //******************************************************************************* |
richnash | 0:9688737bf8cd | 65 | // |
richnash | 0:9688737bf8cd | 66 | //******************************************************************************* |
richnash | 0:9688737bf8cd | 67 | int UTILS_ParseString ( char* pszString, // String to parse |
richnash | 0:9688737bf8cd | 68 | char* apszParms[], // array to put parsed params into |
richnash | 0:9688737bf8cd | 69 | int iMaxParams, // max number of params |
richnash | 0:9688737bf8cd | 70 | int iSeperator, // |
richnash | 0:9688737bf8cd | 71 | int iStrip // trim params ? 1=yes |
richnash | 0:9688737bf8cd | 72 | ) |
richnash | 0:9688737bf8cd | 73 | { |
richnash | 0:9688737bf8cd | 74 | char* pszStr ; // |
richnash | 0:9688737bf8cd | 75 | char* pszTok ; // |
richnash | 0:9688737bf8cd | 76 | int i ; // |
richnash | 0:9688737bf8cd | 77 | |
richnash | 0:9688737bf8cd | 78 | // defaults |
richnash | 0:9688737bf8cd | 79 | i = 0 ; |
richnash | 0:9688737bf8cd | 80 | pszStr = pszString ; |
richnash | 0:9688737bf8cd | 81 | |
richnash | 0:9688737bf8cd | 82 | // loop through the string |
richnash | 0:9688737bf8cd | 83 | while( (pszStr != NULL) && (i < iMaxParams) ) |
richnash | 0:9688737bf8cd | 84 | { |
richnash | 0:9688737bf8cd | 85 | // store the start of the param |
richnash | 0:9688737bf8cd | 86 | pszTok = pszStr; |
richnash | 0:9688737bf8cd | 87 | |
richnash | 0:9688737bf8cd | 88 | // look for a seperator |
richnash | 0:9688737bf8cd | 89 | pszStr = strchr( pszStr, iSeperator ); |
richnash | 0:9688737bf8cd | 90 | |
richnash | 0:9688737bf8cd | 91 | // are we at the end of the string !? |
richnash | 0:9688737bf8cd | 92 | if( pszStr != NULL ) |
richnash | 0:9688737bf8cd | 93 | { |
richnash | 0:9688737bf8cd | 94 | // overwrite the : with a string terminator |
richnash | 0:9688737bf8cd | 95 | *pszStr = '\0'; |
richnash | 0:9688737bf8cd | 96 | |
richnash | 0:9688737bf8cd | 97 | // move on a char |
richnash | 0:9688737bf8cd | 98 | pszStr++; |
richnash | 0:9688737bf8cd | 99 | } |
richnash | 0:9688737bf8cd | 100 | |
richnash | 0:9688737bf8cd | 101 | // store the pointer |
richnash | 0:9688737bf8cd | 102 | apszParms[i] = pszTok; |
richnash | 0:9688737bf8cd | 103 | |
richnash | 0:9688737bf8cd | 104 | // have we been asked to trim the params ? |
richnash | 0:9688737bf8cd | 105 | if( iStrip == 1 ) |
richnash | 0:9688737bf8cd | 106 | { |
richnash | 0:9688737bf8cd | 107 | // just do a trim on it.. |
richnash | 0:9688737bf8cd | 108 | UTILS_TrimString( pszTok, pszTok ); |
richnash | 0:9688737bf8cd | 109 | } |
richnash | 0:9688737bf8cd | 110 | |
richnash | 0:9688737bf8cd | 111 | // move on |
richnash | 0:9688737bf8cd | 112 | i++; |
richnash | 0:9688737bf8cd | 113 | } |
richnash | 0:9688737bf8cd | 114 | |
richnash | 0:9688737bf8cd | 115 | // return the number of params we found ! |
richnash | 0:9688737bf8cd | 116 | return i; |
richnash | 0:9688737bf8cd | 117 | } |
richnash | 0:9688737bf8cd | 118 | |
richnash | 0:9688737bf8cd | 119 | |
richnash | 0:9688737bf8cd | 120 | //******************************************************************************* |
richnash | 0:9688737bf8cd | 121 | // Returns : |
richnash | 0:9688737bf8cd | 122 | // -1 check passed |
richnash | 0:9688737bf8cd | 123 | // -2 incorrect number of params |
richnash | 0:9688737bf8cd | 124 | // -3 incorrect start position |
richnash | 0:9688737bf8cd | 125 | // +? failed validation of parameter ? |
richnash | 0:9688737bf8cd | 126 | //******************************************************************************* |
richnash | 0:9688737bf8cd | 127 | int UTILS_CheckParams( char * pszMask, int iTokens, char * pszTokens[], int iStartParam ) // , int iBlanks ) |
richnash | 0:9688737bf8cd | 128 | { |
richnash | 0:9688737bf8cd | 129 | int iFormatChars = strlen(pszMask); |
richnash | 0:9688737bf8cd | 130 | int i; |
richnash | 0:9688737bf8cd | 131 | int iMaskPos; |
richnash | 0:9688737bf8cd | 132 | |
richnash | 0:9688737bf8cd | 133 | // are there the correct number of params ? |
richnash | 0:9688737bf8cd | 134 | if( iFormatChars != (iTokens-iStartParam) ) |
richnash | 0:9688737bf8cd | 135 | { |
richnash | 0:9688737bf8cd | 136 | //LOG_AppendToLog( LOG_I, "(UTILS_CheckParams) failed (rc=-2)\n" ); |
richnash | 0:9688737bf8cd | 137 | return -2; |
richnash | 0:9688737bf8cd | 138 | } |
richnash | 0:9688737bf8cd | 139 | |
richnash | 0:9688737bf8cd | 140 | // make sure we are not trying to start checking further into the array than we have params for !! |
richnash | 0:9688737bf8cd | 141 | if( iStartParam > iTokens ) |
richnash | 0:9688737bf8cd | 142 | { |
richnash | 0:9688737bf8cd | 143 | //LOG_AppendToLog( LOG_I, "(UTILS_CheckParams) failed (rc=-3)\n" ); |
richnash | 0:9688737bf8cd | 144 | return -3; |
richnash | 0:9688737bf8cd | 145 | } |
richnash | 0:9688737bf8cd | 146 | |
richnash | 0:9688737bf8cd | 147 | iMaskPos = 0; |
richnash | 0:9688737bf8cd | 148 | |
richnash | 0:9688737bf8cd | 149 | // Now check each param to make sure its the correct format |
richnash | 0:9688737bf8cd | 150 | for( i=iStartParam; i<=(iFormatChars); ++i ) |
richnash | 0:9688737bf8cd | 151 | { |
richnash | 0:9688737bf8cd | 152 | // if it is a lower case mask then it can NOT be blank ! |
richnash | 0:9688737bf8cd | 153 | if( (int)*(pszMask+iMaskPos) > 'Z' ) |
richnash | 0:9688737bf8cd | 154 | { |
richnash | 0:9688737bf8cd | 155 | // Blanks are not allowed ! |
richnash | 0:9688737bf8cd | 156 | if( strlen(pszTokens[i]) == 0 ) |
richnash | 0:9688737bf8cd | 157 | return i; |
richnash | 0:9688737bf8cd | 158 | } |
richnash | 0:9688737bf8cd | 159 | |
richnash | 0:9688737bf8cd | 160 | // check the data type |
richnash | 0:9688737bf8cd | 161 | switch( (int)*(pszMask+iMaskPos) ) |
richnash | 0:9688737bf8cd | 162 | { |
richnash | 0:9688737bf8cd | 163 | // Integer |
richnash | 0:9688737bf8cd | 164 | case 'i': |
richnash | 0:9688737bf8cd | 165 | case 'I': |
richnash | 0:9688737bf8cd | 166 | { |
richnash | 0:9688737bf8cd | 167 | char * psz ; // |
richnash | 0:9688737bf8cd | 168 | //long l ; // |
richnash | 0:9688737bf8cd | 169 | |
richnash | 0:9688737bf8cd | 170 | // defaults |
richnash | 0:9688737bf8cd | 171 | psz = NULL; |
richnash | 0:9688737bf8cd | 172 | //l = strtol( pszTokens[i], &psz, 10 ); |
richnash | 0:9688737bf8cd | 173 | strtol( pszTokens[i], &psz, 10 ); |
richnash | 0:9688737bf8cd | 174 | |
richnash | 0:9688737bf8cd | 175 | // if the pointer aint at the end of the string then we've got duff chars |
richnash | 0:9688737bf8cd | 176 | if( pszTokens[i] + strlen(pszTokens[i]) != psz ) |
richnash | 0:9688737bf8cd | 177 | { |
richnash | 0:9688737bf8cd | 178 | // failed.. its a non numeric param |
richnash | 0:9688737bf8cd | 179 | return i; |
richnash | 0:9688737bf8cd | 180 | } |
richnash | 0:9688737bf8cd | 181 | break; |
richnash | 0:9688737bf8cd | 182 | } |
richnash | 0:9688737bf8cd | 183 | |
richnash | 0:9688737bf8cd | 184 | // Address |
richnash | 0:9688737bf8cd | 185 | case 'a': |
richnash | 0:9688737bf8cd | 186 | case 'A': |
richnash | 0:9688737bf8cd | 187 | { |
richnash | 0:9688737bf8cd | 188 | // check for a valid ip address |
richnash | 0:9688737bf8cd | 189 | char szIP [20] ; // just enough to hold a |
richnash | 0:9688737bf8cd | 190 | char* pszParamsIP [4] ; // |
richnash | 0:9688737bf8cd | 191 | int numParams ; // |
richnash | 0:9688737bf8cd | 192 | int rcCheckParams ; // param format rc |
richnash | 0:9688737bf8cd | 193 | |
richnash | 0:9688737bf8cd | 194 | // Make sure we have an ok amount of chars ! |
richnash | 0:9688737bf8cd | 195 | if( strlen( pszTokens[i] ) > 15 ) |
richnash | 0:9688737bf8cd | 196 | { |
richnash | 0:9688737bf8cd | 197 | // invalid ip address |
richnash | 0:9688737bf8cd | 198 | return i; |
richnash | 0:9688737bf8cd | 199 | } |
richnash | 0:9688737bf8cd | 200 | |
richnash | 0:9688737bf8cd | 201 | // take a copy of the ip address to work on |
richnash | 0:9688737bf8cd | 202 | strcpy( szIP, pszTokens[i] ); |
richnash | 0:9688737bf8cd | 203 | |
richnash | 0:9688737bf8cd | 204 | // parse the ip using a dot |
richnash | 0:9688737bf8cd | 205 | numParams = UTILS_ParseString( szIP, pszParamsIP, 4, '.', PARSE_STRIP ); |
richnash | 0:9688737bf8cd | 206 | |
richnash | 0:9688737bf8cd | 207 | // check for a correctly formated set of params |
richnash | 0:9688737bf8cd | 208 | // yes this is a recursive call :-) so DONT put 'a' or 'A' in this line !!!!! |
richnash | 0:9688737bf8cd | 209 | rcCheckParams = UTILS_CheckParams( "iiii", numParams, pszParamsIP, 0 ); |
richnash | 0:9688737bf8cd | 210 | |
richnash | 0:9688737bf8cd | 211 | // check that the format was ok ! |
richnash | 0:9688737bf8cd | 212 | if( rcCheckParams != -1 ) |
richnash | 0:9688737bf8cd | 213 | { |
richnash | 0:9688737bf8cd | 214 | // failed :-( |
richnash | 0:9688737bf8cd | 215 | return i; |
richnash | 0:9688737bf8cd | 216 | } |
richnash | 0:9688737bf8cd | 217 | |
richnash | 0:9688737bf8cd | 218 | break; |
richnash | 0:9688737bf8cd | 219 | } |
richnash | 0:9688737bf8cd | 220 | |
richnash | 0:9688737bf8cd | 221 | // String |
richnash | 0:9688737bf8cd | 222 | case 's': |
richnash | 0:9688737bf8cd | 223 | case 'S': |
richnash | 0:9688737bf8cd | 224 | { |
richnash | 0:9688737bf8cd | 225 | // anything is ok.. |
richnash | 0:9688737bf8cd | 226 | break; |
richnash | 0:9688737bf8cd | 227 | } |
richnash | 0:9688737bf8cd | 228 | |
richnash | 0:9688737bf8cd | 229 | // character |
richnash | 0:9688737bf8cd | 230 | case 'c': |
richnash | 0:9688737bf8cd | 231 | case 'C': |
richnash | 0:9688737bf8cd | 232 | { |
richnash | 0:9688737bf8cd | 233 | // Make sure there is only 1 char |
richnash | 0:9688737bf8cd | 234 | if( strlen(pszTokens[i]) != 1 ) |
richnash | 0:9688737bf8cd | 235 | { |
richnash | 0:9688737bf8cd | 236 | // Error if its more than 1 char |
richnash | 0:9688737bf8cd | 237 | return i; |
richnash | 0:9688737bf8cd | 238 | } |
richnash | 0:9688737bf8cd | 239 | } |
richnash | 0:9688737bf8cd | 240 | } |
richnash | 0:9688737bf8cd | 241 | |
richnash | 0:9688737bf8cd | 242 | // Move onto the next mask char |
richnash | 0:9688737bf8cd | 243 | iMaskPos++; |
richnash | 0:9688737bf8cd | 244 | } |
richnash | 0:9688737bf8cd | 245 | |
richnash | 0:9688737bf8cd | 246 | // all ok :-) |
richnash | 0:9688737bf8cd | 247 | return -1; |
richnash | 0:9688737bf8cd | 248 | } |
richnash | 0:9688737bf8cd | 249 | |
richnash | 0:9688737bf8cd | 250 | |
richnash | 0:9688737bf8cd | 251 | //******************************************************************************* |
richnash | 0:9688737bf8cd | 252 | // |
richnash | 0:9688737bf8cd | 253 | //******************************************************************************* |
richnash | 0:9688737bf8cd | 254 | int UTILS_HEXtoDEC( int Pos1, int Pos2 ) // Convert 2 byte HEX to DEC |
richnash | 0:9688737bf8cd | 255 | { |
richnash | 0:9688737bf8cd | 256 | //int dump; |
richnash | 0:9688737bf8cd | 257 | |
richnash | 0:9688737bf8cd | 258 | // Now convert the HEX to DEC |
richnash | 0:9688737bf8cd | 259 | |
richnash | 0:9688737bf8cd | 260 | int DECval = 0; |
richnash | 0:9688737bf8cd | 261 | |
richnash | 0:9688737bf8cd | 262 | if(Pos2 <= 57) // Convert Pos2 from 16 base to 10 base |
richnash | 0:9688737bf8cd | 263 | { |
richnash | 0:9688737bf8cd | 264 | DECval = DECval + (Pos2-48); |
richnash | 0:9688737bf8cd | 265 | } |
richnash | 0:9688737bf8cd | 266 | else |
richnash | 0:9688737bf8cd | 267 | { |
richnash | 0:9688737bf8cd | 268 | DECval = DECval + (Pos2-55); |
richnash | 0:9688737bf8cd | 269 | } |
richnash | 0:9688737bf8cd | 270 | |
richnash | 0:9688737bf8cd | 271 | if(Pos1 <= 57) // Convert Pos1 from 16 base to 10 base |
richnash | 0:9688737bf8cd | 272 | { |
richnash | 0:9688737bf8cd | 273 | DECval = DECval + 16*(Pos1-48); |
richnash | 0:9688737bf8cd | 274 | } |
richnash | 0:9688737bf8cd | 275 | else |
richnash | 0:9688737bf8cd | 276 | { |
richnash | 0:9688737bf8cd | 277 | DECval = DECval + 16*(Pos1-55); |
richnash | 0:9688737bf8cd | 278 | } |
richnash | 0:9688737bf8cd | 279 | |
richnash | 0:9688737bf8cd | 280 | return DECval; |
richnash | 0:9688737bf8cd | 281 | } |
richnash | 0:9688737bf8cd | 282 | |
richnash | 0:9688737bf8cd | 283 | //******************************************************************************* |
richnash | 0:9688737bf8cd | 284 | // |
richnash | 0:9688737bf8cd | 285 | //******************************************************************************* |
richnash | 0:9688737bf8cd | 286 | char* UTILS_bit_sprintf(char* pszOut, int iValue, int length) |
richnash | 0:9688737bf8cd | 287 | { |
richnash | 0:9688737bf8cd | 288 | unsigned int mask = 0x01; |
richnash | 0:9688737bf8cd | 289 | int bit = 0; |
richnash | 0:9688737bf8cd | 290 | |
richnash | 0:9688737bf8cd | 291 | for( bit = length; bit >= 0; bit-- ) |
richnash | 0:9688737bf8cd | 292 | { |
richnash | 0:9688737bf8cd | 293 | if ((mask << bit) & iValue) |
richnash | 0:9688737bf8cd | 294 | { |
richnash | 0:9688737bf8cd | 295 | *(pszOut+bit) = '1'; |
richnash | 0:9688737bf8cd | 296 | } |
richnash | 0:9688737bf8cd | 297 | else |
richnash | 0:9688737bf8cd | 298 | { |
richnash | 0:9688737bf8cd | 299 | *(pszOut+bit) = '0'; |
richnash | 0:9688737bf8cd | 300 | } |
richnash | 0:9688737bf8cd | 301 | } |
richnash | 0:9688737bf8cd | 302 | |
richnash | 0:9688737bf8cd | 303 | *(pszOut+length) = '\0'; |
richnash | 0:9688737bf8cd | 304 | |
richnash | 0:9688737bf8cd | 305 | return pszOut; |
richnash | 0:9688737bf8cd | 306 | } |
richnash | 0:9688737bf8cd | 307 | |
richnash | 0:9688737bf8cd | 308 | |
richnash | 0:9688737bf8cd | 309 | // ================================================================================================================== |
richnash | 0:9688737bf8cd | 310 | // |
richnash | 0:9688737bf8cd | 311 | // ================================================================================================================== |
richnash | 0:9688737bf8cd | 312 | char *UTILS_replace_char_in_string(char *in_string, char to_search, char to_replace_with) |
richnash | 0:9688737bf8cd | 313 | { |
richnash | 0:9688737bf8cd | 314 | //char *buf; |
richnash | 0:9688737bf8cd | 315 | int i=0; //,j=0; |
richnash | 0:9688737bf8cd | 316 | //char temp[50]; |
richnash | 0:9688737bf8cd | 317 | |
richnash | 0:9688737bf8cd | 318 | while(in_string[i] !='\0') |
richnash | 0:9688737bf8cd | 319 | { |
richnash | 0:9688737bf8cd | 320 | if(in_string[i] == to_search ) |
richnash | 0:9688737bf8cd | 321 | { |
richnash | 0:9688737bf8cd | 322 | //temp[j] = to_replace_with; |
richnash | 0:9688737bf8cd | 323 | in_string[i] = to_replace_with; |
richnash | 0:9688737bf8cd | 324 | //j++; |
richnash | 0:9688737bf8cd | 325 | } |
richnash | 0:9688737bf8cd | 326 | //else |
richnash | 0:9688737bf8cd | 327 | //temp[j++] = string[i++]; |
richnash | 0:9688737bf8cd | 328 | i++; |
richnash | 0:9688737bf8cd | 329 | } |
richnash | 0:9688737bf8cd | 330 | |
richnash | 0:9688737bf8cd | 331 | //temp[j] = '\0'; |
richnash | 0:9688737bf8cd | 332 | //buf = (char *) malloc(strlen(temp) + 1); |
richnash | 0:9688737bf8cd | 333 | //strcpy(buf,temp); |
richnash | 0:9688737bf8cd | 334 | |
richnash | 0:9688737bf8cd | 335 | // printf("%s\n",buf); |
richnash | 0:9688737bf8cd | 336 | |
richnash | 0:9688737bf8cd | 337 | //return buf; |
richnash | 0:9688737bf8cd | 338 | return in_string; |
richnash | 0:9688737bf8cd | 339 | } |
richnash | 0:9688737bf8cd | 340 | |
richnash | 0:9688737bf8cd | 341 | // ================================================================================================================== |
richnash | 0:9688737bf8cd | 342 | // |
richnash | 0:9688737bf8cd | 343 | // ================================================================================================================== |
richnash | 0:9688737bf8cd | 344 | char *UTILS_strip_char_in_string(char *in_string, char to_search ) |
richnash | 0:9688737bf8cd | 345 | { |
richnash | 0:9688737bf8cd | 346 | int i=0,j=0; |
richnash | 0:9688737bf8cd | 347 | |
richnash | 0:9688737bf8cd | 348 | while(in_string[i] !='\0') |
richnash | 0:9688737bf8cd | 349 | { |
richnash | 0:9688737bf8cd | 350 | if(in_string[i] == to_search ) |
richnash | 0:9688737bf8cd | 351 | { |
richnash | 0:9688737bf8cd | 352 | ++i; |
richnash | 0:9688737bf8cd | 353 | } |
richnash | 0:9688737bf8cd | 354 | else |
richnash | 0:9688737bf8cd | 355 | { |
richnash | 0:9688737bf8cd | 356 | in_string[j] = in_string[i]; |
richnash | 0:9688737bf8cd | 357 | ++i; |
richnash | 0:9688737bf8cd | 358 | ++j; |
richnash | 0:9688737bf8cd | 359 | } |
richnash | 0:9688737bf8cd | 360 | |
richnash | 0:9688737bf8cd | 361 | in_string[j] = in_string[i]; |
richnash | 0:9688737bf8cd | 362 | } |
richnash | 0:9688737bf8cd | 363 | |
richnash | 0:9688737bf8cd | 364 | in_string[j] = '\0'; |
richnash | 0:9688737bf8cd | 365 | |
richnash | 0:9688737bf8cd | 366 | return in_string; |
richnash | 0:9688737bf8cd | 367 | } |