BEGIN_INANITY std::string Strings::Unicode2UTF8(const std::wstring& str) { std::string res; utf8::unchecked::utf16to8(str.begin(), str.end(), std::back_inserter(res)); return res; }
template <> inline std::string encode< char, wchar_t >( const std::wstring& source ) { std::string result; result.resize( source.length() ); std::transform(source.begin(), source.end(), result.begin(), detail::narrow()); return result; }
BigArray<T>::BigArray(std::wstring fileName, unsigned long r, unsigned long c) { std::string fName = std::string(fileName.begin(), fileName.end()); init(fName, r, c); MPI_Barrier(MPI_COMM_WORLD); }
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); }
LargeRAWFile::LargeRAWFile(const std::wstring& wstrFilename, uint64_t iHeaderSize): m_bIsOpen(false), m_bWritable(false), m_iHeaderSize(iHeaderSize) { string strFilename(wstrFilename.begin(), wstrFilename.end()); m_strFilename = strFilename; }
void CSalsitaExtensionHelper::ResourcesDirMakeUrl(const wchar_t *resourcesDir, const wchar_t *relativeUrl, std::wstring &pageUrl) { pageUrl.assign(L"file:///"); pageUrl.append(resourcesDir); ResourcesDirNormalize(pageUrl); pageUrl.append(relativeUrl); std::replace(pageUrl.begin(), pageUrl.end(), L'\\', L'/'); }
BigArray<T>::BigArray(std::wstring fileName, const gMat2D<T>& mat) { std::string fName = std::string(fileName.begin(), fileName.end()); init(fName, mat.rows(), mat.cols()); MPI_Barrier(MPI_COMM_WORLD); }
bool copy_string(const ComponentBaseImpl& comp, const std::wstring& str, WCHAR_T** out) { if (*out = comp.alloc<WCHAR_T[]>(size_t(str.size() + 1))) { std::copy(str.begin(), str.end(), *out); return true; } return false; }
void IfcPPReaderSTEP::loadModelFromFile( const std::wstring& file_path, shared_ptr<IfcPPModel>& target_model ) { // if file content needs to be loaded into a plain model, call resetModel() before loadModelFromFile std::wstring ext = file_path.substr( file_path.find_last_of( L"." ) + 1 ); if( boost::iequals( ext, "ifc" ) ) { // ok, nothing to do here } else if( boost::iequals( ext, "ifcXML" ) ) { // TODO: implement xml reader messageCallback( "ifcXML not yet implemented", StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ ); return; } else if( boost::iequals( ext, "ifcZIP" ) ) { // TODO: implement zip uncompress messageCallback( "ifcZIP not yet implemented", StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ ); return; } else { std::wstringstream strs; strs << "Unsupported file type: " << ext; messageCallback( strs.str().c_str(), StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ ); return; } // open file #ifdef _MSC_VER std::ifstream infile(file_path.c_str(), std::ifstream::in ); #else std::string file_path_str( file_path.begin(), file_path.end() ); std::ifstream infile(file_path_str.c_str(), std::ifstream::in ); #endif if( !infile.is_open() ) { std::wstringstream strs; strs << "Could not open file: " << file_path.c_str(); messageCallback( strs.str().c_str(), StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ ); return; } // get length of file content std::streampos file_size = infile.tellg(); infile.seekg( 0, std::ios::end ); file_size = infile.tellg() - file_size; infile.seekg( 0, std::ios::beg ); // read file content into string std::string buffer( (int)file_size, '\0' ); infile.read( &buffer[0], file_size ); infile.close(); loadModelFromString( buffer, target_model ); }
std::string WideToUTF8(const std::wstring& in) { // TODO: Eventually we want this function to convert from Unicode // characters to UTF-8 characters, but do this for now, just so // that on non-Win32 platforms we can use the same code. std::string result(in.length(), ' '); std::copy(in.begin(), in.end(), result.begin()); return result; }
Failure::Failure( const std::wstring& theCondition, const std::string& theFileName, long theLineNumber) : condition(theCondition.begin(), theCondition.end()), fileName(theFileName), lineNumber(theLineNumber) { }
void DOMElement::setTextContent(const std::wstring & ws) { if(isNull()) return; std::basic_string<XMLCh> xs(ws.begin(), ws.end()); XELEM(m_wrapped)->setTextContent(xs.c_str()); }
ConnectionListener::ConnectionListener(const std::wstring &name, TelldusCore::EventRef waitEvent) { d = new PrivateData; d->waitEvent = waitEvent; d->name = "/tmp/" + std::string(name.begin(), name.end()); d->running = true; this->start(); }
static std::string convert(std::wstring const & w) { std::string s; utf8::utf32to8(w.begin(),w.end(), std::back_inserter(s)); return s; }
std::string StringUtils::wstring_To_Utf8(const std::wstring& widestring) { size_t widesize = widestring.length(); if (sizeof(wchar_t) == 2) { size_t utf8size = 3 * widesize + 1; std::string resultstring; resultstring.resize(utf8size, '\0'); const UTF16* sourcestart = reinterpret_cast<const UTF16*>(widestring.c_str()); const UTF16* sourceend = sourcestart + widesize; UTF8* targetstart = reinterpret_cast<UTF8*>(&resultstring[0]); UTF8* targetend = targetstart + utf8size; ConversionResult res = ConvertUTF16toUTF8(&sourcestart, sourceend, &targetstart, targetend, strictConversion); if (res != conversionOK) { return std::string(widestring.begin(), widestring.end()); } *targetstart = 0; return std::string(resultstring.c_str()); } else if (sizeof(wchar_t) == 4) { size_t utf8size = 4 * widesize + 1; std::string resultstring; resultstring.resize(utf8size, '\0'); const UTF32* sourcestart = reinterpret_cast<const UTF32*>(widestring.c_str()); const UTF32* sourceend = sourcestart + widesize; UTF8* targetstart = reinterpret_cast<UTF8*>(&resultstring[0]); UTF8* targetend = targetstart + utf8size; ConversionResult res = ConvertUTF32toUTF8(&sourcestart, sourceend, &targetstart, targetend, strictConversion); if (res != conversionOK) { return std::string(widestring.begin(), widestring.end()); } *targetstart = 0; return std::string(resultstring.c_str()); } else { assert(false); } return ""; }
template<> void ScriptInterface::ToJSVal<std::wstring>(JSContext* cx, JS::MutableHandleValue ret, const std::wstring& val) { JSAutoRequest rq(cx); utf16string utf16(val.begin(), val.end()); JS::RootedString str(cx, JS_NewUCStringCopyN(cx, reinterpret_cast<const char16_t*> (utf16.c_str()), utf16.length())); if (str) ret.setString(str); else ret.setUndefined(); }
bool isWord(const std::wstring &str) { for (auto i = str.begin(); i != str.end(); ++i) { if (!(std::iswalnum(*i) || *i == L'-')) { return false; } } return true; }
void TestUtils::wtrim(std::wstring& str, const wchar_t* szTrim) { std::string::size_type pos = str.find_last_not_of(szTrim); if(pos != std::string::npos) { str.erase(pos + 1); pos = str.find_first_not_of(szTrim); if(pos != std::string::npos) str.erase(0, pos); } else str.erase(str.begin(), str.end()); }
static bool is_equal_ignore_case (const std::wstring& a, const std::wstring& b) { return a.length () == b.length () && std::equal (a.begin (), a.end (), b.begin (), char_equal_ignore_case ); }
void EvalAtom::CreateVariable(std::wstring& src) { EvalTable::CheckIdentSize(src); /** * Convert wstring representation of identifier to * string representation. No reason to support non * latin characters in math formula. */ Ident = std::string(src.begin(), src.end()); }
inline std::string to_string(const std::wstring &s) { using namespace std; string buffer; copy(s.begin(), s.end(), wctomb_inserter(buffer)); return buffer; }
inline void FileDialog::SetFilter(const std::wstring &filter) { m_filter = filter; std::transform(m_filter.begin(), m_filter.end(), m_filter.begin(), [](wchar_t ch) { if (ch == L'|') { return L'\0'; } else { return ch; } }); }
std::string wstring_to_utf8(const std::wstring& src) { std::string out_str; std::wstring in_str; utf8::replace_invalid(src.begin(), src.end(), std::back_inserter(in_str)); #ifdef _WIN32 utf8::utf16to8(in_str.begin(), in_str.end(), std::back_inserter(out_str)); #else utf8::utf32to8(in_str.begin(), in_str.end(), std::back_inserter(out_str)); #endif return out_str; }
void CSalsitaExtensionHelper::ResourcesDirGetDebugPath(const wchar_t *preprocessorDefinedPath, std::wstring &result) { result.assign(preprocessorDefinedPath); std::replace(result.begin(), result.end(), L'/', L'\\'); std::wstring canonicalized; canonicalized.resize(MAX_PATH+1); PathCanonicalizeW((LPWSTR)canonicalized.c_str(), result.c_str()); result.assign(canonicalized.c_str()); ResourcesDirNormalize(result); }
const std::wstring tolower_and_del_delims(const std::wstring& str, const bool reverse) { std::wstring ret_str; if(reverse) { remove_copy_if(str.rbegin(), str.rend(), std::back_inserter(ret_str), is_delim); } else { remove_copy_if(str.begin(), str.end(), std::back_inserter(ret_str), is_delim); } std::transform(ret_str.begin(), ret_str.end(), ret_str.begin(), std::towlower); return ret_str; }
// Converting wstring to string std::string narrow( const std::wstring& in, std::locale loc /* = std::locale() */ ) { std::string out( in.length(), 0 ); std::wstring::const_iterator i = in.begin(), ie = in.end(); std::string::iterator j = out.begin(); for( ; i!=ie; ++i, ++j ) *j = std::use_facet< std::ctype< wchar_t > > ( loc ).narrow( *i ); return out; }
bool C_CoordinateTransform::LoadTransformationMatrix( std::wstring A_rFileName ) { bool bResult = false; try { std::ifstream oFile; std::string fileN(A_rFileName.begin(), A_rFileName.end()); oFile.open(fileN.c_str(), std::ios::binary); if ( oFile ) { Size_<unsigned int> displayRes; oFile.read((char*)&displayRes.width, sizeof(unsigned int)); oFile.read((char*)&displayRes.height, sizeof(unsigned int)); if ( displayRes == Size_<unsigned int>(0, 0) ) { p->m_oCoordinateTransformationSystemStatus = E_ctssEMPTY; throw false; } p->m_oDisplayResolution = displayRes; Size_<unsigned int> size; oFile.read((char*)&size.width, sizeof(unsigned int)); oFile.read((char*)&size.height, sizeof(unsigned int)); if ( size == Size_<unsigned int>(0, 0) ) { p->m_oCoordinateTransformationSystemStatus = E_ctssEMPTY; throw false; } p->m_oTransformationMatrix = matrix<Point2i>(size); oFile.read( (char*)p->m_oTransformationMatrix.matrix_data.data(), p->m_oTransformationMatrix.matrix_data.size() * sizeof(Point2i) ); p->m_oCoordinateTransformationSystemStatus = E_ctssCALIBRATED; } else { p->m_oCoordinateTransformationSystemStatus = E_ctssEMPTY; throw false; } bResult = true; } catch ( bool bError ) { bResult = bError; } return bResult; }
std::string wstring_to_string(std::wstring const& a) { TRACE("hugh::support::wstring_to_string(std::wstring)"); #if defined(__GLIBCXX__) && (__GLIBCXX__ <= GLIBCXX_NO_CODECVT) return std::string(a.begin(), a.end()); #else return std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>().to_bytes(a); #endif }
void keymagic_driver::AppendString(std::list<int>& container, const std::wstring& str, bool Op_Length) { if (Op_Length) { container.push_back(opSTRING); container.push_back(str.length()); } for (std::wstring::const_iterator si = str.begin(); si != str.end(); si++) { container.push_back(*si); } }
bool ResolveFromCommandLine(std::wstring &path) { if (path.empty()) { return false; } path = Path::ExpandEnvStrings(path); if (path[0] == L'\"') { std::wstring unescaped; unescaped.reserve(path.size()); std::wstring::iterator endOfUnescape = CmdLineToArgvWUnescape(path.begin(), path.end(), std::back_inserter(unescaped)); if (boost::istarts_with(unescaped, GetRundll32Path())) { std::wstring::iterator startOfArgument = std::find(endOfUnescape, path.end(), L'\"'); if (startOfArgument != path.end()) { unescaped.push_back(L' '); CmdLineToArgvWUnescape(startOfArgument, path.end(), std::back_inserter(unescaped)); // Unescape the argument RundllCheck(unescaped); } } path = unescaped; ExpandShortPath(path); Prettify(path.begin(), path.end()); return SystemFacades::File::IsExclusiveFile(path); } else { NativePathToWin32Path(path); bool status = StripArgumentsFromPath(path); if (status) { ExpandShortPath(path); Prettify(path.begin(), path.end()); } return status; } }