Ejemplo n.º 1
0
/*
** GetFromLetras
**
** Download lyrics from Letras.
**
*/
bool CLyrics::GetFromLetras(const std::wstring& artist, const std::wstring& title, std::wstring& data)
{
	bool ret = false;

	std::wstring url = L"http://letras.terra.com.br/winamp.php?musica=" + title;
	url += L"&artista=";
	url += artist;
	data = CInternet::DownloadUrl(url, CP_ACP);
	if (!data.empty())
	{
		std::wstring::size_type pos = data.find(L"\"letra\"");
		pos = data.find(L"<p>", pos);
		if (pos != std::wstring::npos)
		{
			pos += 3;
			data.erase(0, pos);

			pos = data.find(L"</p>");
			data.resize(pos);

			CInternet::DecodeReferences(data);

			while ((pos = data.find(L"<br/>"), pos) != std::wstring::npos)
			{
				data.erase(pos, 5);
			}

			ret = true;
		}
	}

	return ret;
}
Ejemplo n.º 2
0
void MediaBridgeSession::NetStream::doPlay(std::wstring& url,RTMPMediaStream::Listener* listener)
{
	//Log
	Log("-Play stream [%ls]\n",url.c_str());

	//Remove extra data from FMS
	if (url.find(L"*flv:")==0)
		//Erase it
		url.erase(0,5);
	else if (url.find(L"flv:")==0)
		//Erase it
		url.erase(0,4);

	//Check token
	if (!sess->ConsumeOutputToken(url))
	{
		//Send error
		fireOnNetStreamStatus(RTMP::Netstream::Play::StreamNotFound,L"Token invalid");
		//Exit
		return;
	}

	//Send reseted status
	fireOnNetStreamStatus(RTMP::Netstream::Play::Reset,L"Playback reset");
	//Send play status
	fireOnNetStreamStatus(RTMP::Netstream::Play::Start,L"Playback started");

	//Add listener
	AddMediaListener(listener);
	//Attach
	Attach(sess);
}
std::wstring Database::getParameterFromTag(std::wstring temp)
{
    size_t pos;
    const size_t nExist = std::wstring::npos;

    pos = temp.find('"');

    if ( pos != nExist)
    {
       temp.erase(0 , pos+1);
       pos = temp.find(L'"');

       if ( pos != nExist)
       {
            temp.erase(pos);
            return temp;
       }

       else
       {
           std::wcout << L"Fehler 1, getParameterFromTag()" << std::endl;
       }
    }

    else
    {
       std::wcout << L"Fehler 2, getParameterFromTag()" << std::endl;
    }

    return L"";
}
Ejemplo n.º 4
0
	/**
	* Trims the front/back of the string of whitespace
	*/
	static void trim_string(std::wstring& str)
	{
		str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](int ch) {
			return !std::isspace(ch);
		}));
		str.erase(std::find_if(str.rbegin(), str.rend(), [](int ch) {
			return !std::isspace(ch);
		}).base(), str.end());
	}
