75 lines
1.6 KiB
C++
75 lines
1.6 KiB
C++
#ifndef _HTTP_READER_HPP_
|
|
#define _HTTP_READER_HPP_
|
|
#ifndef _COMMON_WINDOWS_HPP_
|
|
#include <common/windows.hpp>
|
|
#endif
|
|
|
|
class Reader
|
|
{
|
|
public:
|
|
Reader(void);
|
|
virtual ~Reader();
|
|
protected:
|
|
WORD getAt(int bracketLevel,String &lineString,String &textString);
|
|
float strToDec(String strNum);
|
|
private:
|
|
enum {LeftBracket='<',RightBracket='>'};
|
|
};
|
|
|
|
inline
|
|
Reader::Reader(void)
|
|
{
|
|
}
|
|
|
|
inline
|
|
Reader::~Reader()
|
|
{
|
|
}
|
|
|
|
WORD Reader::getAt(int bracketLevel,String &lineString,String &textString)
|
|
{
|
|
char *ptrStr=((LPSTR)lineString);
|
|
char *ptrEnd=((LPSTR)lineString+lineString.length());
|
|
String captureString;
|
|
|
|
for(int currLevel=0;currLevel<bracketLevel;currLevel++)
|
|
{
|
|
while(*ptrStr!=LeftBracket&&ptrStr<=ptrEnd)ptrStr++;
|
|
if(ptrStr>ptrEnd)return FALSE;
|
|
while(*ptrStr!=RightBracket&&ptrStr<=ptrEnd)ptrStr++;
|
|
if(ptrStr>ptrEnd)return FALSE;
|
|
}
|
|
ptrStr++;
|
|
while(*ptrStr!=LeftBracket&&ptrStr<=ptrEnd)captureString+=*ptrStr++;
|
|
if(captureString.isNull())return FALSE;
|
|
textString=captureString;
|
|
return TRUE;
|
|
}
|
|
|
|
inline
|
|
float Reader::strToDec(String strNum)
|
|
{
|
|
float number;
|
|
float num;
|
|
float den;
|
|
String frString;
|
|
String whString;
|
|
|
|
number=0.00;
|
|
if(strNum.isNull())return number;
|
|
if(strNum.strstr("."))return number=::atof(strNum);
|
|
whString=strNum.betweenString(0,' ');
|
|
if(whString.isNull())whString=strNum;
|
|
if(!whString.strstr("/"))
|
|
{
|
|
number=::atof(whString);
|
|
frString=strNum.betweenString(' ',0);
|
|
}
|
|
else frString=strNum;
|
|
if(frString.isNull())return number;
|
|
num=::atof(frString.betweenString(0,'/'));
|
|
den=::atof(frString.betweenString('/',0));
|
|
number+=num/den;
|
|
return number;
|
|
}
|
|
#endif |