Eli Hughes / Mbed 2 deprecated RobotPowerLogger-V2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers KeyValue.c Source File

KeyValue.c

00001 #include "System.h"
00002 
00003 
00004 CHAR Key[64];
00005 CHAR Value[64];
00006 
00007 BOOL KeyValueSplit(CHAR *LineBuf,CHAR *Key,CHAR *Value)
00008 {
00009     BOOL FoundKey = FALSE;
00010     
00011     DWORD StringLength;
00012     
00013     
00014     StringLength = strlen(LineBuf);
00015     
00016    
00017     if(LineBuf[StringLength-3] == '\r' || LineBuf[StringLength-3] == '\n')
00018     {
00019         LineBuf[StringLength-3] = NULL;
00020     }
00021     
00022     if(LineBuf[StringLength-2] == '\r' || LineBuf[StringLength-2] == '\n')
00023     {
00024         LineBuf[StringLength-2] = NULL;
00025     }
00026     
00027     if(LineBuf[StringLength-1] == '\r' || LineBuf[StringLength-1] == '\n')
00028     {
00029         LineBuf[StringLength-1] = NULL;
00030     }
00031     
00032     while(*LineBuf!=NULL)
00033     {
00034         if(FoundKey == FALSE)
00035         {
00036             if(*LineBuf > 32)
00037             {
00038                if(*LineBuf == '=')
00039                {
00040                   *Key = NULL;
00041                   FoundKey = TRUE;
00042                } 
00043                else
00044                {
00045                    *Key = *LineBuf;
00046                    Key++;
00047                }
00048             }
00049         }
00050         else
00051         {
00052             if(*LineBuf > 32)
00053                 {
00054                    *Value = *LineBuf;
00055                     Value++;
00056                 }
00057         }    
00058         
00059         LineBuf++;
00060     }
00061     
00062     
00063     //make sure the strings are terminated
00064     *Key = NULL;
00065     *Value = NULL;
00066 
00067     return FoundKey;
00068 }
00069