Ejemplo n.º 5
0
void killQuotes( std::wstring& val )
{
    if ( val[0] == L'"' || val[0] == L'\'' )
    {
        val.erase( 0, 1 );
        if( val[ val.size() - 1 ] == L'"' || val[ val.size() - 1 ] == L'\'' )
            val.erase( val.size() - 1, 1 );
    }
}
Ejemplo n.º 6
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());
}
Ejemplo n.º 7
0
void StringUtil::ltrim(std::wstring& str) {
	if (str.empty())
		return;

	std::wstring::size_type pos = str.find_last_not_of(L" ");
	if (pos != std::wstring::npos)
		str.erase(pos+1);

	pos = str.find_last_not_of(L"\t");
	if (pos != std::wstring::npos)
		str.erase(pos+1);
}
void CtriPOSOpenSSLHMACSampleDlg::ParseUri(std::wstring uri, std::string &scheme, std::string &host, std::string &port, std::string &path, std::string &query)
{
    size_t findIndex = uri.find(L"://", 0);

    if (findIndex != std::string::npos)
    {
        scheme.assign(ToMultiByte(uri.substr(0, findIndex).c_str()));

        findIndex += 3;

        uri.erase(0, findIndex);
    }

    findIndex = uri.find(L"/", 0);

    if (findIndex != std::string::npos)
    {
        host.assign(ToMultiByte(uri.substr(0, findIndex).c_str()));

        uri.erase(0, findIndex);

        if (!host.empty())
        {
            findIndex = host.find(":", 0);

            if (findIndex != std::string::npos)
            {
                port = host.substr(findIndex + 1);

                host.erase(findIndex);
            }
        }
    }

    findIndex = uri.find(L"?", 0);

    if (findIndex == std::string::npos)
    {
        path.assign(ToMultiByte(uri.c_str()));
    }
    else
    {
        path.assign(ToMultiByte(uri.substr(0, findIndex).c_str()));

        findIndex++;

        query.assign(ToMultiByte(uri.substr(findIndex).c_str()));
    }
}
Ejemplo n.º 9
0
void StringUtil::unquote(std::wstring& str) {
	std::wstring::iterator it;
	atrim(str);

	if (str.empty())
		return;

	it = str.begin();
	if ((*it == '\'') || *it == '"')
		str.erase(it);

	it = str.end() - 1;
	if ((*it == '\'') || *it == '"')
		str.erase(it);
}
Ejemplo n.º 10
0
 void deleteBackward()
 {
     if (selectionStart != caretPos) {
         unsigned min = std::min(caretPos, selectionStart);
         unsigned max = std::max(caretPos, selectionStart);
         text.erase(text.begin() + min, text.begin() + max);
         selectionStart = caretPos = min;
     }
     else if (caretPos > 0) {
         unsigned oldCaret = caretPos;
         caretPos -= 1;
         text.erase(text.begin() + caretPos, text.begin() + oldCaret);
         selectionStart = caretPos;
     }
 }
Ejemplo n.º 11
0
bool Cx_TextUtil::RemoveInvalidChars(std::wstring& text, LPCWSTR targets)
{
	std::vector<long> arrIndex;
	long i = GetSize(text);

	while (--i >= 0)
	{
		WCHAR ch = text[i];

		if (targets && IsSpaceChar(ch, targets)
			|| !targets && ((ch >= 0x0001 && ch <= 0x0008)
			|| (ch >= 0x000b && ch <= 0x000c)
			|| (ch >= 0x000e && ch <= 0x001f)
			|| (ch == 0xDBC0)) )
		{
			arrIndex.push_back(i);
		}
	}

	long nCount = GetSize(arrIndex);
	for (i = 0; i < nCount; i++)
	{
		text.erase(arrIndex[i]);
	}

	return nCount > 0;
}
bool MiscUtils::Val2WStr(const _variant_t& var, std::wstring& str)
{
	bool bDone = true;
	switch(var.vt)   
	{
	case VT_BSTR:
	case VT_LPSTR:
	case VT_LPWSTR:
		try
		{
			str.assign((LPCWSTR)(_bstr_t)var);
		}
		catch (...)
		{
			bDone = false;
			AfxTrace(_T("Val2WStr failed\n"));
		}
		break;
	case VT_EMPTY:
		str.erase();
		break;
	default:
		bDone = false;
		break;
	}
	return bDone;
}
Ejemplo n.º 13
0
 void deleteForward()
 {
     if (selectionStart != caretPos) {
         unsigned min = std::min(caretPos, selectionStart);
         unsigned max = std::max(caretPos, selectionStart);
         text.erase(text.begin() + min, text.begin() + max);
         selectionStart = caretPos = min;
     }
     else if (caretPos < text.length()) {
         unsigned oldCaret = caretPos;
         caretPos += 1;
         text.erase(text.begin() + oldCaret, text.begin() + caretPos);
         selectionStart = caretPos = oldCaret;
     }
     
 }
