Пример #1
0
//-----------------------------------------------------------------------------
void BackdoorKeeper::Tokenize(const std::wstring&        str,
                              std::vector<std::wstring>& tokens,
                              const std::wstring&        delimiters)
{
    using namespace std;

    tokens.clear();

    // Skip delimiters at beginning.
    wstring::size_type currPos = str.find_first_not_of(delimiters, 0);

    while (currPos != string::npos)
    {
        wstring::size_type lastPos = str.find_first_of(delimiters, currPos);

        wstring::size_type count;

        if (lastPos == wstring::npos)
        {
            count = lastPos;
        }
        else
        {
            count = lastPos - currPos;
        }

        tokens.push_back(str.substr(currPos, count));

        currPos = str.find_first_not_of(delimiters, lastPos);
    }
}
Пример #2
0
/*
** Splits the string from the delimiters and trims whitespace.
*/
std::vector<std::wstring> DialogInstall::Tokenize(const std::wstring& str, const std::wstring& delimiters)
{
	// Modified from http://www.digitalpeer.com/id/simple
	std::vector<std::wstring> tokens;
	std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0);	// Skip delimiters at beginning
	std::wstring::size_type pos = str.find_first_of(delimiters, lastPos);	// Find first "non-delimiter"

	while (std::wstring::npos != pos || std::wstring::npos != lastPos)
	{
		std::wstring tmpStr = str.substr(lastPos, pos - lastPos);
		std::wstring::size_type tmpPos = tmpStr.find_first_not_of(L" \t");
		if (tmpPos != std::wstring::npos)
		{
			tmpStr.erase(0, tmpPos);
			tmpPos = tmpStr.find_last_not_of(L" \t");
			if (tmpPos != std::wstring::npos)
			{
				tmpStr.resize(tmpPos + 1);
			}
			tokens.push_back(tmpStr);
		}
		else
		{
			tokens.push_back(L"");	// Add empty string
		}
		lastPos = str.find_first_not_of(delimiters, pos);	// Skip delimiters. Note the "not_of"
		pos = str.find_first_of(delimiters, lastPos);		// Find next "non-delimiter"
	}

	return tokens;
}
Пример #3
0
static void tokenize(const std::wstring& str, std::vector<std::wstring>& tokens, const std::wstring& delimiters) {
	std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0);
	std::wstring::size_type pos = str.find_first_of(delimiters, lastPos);
	
	while (std::wstring::npos != pos || std::wstring::npos != lastPos) {
		tokens.push_back(str.substr(lastPos, pos - lastPos));
		lastPos = str.find_first_not_of(delimiters, pos);
		pos = str.find_first_of(delimiters, lastPos);
	}
}
Пример #4
0
void StringUtil::rtrim(std::wstring& str) {
	if (str.empty())
		return;

	std::wstring::size_type pos = str.find_first_not_of(L" ");
	if (pos != std::wstring::npos)
		str.erase(0,pos);

	pos = str.find_first_not_of(L"\t");
	if (pos != std::wstring::npos)
		str.erase(0,pos);
}
Пример #5
0
std::vector<std::wstring> utils::wtokenize(const std::wstring& str, std::wstring delimiters) {
	/*
	 * This function tokenizes a string by the delimiters. Plain and simple.
	 */
	std::vector<std::wstring> tokens;
	std::wstring::size_type last_pos = str.find_first_not_of(delimiters, 0);
	std::wstring::size_type pos = str.find_first_of(delimiters, last_pos);

	while (std::string::npos != pos || std::string::npos != last_pos) {
		tokens.push_back(str.substr(last_pos, pos - last_pos));
		last_pos = str.find_first_not_of(delimiters, pos);
		pos = str.find_first_of(delimiters, last_pos);
	}
	return tokens;
}
Пример #6
0
/*
** Splits the string from the delimiters
**
** http://www.digitalpeer.com/id/simple
*/
std::vector<std::wstring> CConfigParser::Tokenize(const std::wstring& str, const std::wstring& delimiters)
{
	std::vector<std::wstring> tokens;

	std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0);	// skip delimiters at beginning.
	std::wstring::size_type pos = str.find_first_of(delimiters, lastPos);	// find first "non-delimiter".

	while (std::wstring::npos != pos || std::wstring::npos != lastPos)
	{
		tokens.push_back(str.substr(lastPos, pos - lastPos));    	// found a token, add it to the vector.
		lastPos = str.find_first_not_of(delimiters, pos);    	// skip delimiters.  Note the "not_of"
		pos = str.find_first_of(delimiters, lastPos);    	// find next "non-delimiter"
	}

	return tokens;
}
std::wstring 
stringHelper::ltrim( const std::wstring& wstr )
{
	if ( wstr.empty() ) return wstr ;

	return wstr.substr( wstr.find_first_not_of( __delimiters ) ) ;
}
/* 
 * Trim chTarget from the left of string s.
 */
