コード例 #1
0
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);
    }
}
コード例 #2
0
ファイル: imi_context.cpp プロジェクト: iksky/sunpinyin
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;
}
コード例 #3
0
ファイル: launch.cpp プロジェクト: 276361270/appjs
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;
}
コード例 #4
0
ファイル: string.cpp プロジェクト: vjcagay/taiga
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;
}