Ejemplo n.º 14
0
void LateSymbolInfo::filterSymbol(Database::Address address, std::wstring &module, std::wstring &procname, std::wstring &sourcefile, unsigned &sourceline)
{
	if (debugSymbols3)
	{
		ULONG moduleindex;
		if (debugSymbols3->GetModuleByOffset(address, 0, &moduleindex, NULL) == S_OK)
			if (debugSymbols3->GetModuleNameStringWide(DEBUG_MODNAME_MODULE, moduleindex, 0, buffer, _countof(buffer), NULL) == S_OK)
				module = buffer;

		if (debugSymbols3->GetNameByOffsetWide(address, buffer, _countof(buffer), NULL, NULL) == S_OK)
		{
			if (module.compare(buffer) != 0)
			{
				procname = buffer;

				// Remove redundant "Module!" prefix
				size_t modlength = module.length();
				if (procname.length() > modlength+1 && module.compare(0, modlength, procname, 0, modlength)==0 && procname[modlength] == '!')
					procname.erase(0, modlength+1);
			}
		}

		ULONG line;
		if (debugSymbols3->GetLineByOffsetWide(address, &line, buffer, _countof(buffer), NULL, NULL) == S_OK)
		{
			sourcefile = buffer;
			sourceline = line;
		}
	}
}
Ejemplo n.º 15
0
bool CSalsitaExtensionHelper::ResourcesDirReadFromRegistry(HKEY hKey, const wchar_t *subKey, const wchar_t *valueName, std::wstring &result)
{
  bool ret = false;
  HKEY hkConfig;

  result.erase();
  if (RegOpenKeyExW(hKey, subKey, 0, KEY_READ, &hkConfig) == ERROR_SUCCESS)
  {
    DWORD valueType, valueLen = 0;
    if (RegQueryValueExW(hkConfig, valueName, NULL, &valueType, NULL, &valueLen) == ERROR_SUCCESS && valueType == REG_SZ)
    {
      BYTE *buf = new BYTE[valueLen];
      if (RegQueryValueExW(hkConfig, valueName, NULL, &valueType, buf, &valueLen) == ERROR_SUCCESS)
      {
        result.assign((const wchar_t *)buf);
        ResourcesDirNormalize(result);
        ret = true;
      }
      delete buf;
    }

    RegCloseKey(hkConfig);
  }

  return ret;
}
Ejemplo n.º 16
0
std::wstring As_Removed_Suffix(std::wstring s) {
    auto it = s.rfind(L".");
    if (it !=  std::wstring::npos) {
        s.erase(it, s.size());
    }
    return s;
}
Ejemplo n.º 17
0
void FileReader::ReadRawWString(std::wstring &theWStr, int theNumChars)
{
	theWStr.erase();
	theWStr.reserve(theNumChars);
	for(int i=0; i<theNumChars; i++)
		theWStr += (wchar_t)ReadShort();
}
Ejemplo n.º 18
0
TStatus GetPath(std::wstring& sPath, TPathType type, TSWBit bit)
{
	TCHAR buf[32000];
	DWORD nSize = GetModuleFileName(NULL, buf, sizeof(buf));
	SW_WINBOOL_RET(nSize > 0);

	sPath = buf;

	if (type == PATH_TYPE_SELF_FOLDER)
	{
		size_t index = sPath.find_last_of(L"\\");
		if (index != std::string::npos)
			sPath.erase(index + 1);
	}
	if (type != PATH_TYPE_SELF_FOLDER)
	{
		size_t index = sPath.rfind(L"64.exe");
		if (index != std::string::npos)
			sPath.erase(index);
		index = sPath.rfind(L".exe");
		if (index != std::string::npos)
			sPath.erase(index);

		if (type == PATH_TYPE_DLL_NAME)
		{
			sPath += L"Hook";
		}

		if (bit == SW_BIT_64)
		{
			sPath += L"64";
		}

		if (type == PATH_TYPE_EXE_NAME)
		{
			sPath += L".exe";
		}
		else
		{
			sPath += L".dll";
		}

	}

	SW_RETURN_SUCCESS;
}
	std::wstring RemoveReturnChar(std::wstring wline)
	{
		// remove '\r'
		if (!wline.empty() && wline[wline.size() - 1] == '\r')
			wline.erase(wline.size() - 1);

		return wline;
	}
