void StringUtilities::ReplaceAll(wstring &str, const wstring &search, const wstring &replace)
{
    for (size_t pos = 0;; pos += replace.length() - 1)
    {
        pos = str.find(search, pos);
        if (pos == string::npos) break;

        str.erase(pos, search.length());
        str.insert(pos, replace);
    }
}
Beispiel #2
0
unsigned CIMIContext::getBestSentence (wstring& result, unsigned start, unsigned end)
{
    result.clear();

    if (UINT_MAX == end) end = m_tailIdx - 1;

    while (end > start && m_lattice[end].m_bwType == CLatticeFrame::NO_BESTWORD)
        end --;

    unsigned i = end, nWordConverted = 0;
    while (i > start) {
        CLatticeFrame &fr = m_lattice[i];
        result.insert (0, fr.m_bestWord.m_cwstr);
        i = fr.m_bestWord.m_start;
        nWordConverted ++;
    }

    return nWordConverted;
}
Beispiel #3
0
size_t Launch(wstring exe, wstring params) {
  if (params.size() != 0 && params[0] != L' ') {
    params.insert(0, L" ");
  }
  
  size_t ret = 0, lastSlash = 0;
  DWORD exitCode = 0;
  wstring temp = L"";

  wchar_t* paramCopy = new wchar_t[params.size() + 1];
  if (paramCopy == 0)
    return 1;

  const wchar_t* transfer = params.c_str();
  wcscpy_s(paramCopy, params.size() + 1, transfer);

  STARTUPINFOW startup;
  PROCESS_INFORMATION process;
  memset(&startup, 0, sizeof(startup));
  memset(&process, 0, sizeof(process));
  startup.cb = sizeof(startup);


  if (CreateProcessW(const_cast<LPCWSTR>(exe.c_str()), paramCopy, 0, 0, false,
	                 CREATE_NO_WINDOW, 0, 0, &startup, &process) != false) {
    exitCode = WaitForSingleObject(process.hProcess, 1000);
  } else {
    ret = GetLastError();
  }
  
  delete[]paramCopy;
  paramCopy = 0;
  CloseHandle(process.hProcess);
  CloseHandle(process.hThread);
  return ret;
}
Beispiel #4
0
wstring PadChar(wstring str, const wchar_t ch, const size_t len) {
  if (len > str.length())
    str.insert(0, len - str.length(), ch);

  return str;
}