Beispiel #1
0
bool CDDELink::ParseLink(const tstring& link, tstring& service, tstring& topic, tstring& item)
{
	size_t serviceBegin = 0;
	size_t serviceEnd = link.find_first_of('|', serviceBegin);

	if ( (serviceEnd == tstring::npos) || (serviceEnd == serviceBegin) )
		return false;

	size_t topicBegin = serviceEnd + 1;
	size_t topicEnd = link.find_first_of('!', topicBegin);

	if ( (topicEnd == tstring::npos) || (topicEnd == topicBegin) )
		return false;

	size_t itemBegin = topicEnd + 1;
	size_t itemEnd = link.length();

	if (itemEnd == itemBegin)
		return false;

	service = link.substr(serviceBegin, serviceEnd - serviceBegin);
	topic   = link.substr(topicBegin,   topicEnd   - topicBegin);
	item    = link.substr(itemBegin,    itemEnd    - itemBegin);

	ASSERT(service.length() != 0);
	ASSERT(topic.length() != 0);
	ASSERT(item.length() != 0);

	return true;
}
Beispiel #2
0
void Tokenize( const tstring& str, std::vector< T >& tokens, const tstring& delimiters )
{
    // Skip delimiters at beginning.
    tstring::size_type lastPos = str.find_first_not_of( delimiters, 0 );
    // Find first "non-delimiter".
    tstring::size_type pos     = str.find_first_of( delimiters, lastPos );

    I temp;
    while ( tstring::npos != pos || tstring::npos != lastPos )
    {
        // Found a token, convert it to the proper type for our vector
        tstringstream stream (str.substr( lastPos, pos - lastPos ));
        stream >> temp; // NOTE: Stream operator stops at spaces!
        if ( !stream.fail() )
        {
            // Add the token to the vector
            tokens.push_back( (T)temp );
        }
        else
        {
            HELIUM_BREAK();
        }
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of( delimiters, pos );
        // Find next "non-delimiter"
        pos = str.find_first_of( delimiters, lastPos );
    }
}
// -----------------------------------------------------------------------------------------
bool CPepeEngineConverter::parseBool(const tstring& str)
{
    if (
        (str.find_first_of(_T("true")) == 0) ||
        (str.find_first_of(_T("yes")) == 0) ||
        (str.find_first_of(_T("1")) == 0)
    ) {
        return true;
    } else {
        return false;
    }
}
Beispiel #4
0
void File::ensureDirectory(const tstring& aFile) noexcept
{
	dcassert(!aFile.empty());
	// Skip the first dir...
	tstring::size_type start = aFile.find_first_of(_T("\\/"));
	if (start == tstring::npos)
		return;
	start++;
	while ((start = aFile.find_first_of(_T("\\/"), start)) != tstring::npos)
	{
		::CreateDirectory((formatPath(aFile.substr(0, start + 1))).c_str(), NULL); //TODO Crash r501 sp1
		start++;
	}
}
Beispiel #5
0
void dir_reader::exclude(const tstring& spec) {
  if (spec.find_first_of(_T("?*")) != tstring::npos) {
    m_wildcard_excluded.insert(spec);
  } else {
    m_excluded.insert(spec);
  }
}
Beispiel #6
0
CTokenizer::CTokenizer(const tstring& p_Str, const tstring& p_Delimiters)
{
	const tstring::size_type len = p_Str.length();
	tstring::size_type i = 0;

	while(i < len)
	{
		// eat leading whitespace
		i = p_Str.find_first_not_of(p_Delimiters, i);
		if(i == tstring::npos)
			return;   // nothing left but white space

		// find the end of the token
		tstring::size_type j = p_Str.find_first_of(p_Delimiters, i);

		// push token
		if(j == tstring::npos) 
		{
			m_Tokens.push_back(p_Str.substr(i));
			return;
		} else
			m_Tokens.push_back(p_Str.substr(i, j - i));

		// set up for next loop
		i = j + 1;
	}
}
    bool CreateDirectory(const tstring& path)
    {
        size_t  pos   = 0;
        int     index = 0;
        tstring subPath;

        while((pos = path.find_first_of(_T("\\/"), pos)) != tstring::npos)
        {
            index++;
            pos++;
            if (index == 1)
            {
                continue;
            }
            subPath = path.substr(0, pos - 1);
            if (!DirectoryExists(subPath))
            {
                if (::CreateDirectory(subPath.c_str(), NULL) == FALSE)
                {
                    return false;
                }
            }
        }
        if (!DirectoryExists(path))
        {
            return ::CreateDirectory(path.c_str(), NULL) != FALSE;
        }
        return true;
    }