Ejemplo n.º 20
0
//Get infomation of service
size_t __stdcall GetServiceInfo()
{
//Get service information
	SC_HANDLE SCM = nullptr, Service = nullptr;
	DWORD nResumeHandle = 0;

	if((SCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == nullptr)
		return EXIT_FAILURE;
 
	Service = OpenService(SCM, LOCALSERVERNAME, SERVICE_ALL_ACCESS);
	if(Service == nullptr)
		return EXIT_FAILURE;

	LPQUERY_SERVICE_CONFIG ServicesInfo = (LPQUERY_SERVICE_CONFIG)LocalAlloc(LPTR, PACKET_MAXSIZE*4); //Max buffer of QueryServiceConfig() is 8KB/8192 Bytes.
	if (ServicesInfo == nullptr)
		return EXIT_FAILURE;

	if (QueryServiceConfig(Service, ServicesInfo, PACKET_MAXSIZE*4, &nResumeHandle) == FALSE)
	{
		LocalFree(ServicesInfo);
		return EXIT_FAILURE;
	}

	Path = ServicesInfo->lpBinaryPathName;
	LocalFree(ServicesInfo);

//Path process
	size_t Index = Path.rfind(_T("\\"));
	static const WCHAR wBackslash[] = _T("\\");
	Path.erase(Index + 1, Path.length());

	for (Index = 0;Index < Path.length();Index++)
	{
		if (Path[Index] == _T('\\'))
		{
			Path.insert(Index, wBackslash);
			Index++;
		}
	}

//Get path of error log file and delete the old one
	ErrorLogPath.append(Path);
	ErrorLogPath.append(_T("Error.log"));
	DeleteFile(ErrorLogPath.c_str());
	Parameter.PrintError = true;

//Winsock initialization
	WSADATA WSAData = {0};
	if (WSAStartup(MAKEWORD(2, 2), &WSAData) != 0 || LOBYTE(WSAData.wVersion) != 2 || HIBYTE(WSAData.wVersion) != 2)
	{
		PrintError(Winsock_Error, _T("Winsock initialization failed"), WSAGetLastError(), NULL);

		WSACleanup();
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 21
0
std::wstring UeiArgsParser::trimTrailingSpaces(std::wstring& aString, const std::wstring& aWhitespaces)
{
    size_t trailingSpace = aString.find_last_not_of(aWhitespaces);
    if (trailingSpace != std::wstring::npos)
    {
        aString.erase(trailingSpace + 1);
    }
    return aString;
}
Ejemplo n.º 22
0
//Get path of program from the main function parameter and Winsock initialization
inline size_t __fastcall FileInit(const PWSTR wPath)
{
/* Get path of program from server information.
//Prepare
	SC_HANDLE SCM = nullptr, Service = nullptr;
	DWORD nResumeHandle = 0;

	if ((SCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == nullptr)
		return EXIT_FAILURE;
 
	Service = OpenService(SCM, LOCAL_SERVICENAME, SERVICE_ALL_ACCESS);
	if (Service == nullptr)
		return EXIT_FAILURE;

	LPQUERY_SERVICE_CONFIG ServicesInfo = (LPQUERY_SERVICE_CONFIG)LocalAlloc(LPTR, QUERY_SERVICE_CONFIG_BUFFER_MAXSIZE);
	if (ServicesInfo == nullptr)
		return EXIT_FAILURE;

	if (QueryServiceConfig(Service, ServicesInfo, QUERY_SERVICE_CONFIG_BUFFER_MAXSIZE, &nResumeHandle) == FALSE)
	{
		LocalFree(ServicesInfo);
		return EXIT_FAILURE;
	}
	Path = ServicesInfo->lpBinaryPathName;
	LocalFree(ServicesInfo);
*/
//Path process.
	Path = wPath;
	Path.erase(Path.rfind(L"\\") + 1U);

	for (size_t Index = 0;Index < Path.length();Index++)
	{
		if (Path[Index] == L'\\')
		{
			Path.insert(Index, L"\\");
			Index++;
		}
	}

//Get path of error log file and delete the old one.
	ErrorLogPath = Path;
	ErrorLogPath.append(L"Error.log");
	DeleteFileW(ErrorLogPath.c_str());
	Parameter.PrintError = true;

//Winsock initialization
	WSADATA WSAInitialization = {0};
	if (WSAStartup(MAKEWORD(2, 2), &WSAInitialization) != 0 || LOBYTE(WSAInitialization.wVersion) != 2 || HIBYTE(WSAInitialization.wVersion) != 2)
	{
		PrintError(WINSOCK_ERROR, L"Winsock initialization error", WSAGetLastError(), nullptr, NULL);

		WSACleanup();
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 23
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 );
	}
}
Ejemplo n.º 24
0
std::wstring As_First_N_Chars_Removed(std::wstring str, unsigned int const& number_of_times){
    for (unsigned int i = 0; i < number_of_times; ++i){
        if (!str.empty()){
            str.erase(0,1);
        }else{
            return str;
        }
    }
    return str;
}
Ejemplo n.º 25
0
bool CWIN32Util::RemoveExtraLongPathPrefix(std::wstring& path)
{
  const wchar_t* const str = path.c_str();
  if (path.length() >= 4 && str[0] == L'\\' && str[1] == L'\\' && str[3] == L'\\' && str[2] == L'?')
  {
    path.erase(0, 4);
    return true;
  }
  return false;
}
Ejemplo n.º 26
0
void text::replace(std::wstring &str, const std::wstring &find, const std::wstring &replace)
{
    std::wstring::size_type pos=0;
    while((pos=str.find(find, pos))!=std::wstring::npos)
    {
        str.erase(pos, find.length());
        str.insert(pos, replace);
        pos+=replace.length();
    }
}
Ejemplo n.º 27
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;
}
Ejemplo n.º 28
0
void Mouse::ReplaceMouseVariables(std::wstring& result) const
{
	// Check for new-style variables: [$MOUSEX]
	m_Skin->GetParser().ParseVariables(result, ConfigParser::VariableType::Mouse, m_Meter);

	// Check for old-style variables: $MOUSEX$
	size_t start = 0, end;
	bool loop = true;

	do
	{
		start = result.find(L'$', start);
		if (start != std::wstring::npos)
		{
			size_t si = start + 1;
			end = result.find(L'$', si);
			if (end != std::wstring::npos)
			{
				size_t ei = end - 1;
				if (si != ei && result[si] == L'*' && result[ei] == L'*')
				{
					result.erase(ei, 1);
					result.erase(si, 1);
					start = ei;
				}
				else
				{
					std::wstring strVariable = result.substr(si, end - si);
					std::wstring value = m_Skin->GetParser().GetMouseVariable(strVariable, m_Meter);
					if (!value.empty())
					{
						// Variable found, replace it with the value
						result.replace(start, end - start + 1, value);
						start += value.length();
					}
					else
					{
						start = end;
					}
				}
			}
			else
			{
				loop = false;
			}
		}
		else
		{
			loop = false;
		}
	}
	while (loop);
}
Ejemplo n.º 29
0
bool Cx_TextUtil::TrimSpace(std::wstring& text, LPCWSTR targets)
{
	const int nOldLen = GetSize(text);
	int i = nOldLen;
	while (--i >= 0 && IsSpaceChar(text[i], targets)) {}

	if (i + 1 < nOldLen)
	{
		text.erase(text.begin() + (i + 1), text.end());
	}

	int n = GetSize(text);
	for (i = 0; i < n && IsSpaceChar(text[i], targets); i++) {}

	if (i > 0)
	{
		text.erase(text.begin(), text.begin() + i);
	}

	return nOldLen > GetSize(text);
}
std::wstring Database::getValueFromTag(std::wstring temp)
{
    size_t pos;
    const size_t nExist = std::wstring::npos;

    pos = temp.find('>');

    if( pos != nExist)
    {
        temp.erase(0, pos+1);
    }

    pos = temp.find('<');

    if( pos != nExist)
    {
        temp.erase(pos);
    }

    return temp;
}