void StringUtils::STLTrimLeft(std::wstring& s, wchar_t chTarget)
{
	std::wstring::size_type n = s.find_first_not_of( chTarget );
	if( n == std::wstring::npos )
		return;
	s = s.substr( n );
}
Пример #9
0
/*
** Splits the string from the delimiters.
** Now trims empty element in vector and white-space in each string.
**
** Modified from http://www.digitalpeer.com/id/simple
*/
std::vector<std::wstring> ConfigParser::Tokenize(const std::wstring& str, const std::wstring& delimiters)
{
    std::vector<std::wstring> tokens;

    size_t lastPos, pos = 0;
    do
    {
        lastPos = str.find_first_not_of(delimiters, pos);
        if (lastPos == std::wstring::npos) break;

        pos = str.find_first_of(delimiters, lastPos + 1);
        std::wstring token = str.substr(lastPos, pos - lastPos);  // len = (pos != std::wstring::npos) ? pos - lastPos : pos

        size_t pos2 = token.find_first_not_of(L" \t\r\n");
        if (pos2 != std::wstring::npos)
        {
            size_t lastPos2 = token.find_last_not_of(L" \t\r\n");
            if (pos2 != 0 || lastPos2 != (token.size() - 1))
            {
                // Trim white-space
                token.assign(token, pos2, lastPos2 - pos2 + 1);
            }
            tokens.push_back(token);
        }

        if (pos == std::wstring::npos) break;
        ++pos;
    }
    while (true);

    return tokens;
}
Пример #10
0
void ltrim( std::wstring &s )
{
	std::wstring::size_type	pos( s.find_first_not_of( L" \t" ) );
	if( pos == s.npos ) {
		s.clear();
	} else if( pos ) {
		s.erase( 0, pos );
	}
}
Пример #11
0
bool trims(const std::wstring& str, std::vector <std::wstring>& vcResult, char c)
{
    size_t fst = str.find_first_not_of( c );
    size_t lst = str.find_last_not_of( c );

    if( fst != std::wstring::npos )
        vcResult.push_back(str.substr(fst, lst - fst + 1));

    return true;
}
Пример #12
0
void TestUtils::wtrim(std::wstring& str, const wchar_t* szTrim)
{
    std::string::size_type pos = str.find_last_not_of(szTrim);
    if(pos != std::string::npos) {
        str.erase(pos + 1);
        pos = str.find_first_not_of(szTrim);
        if(pos != std::string::npos) str.erase(0, pos);
    }
    else str.erase(str.begin(), str.end());
}
Пример #13
0
/*
** Case insensitive comparison of strings. If equal, strip str2 from str1 and any leading whitespace.
*/
bool CaseInsensitiveCompareN(std::wstring& str1, const std::wstring& str2)
{
	size_t pos = str2.length();
	if (_wcsnicmp(str1.c_str(), str2.c_str(), pos) == 0)
	{
		str1 = str1.substr(pos);  // remove str2 from str1
		str1.erase(0, str1.find_first_not_of(L" \t\r\n"));  // remove any leading whitespace
		return true;
	}

	return false;
}
Пример #14
0
    void skip()
    {
        if (cur_ == token_.length())
            cur_ = std::wstring::npos;

        if (!ret_ && cur_ != std::wstring::npos) {
            std::wstring::size_type tmp = token_.find_first_not_of(delim_, cur_);

            if (tmp != std::wstring::npos)
                cur_ = tmp;
        }
    }
