Example #1
0
			static std::deque<string_type> tokenize(string_type input, string_type br)
			{
				typename string_type::iterator a,b,c;
				std::deque<string_type> tokens;

				// std::cerr << "Tokenising string=" << input << " break=" << br << std::endl;

				while ( input.length() )
				{
					a = input.begin();
					c = input.end();
					typename string_type::size_type e = input.find(br);

					if ( e != string_type::npos )
					{
						b = a+e;
						tokens.push_back(string_type(a,b));
						input = string_type(b+br.length(),c);
					}
					else
					{
						tokens.push_back(input);
						input = string_type();
					}

					// std::cerr << "Pushed token " << tokens.back() << " input now " << input << std::endl;
				}

				return tokens;
			}
Example #2
0
 bool is_dropped(Char E) const
 {
   if (m_dropped_delims.length())
     return m_dropped_delims.find(E) != string_type::npos;
   else if (m_use_isspace) {
     return Traits::isspace(E) != 0;
   } else
     return false;
 }
Example #3
0
 bool is_kept(Char E) const
 {
   if (m_kept_delims.length())
     return m_kept_delims.find(E) != string_type::npos;
   else if (m_use_ispunct) {
     return Traits::ispunct(E) != 0;
   } else
     return false;
 }
Example #4
0
 bool is_dropped(Char E) const
 {
   if (m_dropped_delims.length())
     return m_dropped_delims.find(E) != string_type::npos;
   else if (m_use_isspace) {
     using namespace std; 
     return isspace(E) != 0;
   } else
     return false;
 }
Example #5
0
 bool is_kept(Char E) const
 {  
   if (m_kept_delims.length())
     return m_kept_delims.find(E) != string_type::npos;
   else if (m_use_ispunct) {
     using namespace std;
     return ispunct(E) != 0;
   } else
     return false;
 }
Example #6
0
 void parse_format(const string_type & format_str) {
     typedef typename string_type::size_type size_type;
     size_type msg_idx = format_str.find('%');
     if ( msg_idx != string_type::npos) {
         m_prefix = format_str.substr(0, msg_idx);
         m_suffix = format_str.substr( msg_idx + 1);
     }
     else
         // no suffix
         m_prefix = format_str; 
 }
Example #7
0
 bool is_nonret(Char E)const
 {
   if (nonreturnable_.length())
     return  nonreturnable_.find(E) != string_type::npos;
   else{
     if (no_isspace_) {return false;}
     else{
       int r = Traits::isspace(E);
       return r != 0;
     }
   }
 }
Example #8
0
 bool is_ret(Char E)const
 {  
   if (returnable_.length())
     return  returnable_.find(E) != string_type::npos;
   else{
     if (no_ispunct_) {return false;}
     else{
       using namespace std;
       int r = ispunct(E);
       return r != 0;
     }
   }
 }
Example #9
0
    /** @brief sets the format string: what should be before, and what after the original message, separated by "|"

    Example: \n
    "[%idx%] |\n" - this writes "[%idx%] " before the message, and "\n" after the message

    If "|" is not present, the whole message is prepended to the message
    */
    void format(const string_type & format_str) {
        m_format_str = format_str;

        typename string_type::size_type idx = format_str.find('|');
        string_type before, after;
        if ( idx != string_type::npos) {
            before = format_str.substr(0, idx);
            after = format_str.substr(idx + 1);
        }
        else
            before = format_str;

        format( before, after);
    };
Example #10
0
  /** \brief Replace all occurrences of a substring with another string. 
      \param strFind The string that shall be replaced.
      \param strReplaceWith The string that should be inserted instead of strFind
  */
  void ParserError::ReplaceSubString( string_type &strSource,
                                      const string_type &strFind,
                                      const string_type &strReplaceWith)
  {
    string_type strResult;
    string_type::size_type iPos(0), iNext(0);

    for(;;)
    {
      iNext = strSource.find(strFind, iPos);
      strResult.append(strSource, iPos, iNext-iPos);

      if( iNext==string_type::npos )
        break;

      strResult.append(strReplaceWith);
      iPos = iNext + strFind.length();
    } 

    strSource.swap(strResult);
  }
Example #11
0
            void extract( string_type const & data, string_type & name, string_type & value, basic_cookie<Tag> & c )
            {
                std::size_t pos = data.find( string_traits_type::convert('=') );
                name = data.substr( 0,pos );
                if ( pos != string_type::npos )
                {
                    value = data.substr( pos+1 );
                }

                if ( !value.empty() )
                {
                    if ( *value.begin() == '"' && *value.rbegin() != '"' )
                    {
                        value = name + string_traits_type::convert("=") + value;
                        return;
                    }
                    boost::trim_if( value, boost::is_any_of( string_traits_type::convert("\"") ) );
                }
                set_value( name, value, c );
                name.clear();
                value.clear();
            }
Example #12
0
int CCommonFnc::BYTE_ConvertFromHexStringToArray(string_type hexaString, BYTE* pArray, DWORD* pbArrayLen) {
    int         status = STAT_OK;
    DWORD       pos = 0;
    DWORD       pos2 = 0;
	string_type     hexNum;
    DWORD       num;
    BYTE*       pTempArray = NULL;
    DWORD       tempArrayPos = 0;

    // EAT SPACES
    //hexaString.TrimLeft(); hexaString.TrimRight();
	hexaString.erase(hexaString.find_last_not_of(_CONV(" ")) + 1);
	size_t startpos = hexaString.find_first_not_of(_CONV(" "));
	if (string_type::npos != startpos) {
		hexaString = hexaString.substr(startpos);
	}
    hexaString += _CONV(" ");
    hexaString.length();

    if (status == STAT_OK) {
        pTempArray = new BYTE[hexaString.length()];
        memset(pTempArray, 0, hexaString.length());

        pos = pos2 = 0;
        /*while ((pos = hexaString.Find(' ', pos2)) != -1) {
            hexNum = hexaString.Mid(pos2, pos - pos2);
            hexNum.TrimLeft(); hexNum.TrimRight();
            if (hexNum.GetLength() > 0) {
                num = strtol((LPCTSTR) hexNum, NULL, 16);
        
                if (num == 0xFF) pTempArray[tempArrayPos] = 0xFF;
                else pTempArray[tempArrayPos] = (BYTE) num & 0xFF;
                
                tempArrayPos++;
            }
            pos2 = pos + 1;
        }*/
		while ((pos = hexaString.find(' ', pos2)) != string_type::npos) {
			hexNum = hexaString.substr((pos2, pos - pos2));
			hexNum.erase(hexNum.find_last_not_of(_CONV(" ")) + 1);
			size_t startpos2 = hexNum.find_first_not_of(_CONV(" "));
			if (string_type::npos != startpos2) {
				hexNum = hexNum.substr(startpos2);
			}
			if (hexNum.length() > 0) {
				num = type_to_int((LPCTSTR)hexNum.c_str(), NULL, 16);

				if (num == 0xFF) pTempArray[tempArrayPos] = 0xFF;
				else pTempArray[tempArrayPos] = (BYTE)num & 0xFF;

				tempArrayPos++;
			}
			pos2 = pos + 1;
		}

        if (tempArrayPos > *pbArrayLen) {
            status = STAT_NOT_ENOUGHT_MEMORY;
        }  
        else {
            memcpy(pArray, pTempArray, tempArrayPos);
        }
        *pbArrayLen = tempArrayPos;

        if (pTempArray) delete[] pTempArray;
    }

    return status;
}