Beispiel #8
0
RegWrap::RegWrap( const tstring& sKey, REGSAM samDesired ) :
    hkSession( 0 )
{
    // Parse the key

    unsigned long iFirstSlash = sKey.find_first_of( _T("\\") );

    if ( iFirstSlash == tstring::npos )
        return;

    tstring sRootKey = sKey.substr( 0, iFirstSlash );
    tstring sSubKey = sKey.substr( iFirstSlash+1 );

    // Get the root key by its name

    HKEY hRootKey = (HKEY)-1;

    for ( unsigned long i = 0; rkam[i].szName != 0; ++i )
        if ( sRootKey == rkam[i].szName )
            hRootKey = rkam[i].hRootKey;

    if ( hRootKey == (HKEY)-1 )
        return;

    Init( hRootKey, sSubKey, samDesired );
}
Beispiel #9
0
inline void Tokenize<tstring, tstring>( const tstring& str, std::vector< tstring >& tokens, const tstring& delimiters )
{
    // Skip delimiters at beginning.
    tstring::size_type lastPos = str.find_first_not_of( delimiters, 0 );
    // Find first "non-delimiter".
    tstring::size_type pos     = str.find_first_of( delimiters, lastPos );

    while ( tstring::npos != pos || tstring::npos != lastPos )
    {
        // Add the token to the vector
        tokens.push_back( str.substr( lastPos, pos - lastPos ) );
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of( delimiters, pos );
        // Find next "non-delimiter"
        pos = str.find_first_of( delimiters, lastPos );
    }
}
void PopupManager::ShowPm(const tstring& nick, const tstring& msg, HWND owner){
	int pos = msg.find_first_of(_T(">"))+1;
	if(pos == tstring::npos )
		pos = 0;

	tstring s = TSTRING(POPUP_NEW_PM) + _T(" ") + nick + _T(" ") + TSTRING(POPUP_MSG) + msg.substr(pos);
	Show(s, owner);
}
Beispiel #11
0
int lazy_protocol::maybe_have_delim(tstring const& input)
{
    size_t pos =  input.find_first_of(waiter_delim_.data(), waiter_delim_.size());
    if( pos == tstring::npos ) {
        again();
        return 0;
    }
    return call(waiter_method_, tstring(input.data(), pos));
}
void PopupManager::ShowMC(const tstring& msg, HWND owner){
	int pos1 = msg.find_first_of(_T("<"));
	int pos2 = msg.find_first_of(_T(">"));
	
	//something wrong with the string, return
	if(pos1 == tstring::npos || pos2 == tstring::npos)
		return;

	ShowMC(msg.substr(pos1+1, pos2-pos1-1), msg.substr(pos2+1), owner);
	
}
Beispiel #13
0
tstring ChatCtrl::rtfEscape(tstring str) {
	tstring::size_type i = 0;
	while((i = str.find_first_of(_T("{}\\\n"), i)) != tstring::npos) {
		switch(str[i]) {
			// no need to process \r handled elsewhere
			case '\n': str.replace(i, 1, _T("\\line\n")); i+=6; break;
			default: str.insert(i, _T("\\")); i+=2;
		}
	}
	return str;
}
bool PropertyValueVariables::containsLatePropertyVariables(const tstring& strProperty)
{
	bool latePropertyVariableExist = false;
	try
	{
		int indexStartOfVariable = 0;
		for( ;; )
		{
			indexStartOfVariable = strProperty.find_first_of( _T("${"), indexStartOfVariable);
			if( indexStartOfVariable == -1 )
			{
				return latePropertyVariableExist;
			}

			int indexEndOfVariable = strProperty.find_first_of( _T("}"), indexStartOfVariable );
			if( indexEndOfVariable == -1 )
			{
				return latePropertyVariableExist;
			}

			tstring variable = strProperty.substr(indexStartOfVariable+2, indexEndOfVariable - indexStartOfVariable - 2);
			LocalUtilities::trim(variable);
			DEBUG_SHOW( _T("containsLatePropertyVariables variable=") + variable);
			
			// compare late property value variables here
			// future - put late property value variables in a vector
			if( variable.compare( FOUND_JAVA_HOME ) == 0 )
			{
				return true;
			}

			indexStartOfVariable = indexEndOfVariable;
		}
	}
	catch(...)
	{
		DEBUG_SHOW( _T("Exception in containsLatePropertyVariables") );
		ErrHandler::severeError( _T("Error while determining if property contains late variables.") );
	}
	return latePropertyVariableExist;
}
Beispiel #15
0
std::string remove_all_extensions(tstring const& filename)
{
	const size_t last_slash = filename.find_last_of("\\/");
	const size_t last_dot = filename.find_first_of('.', last_slash);
	if( ( last_dot == tstring::npos ) ||
		( last_dot == filename.size() - 1 ) ) 
	{
		return filename.str();
	} else {
		tstring result = filename.substr(0, last_dot);
		return result.str();
	}
}
Beispiel #16
0
bool has_extension(tstring const& filename)
{
    size_t find_start = filename.find_last_of("\\/");
    if( find_start == tstring::npos )
        find_start = 0;
    else
        find_start++;
    
    const size_t dot_pos = filename.find_first_of('.', find_start);
    const bool dot_exists =   (dot_pos != tstring::npos);
    const bool not_at_start = (dot_pos > find_start);
    return dot_exists && not_at_start;
}
bool PropertyValueVariables::containsPropertyVariables(const tstring& strProperty)
{
	try
	{
		int indexStartOfVariable = strProperty.find_first_of( _T("${") );
		if( indexStartOfVariable == -1 )
		{
			return false;
		}

		int indexEndOfVariable = strProperty.find_first_of( _T("}"), indexStartOfVariable );
		if( indexEndOfVariable == -1 )
		{
			return false;
		}
	}
	catch(...)
	{
		DEBUG_SHOW( _T("Exception in containsEarlyPropertyVariables") );
		ErrHandler::severeError( _T("Error while determining if property contains early variables.") );
	}
	return true;
}
Beispiel #18
0
inline void Tokenize( const tstring& str, std::map< TKey, TVal >& tokens, const tstring& delimiters )
{
    // Skip delimiters at beginning.
    tstring::size_type lastPos = str.find_first_not_of( delimiters, 0 );
    // Find first "non-delimiter".
    tstring::size_type pos     = str.find_first_of( delimiters, lastPos );

    while ( tstring::npos != pos || tstring::npos != lastPos )
    {
        tstringstream kStream( str.substr( lastPos, pos - lastPos ) );

        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of( delimiters, pos );
        // Find next "non-delimiter"
        pos = str.find_first_of( delimiters, lastPos );

        if ( tstring::npos != pos || tstring::npos != lastPos )
        {
            tstringstream vStream( str.substr( lastPos, pos - lastPos ) );

            // At this point, we have the key and value.  Build the map entry.
            // Note that the stream operator stops at spaces.
            TKey k;
            kStream >> k;
            TVal v;
            vStream >> v;
            tokens.insert( std::map< TKey, TVal >::value_type( k, v ) );

            // Skip delimiters.  Note the "not_of"
            lastPos = str.find_first_not_of( delimiters, pos );

            // Find next "non-delimiter"
            pos = str.find_first_of( delimiters, lastPos );
        }
        else
        {
Beispiel #19
0
bool
WayPointFileZander::parseString(const TCHAR* src, tstring& dest)
{
  if (src[0] == 0)
    return true;

  dest.assign(src);

  // Cut the string after the first space, tab or null character
  size_t found = dest.find_first_of(_T(" \t\0"));
  if (found != tstring::npos)
    dest = dest.substr(0, found);

  trim_inplace(dest);
  return true;
}
Beispiel #20
0
inline std::vector<tstring<Elem>> split(tstring<Elem> text, tstring<Elem> const & delimiters)
{
   auto tokens = std::vector<tstring<Elem>>{};

   size_t pos, prev_pos = 0;
   while ((pos = text.find_first_of(delimiters, prev_pos)) != std::string::npos)
   {
      if (pos > prev_pos)
         tokens.push_back(text.substr(prev_pos, pos - prev_pos));
      prev_pos = pos + 1;
   }

   if (prev_pos< text.length())
      tokens.push_back(text.substr(prev_pos, std::string::npos));

   return tokens;
}
Beispiel #21
0
/*!
    Splits \a cmd into list of arguments (space-separated).
*/
vector<tstring> CommandParser::splitCommand(const tstring & cmd)
{
    tstring space = _T(" \t\f\v\n\r");
    vector<tstring> args;

    size_t space_pos = 0, start_pos = 0;

    while (true) {
        space_pos = cmd.find_first_of(space, start_pos);
        if (space_pos == tstring::npos) {
            args.push_back(cmd.substr(start_pos, cmd.length() - start_pos));
            break;
        } else {
            args.push_back(cmd.substr(start_pos, space_pos - start_pos));
        }

        start_pos = cmd.find_first_not_of(space, space_pos);
    }

    return args;
}
Beispiel #22
0
	void char_data(tstring const& content)
	{
		ensure_tag_start_closed();
		if( true || ! options.human_readable ) {
			// TODO it should be escaped!
			write_content_bytes(content);
		} else {
			tstring::size_type pos = 0;
			do {
				maybe_indent();
				tstring::size_type const next_lf = content.find_first_of('\n',pos);
				if( pos == tstring::npos ) {  
					write_content_bytes(content.substr(pos));
					break;
				} 
				
				// TODO it should be escaped!
				write_content_bytes(content.substr(pos, next_lf - pos + 1));
				pos = next_lf + 1;
			} while( pos < content.size());
		}
	}
Beispiel #23
0
bool Items::Process(const tstring& key, const tstring& value)
{
  if (__super::Process(key, value))
    return true;

  if (key == ITEMS_ATTR_REQUIRED)
  {
    if (value == ATTR_VALUE_TRUE)
    {
      m_Required = true;
      return true;
    }
    else if (value == ATTR_VALUE_FALSE)
    {
      m_Required = false;
      return true;
    }
  }
  else if (key == ITEMS_ATTR_ITEM)
  {
    size_t delim = value.find_first_of(ITEMS_ATTR_ITEM_DELIM);

    if (delim != tstring::npos)
    {
      m_Statics.push_back(Item (value.substr(0, delim), value.substr(delim+1)));
    }

    return true;
  }
  else if (key == ITEMS_ATTR_PREFIX)
  {
    m_Prefix = value;
    return true;
  }

  return false;
}
int CFulEditCtrl::FullTextMatch(ColorSettings* cs, CHARFORMAT2 &cf, const tstring &line, int pos, int &lineIndex) {
	int index = tstring::npos;
	tstring searchString;

	if( cs->getMyNick() ) {
		tstring::size_type p = cs->getMatch().find(_T("$mynick$"));
		if(p != tstring::npos) {
			searchString = cs->getMatch();
			searchString = searchString.replace(p, 8, nick);
		} 
	} else {
		searchString = cs->getMatch();
	}
	
	//we don't have any nick to search for
	//happens in pm's have to find a solution for this
	if(searchString.empty())
		return tstring::npos;


	//do we want to highlight the timestamps?
	if( cs->getTimestamps() ) {
		if( line[0] != _T('[') )
			return tstring::npos;
		index = 0;
	} else if( cs->getUsers() ) {
		if(timeStamps) {
			index = line.find(_T("] <"));
			// /me might cause this to happen
			if(index == tstring::npos)
				return tstring::npos;
			//compensate for "] "
			index += 2;
		} else if( line[0] == _T('<')) {
			index = 0;
		}
	}else{
		if( cs->getCaseSensitive() ) {
			index = line.find(searchString, pos);
		}else {
			index = Util::findSubString(line, searchString, pos);	
			//index = Text::toLower(line).find(Text::toLower(searchString), pos);
		}
	}
	//return if no matches where found
	if( index == tstring::npos )
		return tstring::npos;

	pos = index + searchString.length();
	
	//found the string, now make sure it matches
	//the way the user specified
	int length;
		
	if( !cs->getUsers() && !cs->getTimestamps() ) {
		length = searchString.length();
		int p = 0;
			
		switch(cs->getMatchType()){
			case 0: //Begins
				p = index-1;
                if(line[p] != _T(' ') && line[p] != _T('\r') &&	line[p] != _T('\t') )
					return tstring::npos;
				break;
			case 1: //Contains
				break;
			case 2: // Ends
				p = index+length;
				if(line[p] != _T(' ') && line[p] != _T('\r') &&	line[p] != _T('\t') )
					return tstring::npos;
				break;
			case 3: // Equals
				if( !( (index == 0 || line[index-1] == _T(' ') || line[index-1] == _T('\t')) && 
					(line[index+length] == _T(' ') || line[index+length] == _T('\r') || 
					line[index+length] == _T('\t')) ) )
					return tstring::npos;
				break;
		}
	}

	long begin, end;

	begin = lineIndex;
		
	if( cs->getTimestamps() ) {
		tstring::size_type pos = line.find(_T("]"));
		if( pos == tstring::npos ) 
			return tstring::npos;  //hmm no ]? this can't be right, return
		
		begin += index +1;
		end = begin + pos -1;
	} else if( cs->getUsers() ) {
		end = begin + line.find(_T(">"));
		begin += index +1;
	} else if( cs->getWholeLine() ) {
		end = begin + line.length();
	} else if( cs->getWholeWord() ) {
		int tmp;

		tmp = line.find_last_of(_T(" \t\r"), index);
		if(tmp != tstring::npos )
			begin += tmp+1;
		
		tmp = line.find_first_of(_T(" \t\r"), index);
		if(tmp != tstring::npos )
			end = lineIndex + tmp;
		else
			end = lineIndex + line.length();
	} else {
		begin += index;
		end = begin + searchString.length();
	}

	SetSel(begin, end);
		
	SetSelectionCharFormat(cf);

	SetSel(GetTextLength()-1, GetTextLength()-1);
	SetSelectionCharFormat(selFormat);

	CheckAction(cs, line);

	if( cs->getTimestamps() || cs->getUsers() )
		return tstring::npos;
	
	return pos;
}
Beispiel #25
0
void litehtml::css::parse_atrule( const tstring& text, const tchar_t* baseurl, document* doc, media_query_list::ptr& media )
{
	if(text.substr(0, 7) == _t("@import"))
	{
		int sPos = 7;
		tstring iStr;
		iStr = text.substr(sPos);
		if(iStr[iStr.length() - 1] == _t(';'))
		{
			iStr.erase(iStr.length() - 1);
		}
		trim(iStr);
		string_vector tokens;
		split_string(iStr, tokens, _t(" "), _t(""), _t("(\""));
		if(!tokens.empty())
		{
			tstring url;
			parse_css_url(tokens.front(), url);
			if(url.empty())
			{
				url = tokens.front();
			}
			tokens.erase(tokens.begin());
			if(doc)
			{
				document_container* doc_cont = doc->container();
				if(doc_cont)
				{
					tstring css_text;
					tstring css_baseurl;
					if(baseurl)
					{
						css_baseurl = baseurl;
					}
					doc_cont->import_css(css_text, url, css_baseurl);
					if(!css_text.empty())
					{
						media_query_list::ptr new_media = media;
						if(!tokens.empty())
						{
							tstring media_str;
							for(string_vector::iterator iter = tokens.begin(); iter != tokens.end(); iter++)
							{
								if(iter != tokens.begin())
								{
									media_str += _t(" ");
								}
								media_str += (*iter);
							}
							new_media = media_query_list::create_from_string(media_str, doc);
							if(!new_media)
							{
								new_media = media;
							}
						}
						parse_stylesheet(css_text.c_str(), css_baseurl.c_str(), doc, new_media);
					}
				}
			}
		}
	} else if(text.substr(0, 6) == _t("@media"))
	{
		tstring::size_type b1 = text.find_first_of(_t('{'));
		tstring::size_type b2 = text.find_last_of(_t('}'));
		if(b1 != tstring::npos)
		{
			tstring media_type = text.substr(6, b1 - 6);
			trim(media_type);
			media_query_list::ptr new_media = media_query_list::create_from_string(media_type, doc);

			tstring media_style;
			if(b2 != tstring::npos)
			{
				media_style = text.substr(b1 + 1, b2 - b1 - 1);
			} else
			{
				media_style = text.substr(b1 + 1);
			}

			parse_stylesheet(media_style.c_str(), baseurl, doc, new_media);
		}
	}
}
Beispiel #26
0
void Script::ParseAttributes(tstring& attributes, Control* control)
{
  INSPECT_SCOPE_TIMER( ("Attributes Script Attribute Processing") );
  
  size_t pos = 0;
  size_t end = tstring::npos;

  while (pos < attributes.length() && pos != tstring::npos)
  {
    // eat ws
    pos = attributes.find_first_not_of(LS_WHITESPACE, pos);

    // the rest is WS, abort
    if (pos == tstring::npos)
      break;

    // search for end of keyword
    end = attributes.find_first_of(LS_WHITESPACE TXT( "=" ), pos);

    // we have no symbol term, just abort
    if (end == tstring::npos)
      break;

    // copy just our symbol into a string
    tstring key (attributes.data() + pos, end - pos);

    // next tchar
    pos = end+1;

    // eat ws
    pos = attributes.find_first_not_of(LS_WHITESPACE, pos);

    // the rest is WS, abort
    if (pos == tstring::npos)
      break;

    // see if the value is directly quoted
    size_t startQuote = attributes.find_first_of( TXT( "\"" ), pos);
    size_t endQuote = attributes.find_first_of( TXT( "\"" ), startQuote+1);

    // search for end of keyword
    end = attributes.find_first_of( TXT( ";" ), pos);

    // if the semi is in the quote
    if (startQuote != tstring::npos && endQuote != tstring::npos && startQuote < end && end < endQuote)
    {
      // search for end of value not quoted
      end = attributes.find_first_of( TXT( ";" ), endQuote);
    }

    // we have no symbol term, just abort
    if (end == tstring::npos)
    {
      end = attributes.length();
    }

    // copy just our symbol into a string
    tstring value (attributes.data() + pos, end - pos);

    // next tchar
    pos = end+1;

    // trim quoted values
    {
      size_t start = value.find_first_of('\"');
      size_t finish = value.find_last_of('\"');

      if (start != tstring::npos)
      {
        if (start == finish)
        {
          value.erase(start, 1);
        }
        else if (start < finish)
        {
          value = value.substr(start + 1, finish - start - 1);
        }
      }
    }

    // insert
    control->Process(key, value);
  }
}