bool attribute::is_nmtoken(wstring& s) const { ba::trim(s); bool result = not s.empty(); wstring::iterator c = s.begin(); while (result and ++c != s.end()) result = is_name_char(*c); return result; }
void Windows8LPIAction::_getFirstLanguage(wstring& regvalue) { if (m_languages.size() > 0) { regvalue = m_languages[0]; std::transform(regvalue.begin(), regvalue.end(), regvalue.begin(), ::tolower); return; } regvalue.clear(); return; }
bool iswlower(wstring _String) { for (wstring::const_iterator iter = _String.begin(); iter != _String.end(); iter++) { if (!iswlower(*iter)) { return false; } } return true; }
string WstringToString( const wstring& wstr ) { #ifdef _WIN32 int n = (int)wstr.size(); string str( n+1, '\0' ); WideCharToMultiByte( CP_ACP, 0, wstr.c_str(), -1, (LPSTR)str.data(), n+1, NULL, NULL ); str.resize( n ); return str; #else return string( wstr.begin(), wstr.end() ); #endif }
/// <summary>Calculates the length of a match between item and a string</summary> /// <param name="txt">The text.</param> /// <returns>Length of match in characters</returns> int SuggestionList::SuggestionItem::Match(const wstring& txt) const { int len = 0; // Compare 'n' characters of input + key for (auto t = txt.begin(), k = Key.begin(); t != txt.end() && k != Key.end(); ++t, ++k) if (*t == *k) ++len; // Return count return len; }
void url::parse(const wstring& url_s) { const wstring prot_end(L"://"); wstring::const_iterator prot_i = search(url_s.begin(), url_s.end(), prot_end.begin(), prot_end.end()); protocol_.reserve(distance(url_s.begin(), prot_i)); transform(url_s.begin(), prot_i, back_inserter(protocol_), ptr_fun<int, int>(tolower)); // protocol is icase if (prot_i == url_s.end()) return; advance(prot_i, prot_end.length()); wstring::const_iterator path_i = find(prot_i, url_s.end(), '/'); host_.reserve(distance(prot_i, path_i)); std::copy(prot_i, path_i, back_inserter(host_)); auto found = host_.find_first_of(L'@'); if (found != std::string::npos) { auto creds = host_.substr(0, found); auto found2 = creds.find_first_of(L':'); if (found2 != std::string::npos) { user_ = creds.substr(0, found2); passw_ = creds.substr(found2+1); } host_ = host_.substr(found+1); } // host is icase wstring::const_iterator query_i = find(path_i, url_s.end(), '?'); path_.assign(path_i, query_i); if (query_i != url_s.end()) ++query_i; query_.assign(query_i, url_s.end()); }
bool DataToken::open(const wstring &filename, DT_MODE mode) { if (active && !close()) return false; O_MODE = mode; string str(filename.begin(), filename.end()); //int openflags = O_WRONLY | O_TRUNC; //if (mode == O_READ) openflags = O_RDONLY; string openflags = (mode == O_WRITE) ? "wb" : "rb"; // fd = ::open(str.c_str(), openflags); fd = ::fopen(str.c_str(), openflags.c_str()); if (!fd) return false; active = true; return true; }
bool attribute::is_names(wstring& s) const { bool result = true; ba::trim(s); if (not s.empty()) { wstring::iterator c = s.begin(); wstring t; while (result and c != s.end()) { result = is_name_start_char(*c); t += *c; ++c; while (result and c != s.end() and is_name_char(*c)) { t += *c; ++c; } if (c == s.end()) break; result = isspace(*c); ++c; t += ' '; while (isspace(*c)) ++c; } swap(s, t); } return result; }
ImgAttr Parser::getImgInfo(wstring content) { ImgAttr img; content.erase(remove(content.begin(), content.end(), '\t'), content.end()); wstring contentInfo = content; const wregex re(L"(<img[^>]*src=['|\"](.*?)['|\"].*?>)", regex::icase); wsmatch results; if (regex_match(contentInfo.cbegin(), contentInfo.cend(), results, re)) { img.src = results[2]; wcout << "img.src = " << img.src << endl; } else { const wregex re2(L"(<img[^>]*data-src=['|\"](.*?)['|\"].*?>)", regex::icase); if (regex_match(contentInfo.cbegin(), contentInfo.cend(), results, re2)) { img.src = results[2]; wcout << "img.src = " << img.src << endl; } } const wregex rew(L"(<img[^>]*width=['|\"](.*?)['|\"].*?>)", regex::icase); if (regex_match(contentInfo.cbegin(), contentInfo.cend(), results, rew)) { img.width = results[2]; wcout << "img.width = " << img.width << endl; } const wregex reh(L"(<img[^>]*height=['|\"](.*?)['|\"].*?>)", regex::icase); if (regex_match(contentInfo.cbegin(), contentInfo.cend(), results, reh)) { img.height = results[2]; wcout << "img.height = " << img.height << endl; } return img; }
void StrUtils::trimright( wstring& s ) { wstring::difference_type dt; wstring::reverse_iterator it; for( it = s.rbegin(); it != s.rend(); it++ ) if( !StrUtils::isspace( *it ) ) break; dt = s.rend() - it; s.erase( s.begin() + dt, s.end() ); }
wstring towuppoer(wstring _String) { wstring _Result; _Result.reserve(_String.length()); for (wstring::const_iterator iter = _String.begin(); iter != _String.end(); iter++) { _Result += towupper(*iter); } return _Result; }
//Delete white spaces from the end and the begining of the string wstring Utils::trim(wstring str) { wstring::iterator it; while ((str.length()>0)&&((*(it=str.begin()))==L' ')) { str.erase(it); } while ((str.length()>0)&&((*(it=(str.end()-1)))==L' ')) { str.erase(it); } return str; }
/* setCurrentState - This method sets this sprite to the newState state and starts its animtion sequence from the beginning. */ void AnimatedSprite::setCurrentState(wstring newState) { string cs(currentState.begin(), currentState.end()); string ns(newState.begin(), newState.end()); if (strcmp(cs.c_str(), ns.c_str()) != 0) { // SET THE ANIMATION STATE currentState = newState; // AND RESET OUR COUNTERS animationCounter = 0; frameIndex = 0; } }
int SpriteManager::calculateTextWidth(wstring text, unsigned int fontId) { float width = 0; wchar_t previousLetter = *(text.begin()); for (std::wstring::iterator it = text.begin(); it != text.end(); ++it) { Glyph g = renderer->getFontManager()->getGlyph(fontId, *it); float kerning = 0; if (it != text.begin() && g.kerning.find(previousLetter) != g.kerning.end()) { kerning = (*(g.kerning.find(previousLetter))).second; } width += kerning; width += g.advanceX; previousLetter = *it; } return width; }
/* Escapes quotes for CSV format used by Meterpreter Extension */ wstring escape(const wstring& s) { wstring res; wstring::const_iterator it = s.begin(); while (it != s.end()) { wchar_t c = *it++; if (c == L'"') { res += L'"'; } res += c; } return res; }
void vmsHttpFlvTrafficAnalyzer::ExtractTitleFromHtml(const vmsHttpTrafficCollector::HttpDialog *pHtmlDlg, wstring &wstrTitle) { wstrTitle = L""; UINT codePage = 0; ExtractCodePageFromHtml (pHtmlDlg, codePage); if (!codePage) codePage = pHtmlDlg->codePage; assert (pHtmlDlg != NULL); if (!pHtmlDlg) return; if (pHtmlDlg->vbResponseBody.empty ()) return; LPCSTR psz = strstrni ((LPCSTR)&pHtmlDlg->vbResponseBody [0], "<title>", pHtmlDlg->vbResponseBody.size ()); if (psz) { psz += 7; LPCSTR pszEnd = (LPCSTR)&pHtmlDlg->vbResponseBody [0] + pHtmlDlg->vbResponseBody.size (); string strTitle; while (psz < pszEnd) { if (*psz != '<') strTitle += *psz++; else break; } if (*psz == '<' && !strTitle.empty ()) { vmsCharsets::DecodeString (strTitle.c_str (), codePage ? codePage : CP_UTF8, wstrTitle); while (wstrTitle.empty () == false && wstrTitle [0] <= ' ') wstrTitle.erase (wstrTitle.begin ()); while (wstrTitle.empty () == false && wstrTitle [wstrTitle.length ()-1] <= ' ') wstrTitle.erase (wstrTitle.end ()-1); for (int i = 0; i < wstrTitle.length (); i++) { if (wstrTitle [i] < ' ') wstrTitle [i] = ' '; if (i && wstrTitle [i] == ' ' && wstrTitle [i-1] == ' ') wstrTitle.erase (wstrTitle.begin () + i--); } } } }
var Install(const wstring &x) { auto_ptr<cmodule_t> r(new cmodule_t); r->rep = dlopen(string(x.begin(),x.end()).c_str(),RTLD_LAZY); if(r->rep) { typedef void(*DllMain)(); DllMain f = (DllMain)dlsym(r->rep,"DllMain"); if(f) f(); return r.release(); } wcerr << L"Install:" << dlerror() << std::endl; return 0; }
/****************************** * Write file ******************************/ bool WriteFile(const wstring &filename, const wstring &output) { string fn(filename.begin(), filename.end()); ofstream out(fn.c_str(), ios_base::out | ios_base::binary); if(out.good()) { const string bytes = UnicodeToBytes(output); out.write(bytes.c_str(), bytes.size()); // close file out.close(); return true; } else { wcerr << L"Unable to write file: " << filename << endl; exit(1); } return false; }
void PrintLogHeader( wstring title ) { const size_t TOTAL_LENGTH = 65; const wchar_t HEADER_CHAR = L'~'; size_t n = ( TOTAL_LENGTH - title.size() - 2 ) / 2; wstring header; header.append( n, HEADER_CHAR ); header += L' '; header.append( title.begin(), title.end() ); header += L' '; header.append( n, HEADER_CHAR ); header.append( TOTAL_LENGTH - header.size(), HEADER_CHAR ); header += L'\n'; wcerr << header; }
bool DoublingPossibleStateFinderRus::evaluateExceptionalTokens( const wstring& currentFeature , vector<wstring>* currentPossibleStates) const { if (currentFeature.size() < 4) { return false; } wstring exceptionalPretendent( currentFeature.begin() + 2, currentFeature.end() - 2); if (fullTagsForExceptionTokens.find(exceptionalPretendent) != fullTagsForExceptionTokens.end()) { *currentPossibleStates = fullTagsForExceptionTokens.find(exceptionalPretendent)->second; return true; } return false; }
BOOL cInjector::RunRemoteProc(DWORD dwPid, wstring wDllName, string procName) { if (!FindInjectedModule(dwPid)) { return false; } HANDLE hThread; HANDLE hProc; HMODULE hMod; LPVOID procAddress; hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid); if (hProc) { std::string s; s.assign(wDllName.begin(), wDllName.end()); PE::ulong procOffset = PE::GetFunctionOffset(s, procName); if (procOffset) { long MODULE_BASE = reinterpret_cast<long>(GetRemoteModuleAddress(dwPid, wDllName)); hThread = CreateRemoteThread(hProc, NULL, NULL, reinterpret_cast<LPTHREAD_START_ROUTINE>((LPVOID)(MODULE_BASE + procOffset)), NULL, NULL, NULL); WaitForSingleObject(hThread, INFINITE); CloseHandle(hProc); CloseHandle(hThread); return true; } else { printf("GetProcAddress() failed with error code %d\n", GetLastError()); } CloseHandle(hProc); } else { printf("OpenProcess() failed with error code %d\n", GetLastError()); } return FALSE; }
/// <summary> /// Sanitizes the input string, escape quoting any symbols we rely on for our delimiters, and returns the sanitized string. /// </summary> /// <param name="s">wstring to be sanitized</param> wstring UnitConverter::Quote(const wstring& s) { wstringstream quotedString(wstringstream::out); //Iterate over the delimiter characters we need to quote wstring::const_iterator cursor = s.begin(); while(cursor != s.end()) { if (quoteConversions.find(*cursor) != quoteConversions.end()) { quotedString << quoteConversions[*cursor]; } else { quotedString << *cursor; } ++cursor; } return quotedString.str(); }
// convert all possible utf16, along with any illegal values string all_utf16to8 (wstring utf16_string) { std::string utf8_string; std::back_insert_iterator<std::basic_string<char> > result = back_inserter(utf8_string); wstring::const_iterator start = utf16_string.begin(); wstring::const_iterator end = utf16_string.end(); //template <typename u16bit_iterator, typename octet_iterator> //octet_iterator all_utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) while (start != end) { uint32_t code_point = utf8::internal::mask16(*start++); // Take care of surrogate pairs first if (utf8::internal::is_lead_surrogate(code_point)) { if (start != end) { uint32_t trail_surrogate = utf8::internal::mask16(*start++); if (utf8::internal::is_trail_surrogate(trail_surrogate)) { code_point = (code_point << 10) + trail_surrogate + utf8::internal::SURROGATE_OFFSET; } else { // there was an error, but keep invalid code_point anyway rather than raise an exception } } else { // there was an error, but keep invalid code_point anyway rather than raise an exception } } // Lone trail surrogate else if (utf8::internal::is_trail_surrogate(code_point)) { // there was an error, but keep invalid code_point anyway rather than raise an exception } try { result = utf8::append(code_point, result); } catch (utf8::invalid_code_point) { // invalid code point so put in unescaped byte values, disregarding endian convention utf8_string += (uint8_t)code_point; utf8_string += (uint8_t)code_point/0x100; } } return utf8_string; }
void CWordMatch::addWord(const wstring& str, int value) { word_map* wordmapptr = &wordmap.next; word_map::iterator wordptr; int count = 1; int strsize = str.size(); // wcout << str << endl; for(wstring::const_iterator it = str.begin(); it != str.end(); ++it, ++count) { // cout << "searct..." << endl; wordptr = wordmapptr->find(*it); if(wordptr != wordmapptr->end()) { // cout << "exists..." << endl; word_pair word = *wordptr; if(count == str.size()) { word.second->value = value; // cout << "set value1: " << value << endl; } nextmap_s* nextmap = word.second; wordmapptr = &nextmap->next; } else { // cout << "new..." << endl; word_pair* word = new word_pair; word->first = *it; nextmap_s* nextwordmap = new nextmap_s; word->second = nextwordmap; if(count == str.size()) { nextwordmap->value = value; // cout << "set value2: " << value << endl; } else { nextwordmap->value = -1; } wordmapptr->insert(*word); wordmapptr = &nextwordmap->next; } } }
void MovablePrefab_Plant::_setThrusterName( const wstring & attribute, const wstring & value ) { if (attribute == name) { if (value == L"no" || value == L"NO" || value == L"") { _MovablePrefab->setThrusterName(""); } else { _MovablePrefab->setThrusterName(string(value.begin(), value.end())); } } else if (attribute == closeNode) { return; } else { wstring tmp(L"MovablePrefab_Plant _setThrusterName: Missing attribute type: "); tmp += attribute; throw My_Exception(tmp); } }
BINLINE void BBuffer::serialize(wstring& str) { if (isWrite) { int32_t n = 0; if (compressInteger) { n = getStringLengthUtf8(str); } else { n = (int32_t)(3 * str.size()); } ensureRemaining(4 + n + 1); serialize(n); int32_t lengthPos = pos - 4; if (str.size() != 0) { int8_t* buf = pBytes->data; int8_t* p = buf + pos; for (wstring::iterator it = str.begin(); it != str.end(); it++) { wchar_t c = (*it); if (c <= 0x7F) { *p++ = (int8_t)c; } else if (c >= 0x80 && c <= 0x07FF) { *p++ = (int8_t)(((c >> 6) & 0x1F) | 0xC0); *p++ = (int8_t)((c & 0x3F) | 0x80); } else { // if (c >= 0x800 && c <= 0xFFFF) { *p++ = (int8_t)(((c >> 12) & 0xF) | 0xE0); *p++ = (int8_t)(((c >> 6) & 0x3F) | 0x80); *p++ = (int8_t)((c & 0x3F) | 0x80); } }
/*************************************************************************** * CheckArrayIndex` * array object helper ***************************************************************************/ bool CArrayObject::CheckArrayIndex( const wstring& str ) { bool b = true; //Should less than 99999 if( str.length() > 5 ) return false; wstring::const_iterator itStrStart = str.begin(); wstring::const_iterator itStrEnd = str.end(); while( itStrStart != itStrEnd ) { if( *itStrStart < '0' || *itStrStart > '9' ) { b = false; break; } itStrStart++; } return b; }
wchar_t GetMostCommonCharacter(wstring str) { Trim(str); std::map<wchar_t, int> frequency; for (auto it = str.begin(); it != str.end(); ++it) { if (IsAlphanumeric(*it)) continue; if (GetCommonCharIndex(*it) == -1) continue; frequency[*it] += 1; } wchar_t most_common_char = L'\0'; for (auto it = frequency.begin(); it != frequency.end(); ++it) { if (most_common_char == L'\0') { most_common_char = it->first; continue; } int character_distance = GetCommonCharIndex(it->first) - GetCommonCharIndex(most_common_char); if (character_distance < 0) { most_common_char = it->first; continue; } float frequency_ratio = static_cast<float>(it->second) / static_cast<float>(frequency[most_common_char]); if (frequency_ratio / character_distance > 0.8f) { most_common_char = it->first; } } return most_common_char; }
/* ----------------------------------------------------------------------- * 関数名 : ws_ftoa * 機能概要: doubleをwstringへ変換 * * どうすればいいのか分からなかったので、まずswprintfで変換してから * 終端の無駄なL'0'を削るという謎処理にしています * ----------------------------------------------------------------------- */ void ws_ftoa(wstring &str, double num) { wchar_t tmpstr[WS_MAXLEN]; #ifndef POSIX swprintf(tmpstr, L"%lf", num); #else swprintf(tmpstr, WS_MAXLEN, L"%lf", num); #endif str = tmpstr; for( ; ; ) { if (str.size() < 4) break; wchar_t lastword = str[str.size() - 1]; if (lastword == L'0') str.erase(str.end() - 1); else { if (lastword == L',') str += L'0'; break; } } }
void Erase(wstring& str1, const wstring& str2, bool case_insensitive) { if (str2.empty() || str1.length() < str2.length()) return; auto it = str1.begin(); do { if (case_insensitive) { it = std::search(it, str1.end(), str2.begin(), str2.end(), &IsCharsEqual); } else { it = std::search(it, str1.end(), str2.begin(), str2.end()); } if (it != str1.end()) str1.erase(it, it + str2.length()); } while (it != str1.end()); }