Luca Jel
/
mbed5a_testy
sdsd
Fork of mbed5a_testy by
string.cpp@1:b8d65b5745d1, 2017-05-05 (annotated)
- Committer:
- Robsonik16
- Date:
- Fri May 05 20:01:41 2017 +0000
- Revision:
- 1:b8d65b5745d1
- Parent:
- other/string.cpp@0:e69a0b7f4b41
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Robsonik16 | 0:e69a0b7f4b41 | 1 | #include "string.h" |
Robsonik16 | 0:e69a0b7f4b41 | 2 | |
Robsonik16 | 0:e69a0b7f4b41 | 3 | void CopyString(char pcSource[], char pcDestination[]){ |
Robsonik16 | 0:e69a0b7f4b41 | 4 | |
Robsonik16 | 0:e69a0b7f4b41 | 5 | unsigned char ucCharacterCounter; |
Robsonik16 | 0:e69a0b7f4b41 | 6 | |
Robsonik16 | 0:e69a0b7f4b41 | 7 | for (ucCharacterCounter=0;(pcSource[ucCharacterCounter]!=NULL);ucCharacterCounter++){ |
Robsonik16 | 0:e69a0b7f4b41 | 8 | pcDestination[ucCharacterCounter]=pcSource[ucCharacterCounter]; |
Robsonik16 | 0:e69a0b7f4b41 | 9 | } |
Robsonik16 | 0:e69a0b7f4b41 | 10 | pcDestination[ucCharacterCounter]=pcSource[ucCharacterCounter]; |
Robsonik16 | 0:e69a0b7f4b41 | 11 | } |
Robsonik16 | 0:e69a0b7f4b41 | 12 | |
Robsonik16 | 0:e69a0b7f4b41 | 13 | enum CompResult eCompareString(char pcStr1[], char pcStr2[]){ |
Robsonik16 | 0:e69a0b7f4b41 | 14 | |
Robsonik16 | 0:e69a0b7f4b41 | 15 | unsigned char ucCharacterCounter; |
Robsonik16 | 0:e69a0b7f4b41 | 16 | |
Robsonik16 | 0:e69a0b7f4b41 | 17 | for(ucCharacterCounter=0;(pcStr1[ucCharacterCounter]!=NULL)&&(pcStr2[ucCharacterCounter]!=NULL);ucCharacterCounter++){ |
Robsonik16 | 0:e69a0b7f4b41 | 18 | if(pcStr1[ucCharacterCounter]!=pcStr2[ucCharacterCounter]){ |
Robsonik16 | 0:e69a0b7f4b41 | 19 | return NOTEQUAL; |
Robsonik16 | 0:e69a0b7f4b41 | 20 | } |
Robsonik16 | 0:e69a0b7f4b41 | 21 | } |
Robsonik16 | 0:e69a0b7f4b41 | 22 | if(pcStr1[ucCharacterCounter]!=pcStr2[ucCharacterCounter]){ |
Robsonik16 | 0:e69a0b7f4b41 | 23 | return NOTEQUAL; |
Robsonik16 | 0:e69a0b7f4b41 | 24 | } |
Robsonik16 | 0:e69a0b7f4b41 | 25 | return EQUAL; |
Robsonik16 | 0:e69a0b7f4b41 | 26 | } |
Robsonik16 | 0:e69a0b7f4b41 | 27 | |
Robsonik16 | 0:e69a0b7f4b41 | 28 | void AppendString (char pcSourceStr[], char pcDestinationStr[]){ |
Robsonik16 | 0:e69a0b7f4b41 | 29 | |
Robsonik16 | 0:e69a0b7f4b41 | 30 | unsigned char ucCharacterCounter; |
Robsonik16 | 0:e69a0b7f4b41 | 31 | |
Robsonik16 | 0:e69a0b7f4b41 | 32 | for (ucCharacterCounter=0;pcDestinationStr[ucCharacterCounter]!=NULL;ucCharacterCounter++){} |
Robsonik16 | 0:e69a0b7f4b41 | 33 | CopyString(pcSourceStr,pcDestinationStr+ucCharacterCounter); |
Robsonik16 | 0:e69a0b7f4b41 | 34 | } |
Robsonik16 | 0:e69a0b7f4b41 | 35 | |
Robsonik16 | 0:e69a0b7f4b41 | 36 | void ReplaceCharactersInString(char pcString[], char cOldChar,char cNewChar){ |
Robsonik16 | 0:e69a0b7f4b41 | 37 | |
Robsonik16 | 0:e69a0b7f4b41 | 38 | unsigned char ucCharacterCounter; |
Robsonik16 | 0:e69a0b7f4b41 | 39 | |
Robsonik16 | 0:e69a0b7f4b41 | 40 | for (ucCharacterCounter=0;pcString[ucCharacterCounter]!=NULL;ucCharacterCounter ++){ |
Robsonik16 | 0:e69a0b7f4b41 | 41 | if(pcString[ucCharacterCounter]==cOldChar){ |
Robsonik16 | 0:e69a0b7f4b41 | 42 | pcString[ucCharacterCounter]=cNewChar; |
Robsonik16 | 0:e69a0b7f4b41 | 43 | } |
Robsonik16 | 0:e69a0b7f4b41 | 44 | } |
Robsonik16 | 0:e69a0b7f4b41 | 45 | } |
Robsonik16 | 0:e69a0b7f4b41 | 46 | |
Robsonik16 | 0:e69a0b7f4b41 | 47 | void UIntToHexStr (unsigned int uiValue, char pcStr[]){ |
Robsonik16 | 0:e69a0b7f4b41 | 48 | |
Robsonik16 | 0:e69a0b7f4b41 | 49 | unsigned char ucBierzacaTetrada; |
Robsonik16 | 0:e69a0b7f4b41 | 50 | unsigned char ucLicznikTetrad; |
Robsonik16 | 0:e69a0b7f4b41 | 51 | |
Robsonik16 | 0:e69a0b7f4b41 | 52 | pcStr[0] = '0'; |
Robsonik16 | 0:e69a0b7f4b41 | 53 | pcStr[1] = 'x'; |
Robsonik16 | 0:e69a0b7f4b41 | 54 | pcStr[6] = NULL; |
Robsonik16 | 0:e69a0b7f4b41 | 55 | |
Robsonik16 | 0:e69a0b7f4b41 | 56 | for(ucLicznikTetrad = 0; ucLicznikTetrad < 4; ucLicznikTetrad++){ |
Robsonik16 | 0:e69a0b7f4b41 | 57 | ucBierzacaTetrada = (uiValue >> (ucLicznikTetrad*4)) & 0xF; |
Robsonik16 | 0:e69a0b7f4b41 | 58 | if(ucBierzacaTetrada < 10){ |
Robsonik16 | 0:e69a0b7f4b41 | 59 | pcStr[5 - ucLicznikTetrad] = '0' + ucBierzacaTetrada; |
Robsonik16 | 0:e69a0b7f4b41 | 60 | } |
Robsonik16 | 0:e69a0b7f4b41 | 61 | else{ |
Robsonik16 | 0:e69a0b7f4b41 | 62 | pcStr[5 - ucLicznikTetrad] = 'A' + ucBierzacaTetrada - 10; |
Robsonik16 | 0:e69a0b7f4b41 | 63 | } |
Robsonik16 | 0:e69a0b7f4b41 | 64 | } |
Robsonik16 | 0:e69a0b7f4b41 | 65 | } |
Robsonik16 | 0:e69a0b7f4b41 | 66 | |
Robsonik16 | 0:e69a0b7f4b41 | 67 | enum Result eHexStringToUInt(char pcStr[],unsigned int *puiValue){ |
Robsonik16 | 0:e69a0b7f4b41 | 68 | |
Robsonik16 | 0:e69a0b7f4b41 | 69 | char cZnakBiezacy; |
Robsonik16 | 0:e69a0b7f4b41 | 70 | unsigned char ucLicznikZnaku; |
Robsonik16 | 0:e69a0b7f4b41 | 71 | *puiValue=0; |
Robsonik16 | 0:e69a0b7f4b41 | 72 | |
Robsonik16 | 0:e69a0b7f4b41 | 73 | if((pcStr[0] != '0')||(pcStr[1] != 'x')||(pcStr[2] == NULL)){ |
Robsonik16 | 0:e69a0b7f4b41 | 74 | return (ERROR); |
Robsonik16 | 0:e69a0b7f4b41 | 75 | } |
Robsonik16 | 0:e69a0b7f4b41 | 76 | for(ucLicznikZnaku=2; pcStr[ucLicznikZnaku]!=NULL; ucLicznikZnaku++){ |
Robsonik16 | 0:e69a0b7f4b41 | 77 | cZnakBiezacy = pcStr[ucLicznikZnaku]; |
Robsonik16 | 0:e69a0b7f4b41 | 78 | if (ucLicznikZnaku>=6){ |
Robsonik16 | 0:e69a0b7f4b41 | 79 | return (ERROR); |
Robsonik16 | 0:e69a0b7f4b41 | 80 | } |
Robsonik16 | 0:e69a0b7f4b41 | 81 | *puiValue= *puiValue<<4; |
Robsonik16 | 0:e69a0b7f4b41 | 82 | if((cZnakBiezacy>='0')&&(cZnakBiezacy<='9')){ |
Robsonik16 | 0:e69a0b7f4b41 | 83 | *puiValue= *puiValue + (cZnakBiezacy-'0'); |
Robsonik16 | 0:e69a0b7f4b41 | 84 | }else if((cZnakBiezacy>='A')&&(cZnakBiezacy<='F')){ |
Robsonik16 | 0:e69a0b7f4b41 | 85 | *puiValue= *puiValue + (cZnakBiezacy-'A'+10); |
Robsonik16 | 0:e69a0b7f4b41 | 86 | }else{ |
Robsonik16 | 0:e69a0b7f4b41 | 87 | return (ERROR); |
Robsonik16 | 0:e69a0b7f4b41 | 88 | } |
Robsonik16 | 0:e69a0b7f4b41 | 89 | } |
Robsonik16 | 0:e69a0b7f4b41 | 90 | return (OK); |
Robsonik16 | 0:e69a0b7f4b41 | 91 | } |
Robsonik16 | 0:e69a0b7f4b41 | 92 | |
Robsonik16 | 0:e69a0b7f4b41 | 93 | void AppendUIntToString (unsigned int uiValue, char pcDestinationStr[]){ |
Robsonik16 | 0:e69a0b7f4b41 | 94 | |
Robsonik16 | 0:e69a0b7f4b41 | 95 | unsigned char ucLicznikZnakow; |
Robsonik16 | 0:e69a0b7f4b41 | 96 | |
Robsonik16 | 0:e69a0b7f4b41 | 97 | for (ucLicznikZnakow=0; pcDestinationStr[ucLicznikZnakow]!=NULL; ucLicznikZnakow++){} |
Robsonik16 | 0:e69a0b7f4b41 | 98 | UIntToHexStr(uiValue, pcDestinationStr+ucLicznikZnakow); |
Robsonik16 | 0:e69a0b7f4b41 | 99 | } |