void CDirectory::SetCurrentDirectory ( const wstring& szDirectoryPath ) { std::string szDirectoryPath_iso ( szDirectoryPath.begin ( ), szDirectoryPath.end ( ) ); szDirectoryPath_iso.assign ( szDirectoryPath.begin ( ), szDirectoryPath.end ( ) ); chdir ( szDirectoryPath_iso.c_str ( ) ); }
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()); }
// See https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter // Some tricky test cases: // "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$001"): "$001" // "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$01"): "a" // "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$10"): "j" // "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$15"): "a5" // "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$20"): "b0" void insertReplacedString(wstring& builder, const wstring& base, const wstring& str, const RegExpMatch& match) { const vector<wstring>& substrings = match.substrings; const wstring& mstr = substrings[0]; for (size_t i = 0; i < str.length(); i++) { if (str[i] == L'$' && str.length() > i + 1) { wchar_t ch = str[++i]; switch (ch) { case L'$': // insert a '$' builder.push_back(ch); break; case L'&': // insert the matched string builder.append(mstr); break; case L'`': // insert the portion preceding the matched string builder.append(base.begin(), base.begin() + match.index); break; case L'\'': // insert the portion following the matched string builder.append(base.begin() + match.index + mstr.length(), base.end()); break; default: if (ch >= L'0' && ch <= L'9') { int expidx = 0; wchar_t ch2 = str.length() > i + 1 ? str[i + 1] : L'\0'; if (ch2 >= L'0' && ch2 <= L'9') { expidx = ch2 - L'0' + 10 * (ch - L'0'); // if expidx overflows, fall back to single-digit if (expidx == 0 || expidx >= (int)substrings.size()) { expidx = ch - L'0'; ch2 = 0; } } else { ch2 = 0; expidx = ch - L'0'; } // substrings.size() is 1 bigger than actual sub matches if (expidx < (int)substrings.size() && expidx > 0) { const wstring& submstr = substrings[expidx]; builder.append(submstr); if (ch2) ++i; break; } } // $ escape fails, output as is builder.push_back(L'$'); builder.push_back(ch); } } else builder.push_back(str[i]); } }
wstring ToLower(wstring in) { in = w_trim(in); int (*pf)(int) = tolower; transform(in.begin(), in.end(), in.begin(), pf); return in; }
/** * Returns a multi-byte representation of a wide-character string. * Flaws: no character set conversions, multiple copy operations. */ inline string toS(const wstring& ws, const wstring& vdefault = L"") { //sprintf(charptr,"%ls",wsdtring.c_str()); string val(ws.begin(), ws.end()); if (val.length() == 0) val.append(vdefault.begin(), vdefault.end()); return val; }
KeyValueFileParser::KeyValueFileParser(const wstring& wstrFilename, bool bStopOnEmptyLine, const wstring& wstrToken, const std::wstring& wstrEndToken) { string strFilename(wstrFilename.begin(), wstrFilename.end()); string strToken(wstrToken.begin(), wstrToken.end()); string strEndToken(wstrEndToken.begin(), wstrEndToken.end()); m_bFileReadable = ParseFile(strFilename, bStopOnEmptyLine, strToken, strEndToken); }
void ToUpper(wstring& str, bool use_locale) { if (use_locale) { std::transform(str.begin(), str.end(), str.begin(), std::bind2nd(std::ptr_fun(&std::toupper<wchar_t>), current_locale)); } else { std::transform(str.begin(), str.end(), str.begin(), towupper); } }
void StrUtils::trimleft(wstring& s ) { wstring::iterator it; for( it = s.begin(); it != s.end(); it++ ) if( !StrUtils::isspace(*it)) break; s.erase( s.begin(), it ); }
wstring trim(wstring str) { wstring::iterator it = str.begin(); while (str.begin() != str.end() && *str.begin() == L' ') str.erase(str.begin()); while (str.begin() != str.end()) { it = str.end() - 1; if (*it != L' ') break; str.erase(it); } return str; }
KeyValueFileParser::KeyValueFileParser(ifstream& fileData, bool bStopOnEmptyLine, const wstring& wstrToken, const wstring& wstrEndToken) { string strToken(wstrToken.begin(), wstrToken.end()); string strEndToken(wstrEndToken.begin(), wstrEndToken.end()); m_bFileReadable = ParseFile(fileData, bStopOnEmptyLine, strToken, strEndToken); }
void IEAcceptLanguagesAction::_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; }
KeyValPair::KeyValPair(const wstring& key, const wstring& value) : strKey(key.begin(), key.end()), wstrKey(key), strValue(value.begin(), value.end()), wstrValue(value) { vwstrValue = Tokenize(value); for (size_t i = 0;i<vwstrValue.size();i++) { vstrValue.push_back(string(vwstrValue[i].begin(), vwstrValue[i].end())); } FillDerivedData(); }
/** * @brief 2つの文字列を小文字として比較する * * @param s1, s2 比較文字列 * * @return s1とs2を辞書式の順序で比較した関係を示す * @retval <0 s1はs2より小さい * @retval =0 s1とs2は等しい * @retval >0 s2はs1より小さい */ int yk51_StringICompW(const wstring &s1, const wstring &s2) { typedef pair<wstring::const_iterator, wstring::const_iterator> pairT; pairT p = mismatch(s1.begin(), s1.end(), s2.begin(), not2(ptr_fun(yk51_CharCompareW))); if(p.first == s1.end()){ if(p.second == s2.end()) return 0; else return -1; } return yk51_CharCompareW(*p.first, *p.second); }
void EraseRight(wstring& str1, const wstring& str2, bool case_insensitive) { if (str1.length() < str2.length()) return; if (case_insensitive) { if (!std::equal(str2.begin(), str2.end(), str1.end() - str2.length(), &IsCharsEqual)) return; } else { if (!std::equal(str2.begin(), str2.end(), str1.end() - str2.length())) return; } str1.resize(str1.length() - str2.length()); }
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; }
void multiValueAttribsStringToMap(const wstring &attribsString, multiValueAttribsMap &attribsMap) { wstring str, key; bool inEscape = false; for (wstring::const_iterator it = attribsString.begin(); it != attribsString.end(); ++it) { if (inEscape) { str.push_back(*it); inEscape = false; } else if (*it == L'\\') { inEscape = true; } else if (*it == L':') { // We're about to move on to the value, so save the key and clear str. key = str; str.clear(); } else if (*it == L',' || *it == L';') { // We're about to move on to a new attribute or another value for the same attribute. // In either case, the current value ends here. // Add this key/value pair to the map. if (!key.empty()) { attribsMap.insert(pair<wstring, wstring>(key, str)); if (*it == L';') { // We're about to move on to a new attribute. key.clear(); } } str.clear(); } else { str.push_back(*it); } } }
string w2c(const wstring& s) { string result; result.reserve(s.length()); for (wstring::const_iterator i = s.begin(); i != s.end(); ++i) { uint32 uc = static_cast<uint16>(*i); if (uc >= 0x0D800 and uc <= 0x0DBFF) { wchar_t ch = static_cast<uint16>(*(i + 1)); if (ch >= 0x0DC00 and ch <= 0x0DFFF) { uc = (uc << 16) | ch; ++i; } } if (uc < 0x080) result += (static_cast<char>(uc)); else if (uc < 0x0800) { char ch[2] = { static_cast<char>(0x0c0 | (uc >> 6)), static_cast<char>(0x080 | (uc & 0x3f)) }; result.append(ch, 2); } else if (uc < 0x00010000)
bool DirUtils::IsDirectory(const wstring& path) { bool result = false; #ifdef WIN32 WCHAR *oldCurrentDir = new WCHAR[MAX_PATH]; // Store old directory GetCurrentDirectory(MAX_PATH, oldCurrentDir); result = (SetCurrentDirectory(path.c_str()) == FALSE ? false : true); // Restore old directory SetCurrentDirectory(oldCurrentDir); delete oldCurrentDir; #else DIR *pdir; string nonUnicodePath(path.begin(), path.end()); pdir = opendir(nonUnicodePath.c_str()); result = (pdir != NULL); if(result) { closedir(pdir); } #endif return result; }
bool FixPath(wstring& path) { // Fix unix paths std::replace( path.begin(), path.end(), L'/', L'\\' ); // Remove double slashes while(true) { size_t p = path.find(L"\\\\"); if (p == string::npos) break; path.replace(p, 2, L"\\"); } // Are we pointing at a real destination? if (DirectoryExists(path)) { if (path[path.length()-1] != L'\\') path += L'\\'; return true; } else if (path.at(path.length() - 1) == L'\\') { // It says its a directory but it's not, must be a file path = path.substr(0, path.length() - 1); } return FileExists(path); }
string IW_CORE_API WStringToString(const wstring& ws) { string temp(ws.begin(), ws.end()); temp.assign(ws.begin(), ws.end()); return temp; };
void DirUtils::getFileList(const wstring& path, vector<wstring>& result) { DIR *directory; struct dirent *directoryEntry; string nonUnicodePath(path.begin(), path.end()); directory = opendir(nonUnicodePath.c_str()); if (directory) { while ((directoryEntry = readdir(directory)) != NULL) { string nonUnicodeEntryName (directoryEntry->d_name); wstring entryName (nonUnicodeEntryName.begin(), nonUnicodeEntryName.end()); wstring fullPath = DirUtils::NormalizePath(path + L"/" + entryName); if(DirUtils::IsDirectory(fullPath)) { if(nonUnicodeEntryName != "." && nonUnicodeEntryName != "..") { DirUtils::getFileList(fullPath, result); } } else { result.push_back(fullPath); } } closedir(directory); } }
// StrcmpNoCase // Perform case-insensitive comparisons of 2 wstrings // Returns -1 (s1 < s2), 0 (s1 == s2), or 1 (s1 > s2) int WONCommon::StrcmpNoCase(const wstring& s1, const wstring& s2) { wstring::const_iterator i1 = s1.begin(); wstring::const_iterator i2 = s2.begin(); while ((i1 != s1.end()) && (i2 != s2.end())) { if (toupper(*i1) != toupper(*i2)) return ((toupper(*i1) < toupper(*i2)) ? -1 : 1); i1++; i2++; } return ((s1.size() == s2.size()) ? 0 : ((s1.size() < s2.size()) ? -1 : 1)); }
// Tries to parse the textual string to find a suitable version indication. wstring ParseVersion(const wstring& text){ wstring::const_iterator begin, end; begin = text.begin(); end = text.end(); for(int i = 0; wregex* re = version_checks[i]; i++) { wsmatch what; while (regex_search(begin, end, what, *re)) { if (what.empty()){ continue; } wssub_match match = what[1]; if (!match.matched) { continue; } return trim_copy(wstring(match.first, match.second)); } } return wstring(); }
string WStringToString(wstring in) { // XXX: Not portable string s(in.begin(), in.end()); s.assign(in.begin(), in.end()); return s; }
Midi Midi::ReadFromFile(const wstring &filename) { #if defined WIN32 fstream file(reinterpret_cast<const wchar_t*>((filename).c_str()), ios::in|ios::binary); #else // TODO: This isn't Unicode! // MACTODO: Test to see if opening a unicode filename works. I bet it doesn't. std::string narrow(filename.begin(), filename.end()); fstream file(narrow.c_str(), ios::in | ios::binary); #endif if (!file.good()) throw MidiError(MidiError_BadFilename); Midi m; try { m = ReadFromStream(file); } catch (const MidiError &e) { // Close our file resource before handing the error up file.close(); throw e; } return m; }
vector<wstring> GetFriendGameRequests(wstring user) { vector<wstring> users; wstring userWs(user.begin(), user.end()); utility::string_t url = L"http://uvm061.dei.isep.ipp.pt:5000/check_game_requests?user="******"status"].to_string(); if (checkIfStatusOk(status)) { users.resize(usersJs[L"users"].size()); int i = 0; for (auto iter = usersJs[L"users"].begin(); iter != usersJs[L"users"].end(); ++iter) { users[i] = iter->second.as_string(); i++; } } else { users.resize(0); } return users; }
void PrefabPlant::_setPrefabName( const wstring & attribute, const wstring & value ) { if (attribute == name) { _prefab->setName(string(value.begin(), value.end())); } }
string EncodeUTF8( const wstring & unicode ) { string utf8; for ( wstring::const_iterator p = unicode.begin(); p != unicode.end(); ++p ) { uint32_t uni; if ( (*p >= 0xD800) && (*p <= 0xDFFF) ) //UTF-16 multibyte { if ( *p >= 0xDC00 ) throw UnicodeException( "Invalid UTF-16 string" ); uni = (*p++ & 0x3FF) << 10; if ( p == unicode.end() ) throw UnicodeException( "Invalid UTF-16 string" ); if ( (*p < 0xDC00) || (*p > 0xDFFF) ) throw UnicodeException( "Invalid UTF-16 string" ); uni |= (*p & 0x3FF); uni += 0x10000; } else uni = *p; //if multibyte, append lead byte if ( uni >= 0x10000 ) utf8 += static_cast< char >( ((uni >> 18) & 0x07) | 0xF0 ); else if ( uni >= 0x800 ) utf8 += static_cast< char >( ((uni >> 12) & 0x0F) | 0xE0 ); else if ( uni >= 0x80 )
void ErasePunctuation(wstring& str, bool keep_trailing) { auto rlast = str.rbegin(); if (keep_trailing) rlast = std::find_if(str.rbegin(), str.rend(), [](wchar_t c) -> bool { return !(c == L'!' || // "Hayate no Gotoku!", "K-ON!"... c == L'+' || // "Needless+" c == L'\''); // "Gintama'" }); auto it = std::remove_if(str.begin(), rlast.base(), [](int c) -> bool { // Control codes, white-space and punctuation characters if (c <= 255 && !isalnum(c)) return true; // Unicode stars, hearts, notes, etc. (0x2000-0x2767) if (c > 8192 && c < 10087) return true; // Valid character return false; }); if (keep_trailing) std::copy(rlast.base(), str.end(), it); str.resize(str.size() - (rlast.base() - it)); }
/// <summary> /// Unsanitizes the sanitized input string, returning it to its original contents before we had quoted it. /// </summary> /// <param name="s">wstring to be unsanitized</param> wstring UnitConverter::Unquote(const wstring& s) { wstringstream quotedSubString(wstringstream::out); wstringstream unquotedString(wstringstream::out); wstring::const_iterator cursor = s.begin(); while(cursor != s.end()) { if(*cursor == LEFTESCAPECHAR) { quotedSubString.str(L""); while (cursor != s.end() && *cursor != RIGHTESCAPECHAR) { quotedSubString << *cursor; ++cursor; } if (cursor == s.end()) { //badly formatted break; } else { quotedSubString << *cursor; unquotedString << unquoteConversions[quotedSubString.str()]; } } else { unquotedString << *cursor; } ++cursor; } return unquotedString.str(); }