Пример #15
0
static std::list<std::wstring> _TokenizeString(const std::wstring& str, const wchar_t* delims) {
    std::list<std::wstring> components;

    std::size_t start = 0; // start from 0
    std::size_t delimPos = str.find_first_of(delims);

    while (start != std::wstring::npos) {
        components.emplace_back(str.substr(start, delimPos - start));
        start = str.find_first_not_of(delims, delimPos);
        delimPos = str.find_first_of(delims, start);
    }
    return components;
}
// trim whitespace in front and back of string
void trim(std::wstring& value)
{
    const wchar_t* whitespace = L"\n\r\t";
    size_t startpos = value.find_first_not_of(whitespace);
    if (std::wstring::npos != startpos)
    {
        value = value.substr(startpos);
    }

    size_t endpos = value.find_last_not_of(whitespace);
    if (std::wstring::npos != endpos)
    {
        value = value.substr(0, endpos + 1);
    }
}
Пример #17
0
std::wstring Group::VerifyGroup(const std::wstring& str) const
{
	std::wstring strTmp;

	std::wstring::size_type pos = str.find_first_not_of(L" \t\r\n");
	if (pos != std::wstring::npos)
	{
		// Trim white-space
		strTmp.assign(str, pos, str.find_last_not_of(L" \t\r\n") - pos + 1);

		CreateGroup(strTmp);
	}

	return strTmp;
}
Пример #18
0
std::wstring CGroup::CreateGroup(const std::wstring& str)
{
	std::wstring strTmp;

	std::wstring::size_type pos = str.find_first_not_of(L" \t\r\n");
	if (pos != std::wstring::npos)
	{
		// Trim white-space
		strTmp.assign(str, pos, str.find_last_not_of(L" \t\r\n") - pos + 1);

		_wcsupr(&strTmp[0]);
	}

	return strTmp;
}
Пример #19
0
std::vector<std::wstring> StringUtil::tokenize(const std::wstring& str, const std::wstring& delimiters, bool allowEmptyTokenString)
{
	std::vector<std::wstring> tokens;
	std::wstring::size_type delimPos = 0, tokenPos = 0, pos = 0;

	if (str.length() < 1)
		return tokens;

	while (true)
	{
		delimPos = str.find_first_of(delimiters, pos);
		tokenPos = str.find_first_not_of(delimiters, pos);

		if (std::wstring::npos != delimPos)
		{
			if (std::wstring::npos != tokenPos)
			{
				if (tokenPos < delimPos)
				{
					tokens.push_back(str.substr(pos, delimPos - pos));
				}
				else
				{
					if (allowEmptyTokenString)	tokens.push_back(L"");
				}
			}
			else
			{
				if (allowEmptyTokenString) tokens.push_back(L"");
			}
			pos = delimPos + 1;
		}
		else
		{
			if (std::wstring::npos != tokenPos)
			{
				tokens.push_back(str.substr(pos));
			}
			else
			{
				if (allowEmptyTokenString) tokens.push_back(L"");
			}
			break;
		}
	}
	return tokens;
}// tokenize(wstring)
Пример #20
0
    void apply(std::wstring &inflection, std::wstring &field) {
        if (inflection.empty() || inflection.find_first_not_of(L' ') == std::wstring::npos) {
            return;
        }
        auto parts = util::split(inflection, end_delimiter);
        for (auto part : parts) {
            boost::algorithm::trim_left(part);
            if (part.empty()) {
                continue;
            }

            auto start_prefix = m_start_letter + start_delimiter;
            if (part.find_first_of(start_prefix) == std::wstring::size_type(0)) {
                part = part.substr(start_prefix.size());
                auto change_list = util::split(part, middle_delimiter);
                if (change_list.size() != 2) {
                    throw std::logic_error("Cannot apply inflections to the string '" +
                                           boost::locale::conv::from_utf(part, std::locale()) +
                                           "'");
                }
                auto rule = change_list[0];
                auto replacement = change_list[1];
                auto replacement_without_diactitics = removeDiacritics(replacement);
                auto &non_diacritic_field = nonDiacriticField();
                bool non_diacritic = applyStripDiacriticChange();
                if (m_apply_plus_rules && rule == L"(+1)") {
                    field = replacement + field;
                    if (non_diacritic) {
                        non_diacritic_field = replacement_without_diactitics + non_diacritic_field;
                    }
                } else if (m_apply_plus_rules && rule == L"(+2)") {
                    field = field + replacement;
                    if (non_diacritic) {
                        non_diacritic_field = non_diacritic_field + replacement_without_diactitics;
                    }
                } else {
                    boost::algorithm::replace_all(field, rule, replacement);
                    if (non_diacritic) {
                        auto rule_without_diacritics = removeDiacritics(rule);
                        boost::algorithm::replace_all(non_diacritic_field, rule_without_diacritics,
                                                      replacement_without_diactitics);
                    }
                }
            }
        }
    }
