Ejemplo n.º 1
0
bool GetValue(const std::string& sMessage, long& lval)
{
	std::string svalue = ExtractValue(sMessage);
   char *pend;
   const char* szValue = svalue.c_str();
   long lValue = strtol(szValue, &pend, 0);
   
   // return true only if scan was stopped by spaces, linefeed or the terminating NUL and if the
   // string was not empty to start with
   if (pend != szValue)
   {
      while( *pend!='\0' && (*pend==' '||*pend=='\n')) pend++;
      if (*pend=='\0')
      {
         lval = lValue;
         return true;
      }
   }
   return false;
}
Ejemplo n.º 2
0
bool GetValue(const std::string& sMessage, double& dval)
{
   std::string svalue = ExtractValue(sMessage);
   printf("GetValue(\"%s\", double)\n", sMessage.c_str());
#ifdef WIN32
   _locale_t loc = _create_locale(LC_ALL, "eng");
   char point = '.';
#else
   std::locale loc("");
   char point = std::use_facet<std::numpunct<char> >(loc).decimal_point();
#endif

   for(size_t p=0; p<svalue.length(); p++)
   {
     if (svalue[p] == '.' || svalue[p] == ',')
       svalue[p] = point;
   }

   char *pend;
   const char* szValue = svalue.c_str();

#ifdef WIN32
   double dValue =_strtod_l(szValue, &pend, loc);
#else
   double dValue = strtod(szValue, &pend);
#endif

   // return true only if scan was stopped by spaces, linefeed or the terminating NUL and if the
   // string was not empty to start with
   if (pend != szValue)
   {
      while( *pend!='\0' && (*pend==' '||*pend=='\n')) pend++;
      if (*pend=='\0')
      {
         dval = dValue;
         return true;
      }
   }
   return false;
}
Ejemplo n.º 3
0
BOOL vmsVideoSiteHtmlCodeParser::Parse_Youtube(LPCSTR pszHtml)
{
	fsString strTitle, strUrl;

	
	
	
	
	LPSTR psz = const_cast<LPSTR>(strstr (pszHtml, "<meta name=\"title\""));

	if (psz)
	{
		psz = strstr (psz, "content=");
		if (psz)
		{
			psz += lstrlen ("content=");
			if (*psz == '"')
			{
				psz++;
				while (*psz && *psz != '"')
				{
					if (is_valid_char (*psz))
						strTitle += *psz++;
					else
						psz++;				
				}
			}
		}
	}

	
	
	
	psz = const_cast<LPSTR>(strstr (pszHtml, "swfArgs ="));
	if (psz == NULL)
		return FALSE;
	psz = strchr (psz, '{');
	if (psz == NULL)
		return FALSE;
	psz++;

	fsString strBase = "http://youtube.com/";
	fsString strParams;
	
	while (*psz != '}')
	{
		while (*psz == ' ' || *psz == ',')
			psz++;

		fsString str;
	
		while (*psz && *psz != ':')
		{
			if (*psz == ' ')
			{
				str = "";
				break;
			}
			str += *psz++;
		}

		if (str.IsEmpty ())
			break;

		if (*psz == ':')
			psz++;
		while (*psz == ' ')
			psz++;

		if (str.Length () > 2 && str [0] == '"' && str [str.Length () - 1] == '"')
		{
			lstrcpy (str, str.pszString+1);
			str [str.Length () - 1] = 0;
		}

		if (lstrcmpi (str, "BASE_YT_URL") == 0)
		{
			strBase = ExtractValue (psz);
		}
		else
		{
			if (strParams.IsEmpty () == FALSE)
				strParams += '&';

			strParams += str; strParams += "="; strParams += ExtractValue (psz);
		}
	}

	strUrl = strBase;
	strUrl += "get_video?";
	strUrl += strParams;

	

	fsDecodeHtmlText (strTitle);

	m_strVideoTitle = strTitle;
	m_strVideoUrl   = strUrl;
	m_strVideoType  = "flv";
	m_bDirectLink   = TRUE;

	return TRUE;
}
Ejemplo n.º 4
0
void ParseExpression(TokenList &a_list, const std::string &a_expression)
{
	enum class ParseState {None, Number, Name} state = ParseState::None;
	int elen = a_expression.length() + 1;
	int idx = 0;
	int tstart = 0;
	char c_char, n_char;

	while (true)
	{
		if (idx < elen)
		{
			c_char = a_expression[idx];
			if (idx + 1 < elen) n_char = a_expression[idx + 1];
			else n_char = 0;
			idx++;
		}
		else
		{
			if (state == ParseState::Name)
			{
				a_list.AddToken(ExtractValue(a_expression, tstart, idx - 1, Token::Type::Name));
				a_list.tail->index = tstart + 1;
			}
			else if (state == ParseState::Number)
			{
				a_list.AddToken(ExtractValue(a_expression, tstart, idx - 1, Token::Type::Number));
				a_list.tail->index = tstart + 1;
			}
			break;
		}

		if (std::isspace(c_char) && state != ParseState::None)
		{
			a_list.AddToken(ExtractValue(a_expression, tstart, idx - 1, (state == ParseState::Name ? Token::Type::Name : Token::Type::Number)));
			a_list.tail->index = tstart + 1;
			state = ParseState::None;
		}
		else if (isop(c_char))
		{
			if (state != ParseState::None)
			{
				a_list.AddToken(ExtractValue(a_expression, tstart, idx - 1, (state == ParseState::Name ? Token::Type::Name : Token::Type::Number)));
				a_list.tail->index = tstart + 1;
			}

			switch (c_char)
			{
			case '+': a_list.AddToken(new Token(Token::OpType::Add, idx)); break;
			case '-':
				if (a_list.count == 0 || a_list.tail->optype != Token::OpType::None)
					a_list.AddToken(new Token(Token::OpType::Unary, idx));
				else a_list.AddToken(new Token(Token::OpType::Sub, idx));
				break;
			case '*': a_list.AddToken(new Token(Token::OpType::Mul, idx)); break;
			case '/': a_list.AddToken(new Token(Token::OpType::Div, idx)); break;
			case '^': a_list.AddToken(new Token(Token::OpType::Pow, idx)); break;
			case '%': a_list.AddToken(new Token(Token::OpType::Mod, idx)); break;
			case '(': a_list.AddToken(new Token(Token::OpType::LPar, idx)); break;
			case ')': a_list.AddToken(new Token(Token::OpType::RPar, idx)); break;
			case ',': a_list.AddToken(new Token(Token::OpType::Comma, idx)); break;
			case '<':
				if (n_char == '=')
				{
					a_list.AddToken(new Token(Token::OpType::LE, idx));
					idx++;
				}
				else a_list.AddToken(new Token(Token::OpType::LT, idx));
				break;
			case '>':
				if (n_char == '=')
				{
					a_list.AddToken(new Token(Token::OpType::GE, idx));
					idx++;
				}
				else a_list.AddToken(new Token(Token::OpType::GT, idx));
				break;
			case '=':
				if (n_char == '=')
				{
					a_list.AddToken(new Token(Token::OpType::EQ, idx));
					idx++;
				}
				break;
			case '!':
				if (n_char == '=')
				{
					a_list.AddToken(new Token(Token::OpType::NE, idx));
					idx++;
				}
				break;
			}
			state = ParseState::None;
		}
		else if (issp(c_char) && state == ParseState::None && !isalpha(n_char))
		{
			switch (c_char)
			{
			case 't': a_list.AddToken(new Token(Token::SpecialType::Time, idx)); break;
			case 'x': a_list.AddToken(new Token(Token::SpecialType::XAxis, idx)); break;
			}
		}
		else if (state == ParseState::None && std::isalnum(c_char))
		{
			if (std::isdigit(c_char))
			{
				tstart = idx - 1;
				state = ParseState::Number;
			}
			else if (std::isalpha(c_char))
			{
				tstart = idx - 1;
				state = ParseState::Name;
			}
		}
	}
}