void Runtime::Debugger::ProcessArgs(Load* load) { // clear arguments.clear(); arguments.push_back(L"obr"); arguments.push_back(program_file); // parse arguments const wstring temp = load->GetFileName(); wchar_t* buffer = (wchar_t*)calloc(sizeof(wchar_t), temp.size() + 1); wcsncpy(buffer, temp.c_str(), temp.size()); #ifdef WIN32 wchar_t* token = wcstok(buffer, L" "); #else wchar_t *state; wchar_t* token = wcstok(buffer, L" ", &state); #endif while(token) { arguments.push_back(token); #ifdef WIN32 token = wcstok(NULL, L" "); #else token = wcstok(NULL, L" ", &state); #endif } wcout << L"program arguments sets." << endl; // clean up free(buffer); buffer = NULL; }
inline wstring calc( wstring const & s ) const { assert( _bufs.size() ); wstring o; o.reserve( s.size() ); int lastMatch; for( size_t offset = 0; offset < s.size(); ++offset ) { lastMatch = -1; for( size_t i = 0; i < MIN( _maxLength, s.size() - offset ); ++i ) { auto& v = _bufs[ i ][ s[ offset + i ] ]; if( v == 0 ) break; else if( v == 1 ) lastMatch = (int)i; } if( lastMatch == -1 ) { o.push_back( s[ offset ] ); } else { o.append( lastMatch + 1, '*' ); offset += lastMatch; // for will + 1 } } return o; }
UInt32 Archive::find_dir(const wstring& path) { if (file_list.empty()) make_index(); ArcFileInfo dir_info; dir_info.is_dir = true; dir_info.parent = c_root_index; size_t begin_pos = 0; while (begin_pos < path.size()) { size_t end_pos = begin_pos; while (end_pos < path.size() && !is_slash(path[end_pos])) end_pos++; if (end_pos != begin_pos) { dir_info.name.assign(path.data() + begin_pos, end_pos - begin_pos); FileIndexRange fi_range = equal_range(file_list_index.begin(), file_list_index.end(), -1, [&] (UInt32 left, UInt32 right) -> bool { const ArcFileInfo& fi_left = left == -1 ? dir_info : file_list[left]; const ArcFileInfo& fi_right = right == -1 ? dir_info : file_list[right]; return fi_left < fi_right; }); if (fi_range.first == fi_range.second) FAIL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)); dir_info.parent = *fi_range.first; } begin_pos = end_pos + 1; } return dir_info.parent; }
vector<IFilter*> IncludeFilterFactory::createFilter(const wstring& configPath, wstring& command, wstring& parameters) { if (command == L"Include") { wstring value = parameters; while (value.length() > 0 && iswspace(value[0])) value = value.substr(1); wstring includePath; if (PathIsRelativeW(value.c_str())) { wchar_t filePath[MAX_PATH]; configPath._Copy_s(filePath, sizeof(filePath) / sizeof(wchar_t), MAX_PATH); if (configPath.size() < MAX_PATH) filePath[configPath.size()] = L'\0'; else filePath[MAX_PATH - 1] = L'\0'; PathRemoveFileSpecW(filePath); PathAppendW(filePath, value.c_str()); includePath = filePath; } else includePath = value; engine->loadConfigFile(includePath); command = L""; } return vector<IFilter*>(); }
void locate_path_root(const wstring& path, size_t& path_root_len, bool& is_unc_path) { unsigned prefix_len = 0; is_unc_path = false; if (substr_match(path, 0, L"\\\\")) { if (substr_match(path, 2, L"?\\UNC\\")) { prefix_len = 8; is_unc_path = true; } else if (substr_match(path, 2, L"?\\") || substr_match(path, 2, L".\\")) { prefix_len = 4; } else { prefix_len = 2; is_unc_path = true; } } if ((prefix_len == 0) && !substr_match(path, 1, L":")) { path_root_len = 0; } else { wstring::size_type p = path.find(L'\\', prefix_len); if (p == wstring::npos) { p = path.size(); } if (is_unc_path) { p = path.find(L'\\', p + 1); if (p == wstring::npos) { p = path.size(); } } path_root_len = p; } }
wstring TokenizerRus::alignSentence(const wstring& sentence) const { wstring alginedSentence = L""; bool shouldMakeSpace = false; for (size_t letterIndex = 0; letterIndex < sentence.size(); ++letterIndex) { if (sentence[letterIndex] == L' ') { shouldMakeSpace = true; } else if (Tools::IsPunctuation(sentence[letterIndex])) { if ((sentence[letterIndex] != L',' && sentence[letterIndex] != L'.' && sentence[letterIndex] != L'-' && sentence[letterIndex] != L':') || letterIndex == 0 || letterIndex + 1 >= sentence.size() || // Working with numbers: 12,6 !std::iswdigit(sentence[letterIndex - 1]) || !std::iswdigit(sentence[letterIndex + 1])) { shouldMakeSpace = shouldMakeSpace || (sentence[letterIndex] != L'-'); } alginedSentence += sentence[letterIndex]; } else if (std::iswdigit(sentence[letterIndex]) && // Deal with 2% letterIndex + 1 < sentence.size() && sentence[letterIndex + 1] == L'%') { shouldMakeSpace = true; alginedSentence += sentence[letterIndex]; } else { if (shouldMakeSpace) { alginedSentence += L" "; } alginedSentence += sentence[letterIndex]; shouldMakeSpace = false; } } return alginedSentence; }
vector<int> get_classes(wstring s) { wstring b_string = L"b"; wstring s_string = L"s"; vector<int> w(classes_list.size()); for (int k=0; k<s.size(); k++) { bool b = false; for (int i=0; not b and i<classes_list.size(); i++) { for (int j=0; not b and j<classes_list[i].size(); j++) { if (classes_list[i][j].size() == 1) { if (s[k] == classes_list[i][j][0]) { w[i]++; if (s[k] == b_string[0]) w[8]++; //to update [b,d] at the time I update [b,v] if (s[k] == s_string[0]) w[5]++; //to update [r,s,l] at the time I update [s,z,ce,ci,x] b = true; } } else { if (k<s.size()-1 and s[k] == classes_list[i][j][0] and s[k+1] == classes_list[i][j][1]) { w[i]++; b = true; } } } } } return w; }
wstring word_wrap(const wstring& str, wstring::size_type wrap_bound) { wstring result; wstring::size_type begin_pos = 0; while (begin_pos < str.size()) { wstring::size_type end_pos = begin_pos + wrap_bound; if (end_pos < str.size()) { for (wstring::size_type i = end_pos; i > begin_pos; i--) { if (str[i - 1] == L' ') { end_pos = i; break; } } } else { end_pos = str.size(); } wstring::size_type trim_pos = end_pos; while (trim_pos > begin_pos && str[trim_pos - 1] == L' ') trim_pos--; if (trim_pos > begin_pos) { if (!result.empty()) result.append(1, L'\n'); result.append(str.data() + begin_pos, trim_pos - begin_pos); } begin_pos = end_pos; } return result; }
string Gosu::wstringToUTF8(const wstring& ws) { unsigned size = WideCharToMultiByte(CP_UTF8, 0, ws.c_str(), ws.size(), 0, 0, 0, 0); vector<char> buffer(size + 1); WideCharToMultiByte(CP_UTF8, 0, ws.c_str(), ws.size(), &buffer[0], buffer.size(), 0, 0); return &buffer[0]; }
bool has_accent(wstring s) { for (int i=0; i<s.size(); i++) for (int j=5; j<vowels_list.size(); j++) if (s[i] == vowels_list[j]) return true; return false; }
string toUtf8String(const wstring& wide) { if (wide.size() > boost::integer_traits<int>::const_max) throw length_error( "Wide string cannot be more than INT_MAX characters long."); if (wide.size() == 0) return ""; // Calculate necessary buffer size int len = ::WideCharToMultiByte( CP_UTF8, 0, wide.c_str(), static_cast<int>(wide.size()), NULL, 0, NULL, NULL); // Perform actual conversion if (len > 0) { vector<char> buffer(len); len = ::WideCharToMultiByte( CP_UTF8, 0, wide.c_str(), static_cast<int>(wide.size()), &buffer[0], static_cast<int>(buffer.size()), NULL, NULL); if (len > 0) { assert(len == static_cast<int>(buffer.size())); return string(&buffer[0], buffer.size()); } } throw boost::system::system_error( ::GetLastError(), boost::system::system_category()); }
void unhex(const wstring& str, Buffer<unsigned char>& buf) { buf.resize(str.size() / 2); for (unsigned i = 0; i < str.size(); i += 2) { unsigned char b = (unhex(str[i]) << 4) | unhex(str[i + 1]); buf.data()[i / 2] = b; } }
wstring AddComma(const wstring& source) { PWCHAR pBuf = (PWCHAR)malloc(source.size() * 4); if (pBuf == NULL) { return L""; } size_t len, i, j; for (len = source.size(), i = 0, j = 0; i < len; i++, j++) { if (!((len - i) % 3) && i != 0) { if (j > 0 && pBuf[j - 1] != L'-') { pBuf[j++] = L','; } } pBuf[j] = source[i]; } pBuf[j] = 0; wstring s(pBuf); free(pBuf); return s; }
/*! sakura.iniの1行を処理する. 1行の読み込みが完了するごとに呼ばれる. @param line [in] 読み込んだ行 */ void CProfile::ReadOneline( const wstring& line ) { // 空行を読み飛ばす if( line.empty() ) return; //コメント行を読みとばす if( 0 == line.compare( 0, 2, LTEXT("//") )) return; // セクション取得 // Jan. 29, 2004 genta compare使用 if( line.compare( 0, 1, LTEXT("[") ) == 0 && line.find( LTEXT("=") ) == line.npos && line.find( LTEXT("]") ) == ( line.size() - 1 ) ) { Section Buffer; Buffer.strSectionName = line.substr( 1, line.size() - 1 - 1 ); m_ProfileData.push_back( Buffer ); } // エントリ取得 else if( !m_ProfileData.empty() ) { //最初のセクション以前の行のエントリは無視 wstring::size_type idx = line.find( LTEXT("=") ); if( line.npos != idx ) { m_ProfileData.back().mapEntries.insert( PAIR_STR_STR( line.substr(0,idx), line.substr(idx+1) ) ); } } }
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParamarg, int cmdShow) { openLog(); #ifdef _NEED_WIN_GENERATE_DUMP _oldWndExceptionFilter = SetUnhandledExceptionFilter(_exceptionFilter); #endif writeLog(L"Updaters started.."); LPWSTR *args; int argsCount; bool needupdate = false, autostart = false, debug = false; args = CommandLineToArgvW(GetCommandLine(), &argsCount); if (args) { for (int i = 1; i < argsCount; ++i) { if (equal(args[i], L"-update")) { needupdate = true; } else if (equal(args[i], L"-autostart")) { autostart = true; } else if (equal(args[i], L"-debug")) { debug = _debug = true; openLog(); } } if (needupdate) writeLog(L"Need to update!"); if (autostart) writeLog(L"From autostart!"); exeName = args[0]; writeLog(L"Exe name is: " + exeName); if (exeName.size() > 11) { if (equal(exeName.substr(exeName.size() - 11), L"Updater.exe")) { exeDir = exeName.substr(0, exeName.size() - 11); writeLog(L"Exe dir is: " + exeDir); if (needupdate && update()) { updateRegistry(); } } else { writeLog(L"Error: bad exe name!"); } } else { writeLog(L"Error: short exe name!"); } LocalFree(args); } else { writeLog(L"Error: No command line arguments!"); } wstring targs = L"-noupdate"; if (autostart) targs += L" -autostart"; if (debug) targs += L" -debug"; ShellExecute(0, 0, (exeDir + L"Telegram.exe").c_str(), targs.c_str(), 0, SW_SHOWNORMAL); writeLog(L"Executed Telegram.exe, closing log and quiting.."); closeLog(); return 0; }
wstring del_trailing_slash(const wstring& path) { if ((path.size() < 2) || (path[path.size() - 1] != L'\\')) { return path; } else { return path.substr(0, path.size() - 1); } }
wstring add_trailing_slash(const wstring& path) { if ((path.size() == 0) || (path[path.size() - 1] == L'\\')) { return path; } else { return path + L'\\'; } }
void PrintStatisticsCaption( wstring& caption ) { const size_t PADDING_SIZE = 15; assert( PADDING_SIZE >= caption.size() ); wstring padding( PADDING_SIZE - caption.size(), L' ' ); wcout << caption << L":" << padding; }
wstring fit_str(const wstring& str, wstring::size_type size) { if (str.size() <= size) return str; if (size <= 3) return str.substr(0, size); size -= 3; // place for ... return wstring(str).replace(size / 2, str.size() - size, L"..."); }
string IceUtil::wstringToString(const wstring& v, const StringConverterPtr& converter, const WstringConverterPtr& wConverter, IceUtil::ConversionFlags flags) { string target; if(!v.empty()) { // // First convert to UTF8 narrow string. // if(wConverter) { UTF8BufferI buffer; Byte* last = wConverter->toUTF8(v.data(), v.data() + v.size(), buffer); target = string(reinterpret_cast<const char*>(buffer.getBuffer()), last - buffer.getBuffer()); } else { size_t size = v.size() * 4 * sizeof(char); Byte* outBuf = new Byte[size]; Byte* targetStart = outBuf; Byte* targetEnd = outBuf + size; const wchar_t* sourceStart = v.data(); ConversionResult cr = convertUTFWstringToUTF8( sourceStart, sourceStart + v.size(), targetStart, targetEnd, flags); if(cr != conversionOK) { delete[] outBuf; assert(cr == sourceExhausted || cr == sourceIllegal); throw IllegalConversionException(__FILE__, __LINE__, cr == sourceExhausted ? "partial character" : "bad encoding"); } target = string(reinterpret_cast<char*>(outBuf), static_cast<size_t>(targetStart - outBuf)); delete[] outBuf; } // // If narrow string converter is present convert to the native narrow string encoding, otherwise // native narrow string encoding is UTF8 and we are done. // if(converter) { string tmp; converter->fromUTF8(reinterpret_cast<const Byte*>(target.data()), reinterpret_cast<const Byte*>(target.data() + target.size()), tmp); tmp.swap(target); } } return target; }
bool ends_with(const wstring &a, const wstring &b) { if (a.size() < b.size()) return false; for (int i = 0, bb = b.size() - 1, aa = a.size() - 1; i < b.size(); ++i) { if (b[bb] != a[aa]) return false; bb--; aa--; } return true; }
bool fill_result(input_context& ic, const wstring& wstr_result) { HIMCC hMem; LPCOMPOSITIONSTRING lpCompStr; DWORD dwSize; dwSize = sizeof(COMPOSITIONSTRING) + (wstr_result.size() + 1) * sizeof(WORD); if (!ic->hCompStr) { ic->hCompStr = ImmCreateIMCC(dwSize); if (!ic->hCompStr) { return false; } lpCompStr = (LPCOMPOSITIONSTRING) ImmLockIMCC(ic->hCompStr); if (!lpCompStr) { return false; } lpCompStr->dwSize = dwSize; ImmUnlockIMCC(ic->hCompStr); } lpCompStr = (LPCOMPOSITIONSTRING) ImmLockIMCC(ic->hCompStr); if (!lpCompStr) { return false; } if (dwSize > lpCompStr->dwSize) { ImmUnlockIMCC(ic->hCompStr); hMem = ImmReSizeIMCC(ic->hCompStr, dwSize); if (!hMem) { return false; } if (ic->hCompStr != hMem) { ImmDestroyIMCC(ic->hCompStr); ic->hCompStr = hMem; } lpCompStr = (LPCOMPOSITIONSTRING) ImmLockIMCC(ic->hCompStr); if (!lpCompStr) { return false; } lpCompStr->dwSize = dwSize; } dwSize = lpCompStr->dwSize; //save it memset(lpCompStr, 0, dwSize); lpCompStr->dwSize = dwSize; lpCompStr->dwResultStrLen = wstr_result.size(); lpCompStr->dwResultStrOffset = sizeof(COMPOSITIONSTRING); memcpy((char *)lpCompStr+sizeof(COMPOSITIONSTRING), wstr_result.c_str(), wstr_result.size() * sizeof(wchar_t)); ImmUnlockIMCC(ic->hCompStr); return true; }
void TransferRule::remove_final_asterisk(wstring &tags) { wchar_t c; if(tags.size() >= 2) { if(tags[tags.size()-1]==L'*' && tags[tags.size()-2]==L'.') tags=tags.substr(0,tags.size()-2); } }
wstring center(const wstring& str, unsigned width) { if (str.size() >= width) return str; size_t lpad = (width - str.size()) / 2; size_t rpad = width - str.size() - lpad; wstring result(lpad, L' '); result.append(str); result.append(rpad, L' '); return result; }
void string_replace( wstring& strBig, const wstring& strSrc, const wstring& strDst ) { wstring::size_type pos=0; wstring::size_type srclen = strSrc.size(); wstring::size_type dstlen = strDst.size(); while( (pos=strBig.find(strSrc, pos)) != wstring::npos) { strBig.replace(pos, srclen, strDst); pos += dstlen; } }
EncodingType getEncodingType( wstring& text ) { // UTF8 if (text.size() >= 3 && text[0] == (wchar_t)0xEF && text[1] == (wchar_t)0xBB && text[2] == (wchar_t)0xBF) { text.erase(0, 3); return(UTF8); } // UTF32_BigEndian if (text.size() >= 4 && text[0] == (wchar_t)0x00 && text[1] == (wchar_t)0x00 && text[2] == (wchar_t)0xFE && text[3] == (wchar_t)0xFF) { text.erase(0, 4); return(UTF32_BigEndian); } // UTF32_LittleEndian if (text.size() >= 4 && text[0] == (wchar_t)0xFF && text[1] == (wchar_t)0xFE && text[2] == (wchar_t)0x00 && text[3] == (wchar_t)0x00) { text.erase(0, 4); return(UTF32_LittleEndian); } // UTF16_BigEndian if (text.size() >= 2 && text[0] == (wchar_t)0xFE && text[1] == (wchar_t)0xFF) { text.erase(0, 2); return(UTF16_BigEndian); } // UTF16_LittleEndian if (text.size() >= 2 && text[0] == (wchar_t)0xFF && text[1] == (wchar_t)0xFE) { text.erase(0, 2); return(UTF16_LittleEndian); } return(ANSI); }
unsigned Dialog::get_label_len(const wstring& str, FARDIALOGITEMFLAGS flags) { if (flags & DIF_SHOWAMPERSAND) return str.size(); else { unsigned cnt = 0; for (unsigned i = 0; i < str.size(); i++) { if (str[i] != '&') cnt++; } return cnt; } }
/* ----------------------------------------------------------------------- * 関数名 : ws_replace * 機能概要: str内のbeforeをすべてafterに置換します * ----------------------------------------------------------------------- */ void ws_replace(wstring &str, const wstring &before, const wstring &after) { int sz_bef = before.size(); int sz_aft = after.size(); for(int rp_pos = 0; ; rp_pos += sz_aft) { rp_pos = str.find(before, rp_pos); if (rp_pos == -1) break; str.replace(rp_pos, sz_bef, after); } }
int num_vowels(wstring s) { int nvowels = 0; for (int i=0; i<s.size(); i++) for (int j=0; j<vowels_list.size(); j++) if (s[i] == vowels_list[j]) { nvowels++; break; } return nvowels; }
bool Dictionary::isDate(const wstring & word) { if (_special[word[word.size() - 1]] != DATE) return false; for (int i = 0; i < word.size() - 1; ++i) if (_special[word[i]] != NUM) return false; return true; }