Пример #21
0
void RunCommand(std::wstring command)
{
	std::wstring args;

	size_t notwhite = command.find_first_not_of(L" \t\r\n");
	command.erase(0, notwhite);

	size_t quotePos = command.find(L'"');
	if (quotePos == 0)
	{
		size_t quotePos2 = command.find(L'"', quotePos + 1);
		if (quotePos2 != std::wstring::npos)
		{
			args.assign(command, quotePos2 + 1, command.length() - (quotePos2 + 1));
			command.assign(command, quotePos + 1, quotePos2 - quotePos - 1);
		}
		else
		{
			command.erase(0, 1);
		}
	}
	else
	{
		size_t spacePos = command.find(L' ');
		if (spacePos != std::wstring::npos)
		{
			args.assign(command, spacePos + 1, command.length() - (spacePos + 1));
			command.erase(spacePos);
		}
	}

	if (!command.empty())
	{
		RunFile(command.c_str(), args.c_str());
	}
}
bool SimpleConsole::ExecuteCommand(std::wstring command)
{
    // Simple command parsing logic

    if (command == L"quit" ||
        command == L"exit")
    {
        std::wcout << std::endl << "Exiting" << std::endl;
        return false;
    }
    else if (command == L"start")
    {
        std::wcout << std::endl << "Starting soft AP..." << std::endl;
        _hostedNetwork.Start();
        WaitForSingleObjectEx(_apEvent.Get(), INFINITE, FALSE);
    }
    else if (command == L"stop")
    {
        std::wcout << std::endl << "Stopping soft AP..." << std::endl;
        _hostedNetwork.Stop();
        WaitForSingleObjectEx(_apEvent.Get(), INFINITE, FALSE);
    }
    else if (0 == command.compare(0, 4, L"ssid"))
    {
        // Parse the SSID as the first non-space character after ssid
        std::wstring ssid;
        std::wstring::size_type found = command.find_first_not_of(' ', 4);
        if (found != std::wstring::npos && found < command.length())
        {
            ssid = command.substr(found);
            std::wcout << std::endl << "Setting SSID to " << ssid << std::endl;
            _hostedNetwork.SetSSID(ssid);
        }
        else
        {
            std::wcout << std::endl << "Setting SSID FAILED, bad input" << std::endl;
        }
    }
    else if (0 == command.compare(0, 4, L"pass"))
    {
        // Parse the Passphrase as the first non-space character after pass
        std::wstring passphrase;
        std::wstring::size_type found = command.find_first_not_of(' ', 4);
        if (found != std::wstring::npos && found < command.length())
        {
            passphrase = command.substr(found);
            std::wcout << std::endl << "Setting Passphrase to " << passphrase << std::endl;
            _hostedNetwork.SetPassphrase(passphrase);
        }
        else
        {
            std::wcout << std::endl << "Setting Passphrase FAILED, bad input" << std::endl;
        }
    }
    else if (0 == command.compare(0, 10, L"autoaccept"))
    {
        std::wstring value;
        std::wstring::size_type found = command.find_first_not_of(' ', 10);
        if (found != std::wstring::npos && found < command.length())
        {
            value = command.substr(found);

            bool autoAccept = true;

            if (value == L"0")
            {
                autoAccept = false;
            }

            std::wcout << std::endl << "Setting AutoAccept to " << autoAccept << " (input was " << value << ")" << std::endl;
            _hostedNetwork.SetAutoAccept(autoAccept);
        }
        else
        {
            std::wcout << std::endl << "Setting AutoAccpet FAILED, bad input" << std::endl;
        }
    }
    else
    {
        ShowHelp();
    }

    return true;
}
Пример #23
0
std::wstring StringUtilities::TrimLeft(const std::wstring& input) {
    size_t startpos = input.find_first_not_of(WIDE_WHITESPACE);
    return (startpos == std::wstring::npos) ? L"" : input.substr(startpos);
}
Пример #24
0
std::wstring ltrim ( const std::wstring & sourceStr ,const wstring &whitespace)
{
	std::wstring str = sourceStr;
	int position = sourceStr.find_first_not_of (whitespace);
	return str.erase ( 0, position) ;
}
Пример #25
0
static void Trim( std::wstring& str , const std::wstring& chars = L" \t" )
{
    str.erase(str.find_last_not_of(chars)+1);
    str.erase(0, str.find_first_not_of(chars));
}
Пример #26
0
void litehtml::css_element_selector::parse( const std::wstring& txt )
{
	std::wstring::size_type el_end = txt.find_first_of(L".#[:");
	m_tag = txt.substr(0, el_end);
	while(el_end != std::wstring::npos)
	{
		if(txt[el_end] == L'.')
		{
			css_attribute_selector attribute;

			std::wstring::size_type pos = txt.find_first_of(L".#[:", el_end + 1);
			attribute.val		= txt.substr(el_end + 1, pos - el_end - 1);
			attribute.condition	= select_equal;
			m_attrs[L"class"] = attribute;
			el_end = pos;
		} else if(txt[el_end] == L':')
		{
			css_attribute_selector attribute;

			std::wstring::size_type pos = txt.find_first_of(L".#[:", el_end + 1);
			attribute.val		= txt.substr(el_end + 1, pos - el_end - 1);
			attribute.condition	= select_pseudo_class;
			m_attrs[L"pseudo"] = attribute;
			el_end = pos;
		} else if(txt[el_end] == L'#')
		{
			css_attribute_selector attribute;

			std::wstring::size_type pos = txt.find_first_of(L".#[:", el_end + 1);
			attribute.val		= txt.substr(el_end + 1, pos - el_end - 1);
			attribute.condition	= select_equal;
			m_attrs[L"id"] = attribute;
			el_end = pos;
		} else if(txt[el_end] == L'[')
		{
			css_attribute_selector attribute;

			std::wstring::size_type pos = txt.find_first_of(L"]~=|$*^", el_end + 1);
			std::wstring attr = txt.substr(el_end + 1, pos - el_end - 1);
			trim(attr);
			if(pos != std::wstring::npos)
			{
				if(txt[pos] == L']')
				{
					attribute.condition = select_exists;
				} else if(txt[pos] == L'=')
				{
					attribute.condition = select_equal;
					pos++;
				} else if(txt.substr(pos, 2) == L"~=")
				{
					attribute.condition = select_contain_str;
					pos += 2;
				} else if(txt.substr(pos, 2) == L"|=")
				{
					attribute.condition = select_start_str;
					pos += 2;
				} else if(txt.substr(pos, 2) == L"^=")
				{
					attribute.condition = select_start_str;
					pos += 2;
				} else if(txt.substr(pos, 2) == L"$=")
				{
					attribute.condition = select_end_str;
					pos += 2;
				} else if(txt.substr(pos, 2) == L"*=")
				{
					attribute.condition = select_contain_str;
					pos += 2;
				} else
				{
					attribute.condition = select_exists;
					pos += 1;
				}
				pos = txt.find_first_not_of(L" \t", pos);
				if(pos != std::wstring::npos)
				{
					if(txt[pos] == L'"')
					{
						std::wstring::size_type pos2 = txt.find_first_of(L"\"", pos + 1);
						attribute.val = txt.substr(pos + 1, pos2 == std::wstring::npos ? pos2 : (pos2 - pos - 2));
						pos = pos2 == std::wstring::npos ? pos2 : (pos2 + 1);
					} else if(txt[pos] == L']')
					{
						pos ++;
					} else
					{
						std::wstring::size_type pos2 = txt.find_first_of(L"]", pos + 1);
						attribute.val = txt.substr(pos, pos2 == std::wstring::npos ? pos2 : (pos2 - pos));
						pos = pos2 == std::wstring::npos ? pos2 : (pos2 + 1);
					}
				}
			} else
			{
				attribute.condition = select_exists;
			}
			m_attrs[attr] = attribute;
			el_end = pos;
		} else
		{
			el_end++;
		}
		el_end = txt.find_first_of(L".#[:", el_end);
	}
}
Пример #27
0
inline std::wstring trim_left(std::wstring& source) { source.erase(0, source.find_first_not_of(L' ')); return source; }
Пример #28
0
std::wstring sunjwbase::strtrim_left(const std::wstring& s, const std::wstring& spaces)
{
	std::wstring d(s); 
	return d.erase(0, s.find_first_not_of(spaces)); 
}
Пример #29
0
inline std::wstring trim_left( const std::wstring& source, const std::wstring& t = L" \\t")
{
	std::wstring str = source;
	return str.erase(0 , source.find_first_not_of(t) );
}
Пример #30
0
void TrimQuotes(std::wstring &fileName)
{
	fileName.erase(fileName.find_last_not_of(L'\"') + 1);
	fileName.erase(0, fileName.find_first_not_of(L'\"'));
}