Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
Diff: string.cpp
- Revision:
- 3:6fc7976cc5bf
- Parent:
- 2:8788d711db7e
--- a/string.cpp Wed May 20 15:42:07 2020 +0000
+++ b/string.cpp Wed May 20 16:37:25 2020 +0000
@@ -1,49 +1,15 @@
#include "string.h"
-struct Token asToken[MAX_TOKEN_NR];
-
-struct Keyword asKeywordList[MAX_KEYWORD_NR]=
-{
-{CLB,"callib"},
-{GT, "goto" },
+struct Keyword asKeywordList[MAX_KEYWORD_NR] = {
+ {CLB,"callib"},
+ {GT, "goto" },
};
-
-unsigned char ucTokenCnt;
-
-void CopyString(char pcSource[], char pcDestination[]){
-
- unsigned char ucCharCounter;
-
- for(ucCharCounter=0;pcSource[ucCharCounter]!='\0';ucCharCounter++){
- pcDestination[ucCharCounter] = pcSource[ucCharCounter];
- }
- pcDestination[ucCharCounter] = '\0';
-}
+enum Result { OK, NOK };
-enum CompResult eCompareString(char pcStr1[], char pcStr2[]){
-
- unsigned char ucCharCounter;
-
- for(ucCharCounter=0;pcStr1[ucCharCounter] != '\0';ucCharCounter++){
- if (pcStr1[ucCharCounter] != pcStr2[ucCharCounter]) return DIFFERENT;
- }
- return EQUAL;
-}
-
-
-void AppendString (char pcSourceStr[],char pcDestinationStr[]){
-
- unsigned char ucEndPointer;
-
- for(ucEndPointer=0;pcDestinationStr[ucEndPointer]!='\0';ucEndPointer++) {}
- CopyString(pcSourceStr,pcDestinationStr+ucEndPointer);
-}
-
-
-void ReplaceCharactersInString(char pcString[],char cOldChar,char cNewChar){
+void Tokenizer::ReplaceCharactersInString(char pcString[],char cOldChar,char cNewChar){
unsigned char ucCharCounter;
@@ -53,25 +19,8 @@
}
-void UIntToHexStr(unsigned int uiValue, char pcStr[]){
-
- unsigned char ucNibbleCounter;
- unsigned char ucCurrentNibble;
-
- pcStr[0] = '0';
- pcStr[1] = 'x';
- for(ucNibbleCounter=0;ucNibbleCounter<4;ucNibbleCounter++){
- ucCurrentNibble = ((uiValue >> ucNibbleCounter*4) & HEX_bm);
- if(ucCurrentNibble>9)
- pcStr[5-ucNibbleCounter] = ucCurrentNibble - 10 + 'A';
- else
- pcStr[5-ucNibbleCounter] = ucCurrentNibble + '0';
- }
- pcStr[6] = '\0';
-}
-
-enum Result eHexStringToUInt(char pcStr[],unsigned int *puiValue){
+enum Result Tokenizer::eHexStringToUInt(char pcStr[],unsigned int *puiValue){
unsigned char ucCharCounter;
@@ -90,18 +39,8 @@
return OK;
}
-void AppendUIntToString (unsigned int uiValue, char pcDestinationStr[]){
-
- unsigned char ucEndPointer;
-
- for(ucEndPointer=0;pcDestinationStr[ucEndPointer]!='\0';ucEndPointer++) {}
- UIntToHexStr(uiValue,pcDestinationStr+ucEndPointer);
-}
-
-
-
-unsigned char ucFindTokensInString(char *pcString){
+unsigned char Tokenizer::ucFindTokensInString(char *pcString){
unsigned char ucTokenPointer;
unsigned char ucDelimiterCounter;
@@ -136,12 +75,12 @@
}
}
-enum Result eStringToKeyword (char pcStr[],enum KeywordCode *peKeywordCode){
+enum Result Tokenizer::eStringToKeyword (char pcStr[],enum KeywordCode *peKeywordCode){
unsigned char ucTokenCounter;
for(ucTokenCounter=0;ucTokenCounter<MAX_TOKEN_NR;ucTokenCounter++){
- if (eCompareString(pcStr,asKeywordList[ucTokenCounter].cString) == EQUAL) {
+ if (!strcmp(pcStr, asKeywordList[ucTokenCounter].cString)) {
*peKeywordCode = asKeywordList[ucTokenCounter].eCode;
return OK;
}
@@ -149,7 +88,7 @@
return NOK;
}
-void DecodeTokens(unsigned char ucTokenCnt){
+void Tokenizer::DecodeTokens(unsigned char ucTokenCnt){
unsigned char ucTokenCounter;
Token* tValue;
@@ -162,9 +101,21 @@
}
}
-void DecodeMsg(char *pcString){
+void Tokenizer::DecodeMsg(char *pcString){
ucTokenCnt = ucFindTokensInString(pcString);
ReplaceCharactersInString(pcString,' ','\0');
DecodeTokens(ucTokenCnt);
}
+
+enum TokenType Tokenizer::eGetTokenType(unsigned char ucIdx) {
+ return asToken[ucIdx].eType;
+}
+
+unsigned char Tokenizer::GetTokenCnt(void) {
+ return ucTokenCnt;
+}
+
+enum KeywordCode Tokenizer::eGetKeyword(unsigned char ucIdx) {
+ return asToken[ucIdx].uValue.eKeyword;
+}