Back

// PSLCmdParam.cpp : Implementation of CPSLCmdParam

#include "stdafx.h"
#include "PSLCmdParam.h"

CPSLCmdParam::CPSLCmdParam()
{
   m_sName = _T("");
   m_sValue = _T("");
   m_sCommand = _T("");
}

HRESULT CPSLCmdParam::FinalConstruct()
{
   return S_OK;
}

void CPSLCmdParam::FinalRelease()
{
}

/*
Command name must always start with either '/' or '-';
Otherwise, this is not a command, and goes into Value;

The command name must have at least one symbol in it;

When values are within quotes, quotes are removed;
Value is truncated to contain no leading spaces;
*/
void CPSLCmdParam::Initialize(LPCTSTR sCommand)
{
   m_sCommand = sCommand;

   long L = (long)_tcslen(sCommand);
   tstring buffer;
   buffer.resize(L + 1);
   TCHAR symbol = sCommand[0];
   int idx = 0;
   if(symbol == '/' || symbol == '-')
   {
      // This looks like a command;
      if(L < 2)
         return; // Nothing;
      bool bHasValue = false;
      idx ++;
      while(idx < L)
      {
         symbol = sCommand[idx];
         if(symbol == ' ')
         {
            if(idx > 1)
            {
               _tcsncpy_s((LPTSTR)buffer.c_str(), L + 1, sCommand + 1, idx);
               m_sName = buffer.c_str();
            }
            break;
         }
         if(symbol == '"')
            break;
         if(symbol == ':' || symbol == '=')
         {
            if(idx > 1)
            {
               _tcsncpy_s((LPTSTR)buffer.c_str(), L + 1, sCommand + 1, idx - 1);
               m_sName = buffer.c_str();
            }
            idx ++;
            break;
         }
         idx ++;
         if(idx == L && idx > 1)
         {
            _tcsncpy_s((LPTSTR)buffer.c_str(), L + 1, sCommand + 1, idx - 1);
            m_sName = buffer.c_str();
         }
      }
   }
   if(idx >= L)
      return;
   if(sCommand[idx] == '"')
      idx ++;
   int start = idx;
   while(idx < L)
   {
      if(sCommand[idx] == '"')
         break;
      idx ++;
   }
   _tcsncpy_s((LPTSTR)buffer.c_str(), L + 1, sCommand + start, idx - start);
   trim(buffer);
   m_sValue = buffer.c_str();
}

////////////////////////////////////////////////////////////////////////
// Interface Implementation;
////////////////////////////////////////////////////////////////////////

STDMETHODIMP CPSLCmdParam::get_Name(BSTR * pValue)
{
   PSL_BEGIN

   *pValue = m_sName.copy();

   PSL_END
}

STDMETHODIMP CPSLCmdParam::get_Value(BSTR * pValue)
{
   PSL_BEGIN

   *pValue = m_sValue.copy();

   PSL_END
}

STDMETHODIMP CPSLCmdParam::get_Command(BSTR * pValue)
{
   PSL_BEGIN

   *pValue = m_sCommand.copy();

   PSL_END
}

Top