Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
	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;
	}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
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'/');
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 9
0
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 );
}
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
Failure::Failure(
    const std::wstring& theCondition,
    const std::string& theFileName,
    long theLineNumber)
    : condition(theCondition.begin(), theCondition.end()),
    fileName(theFileName),
    lineNumber(theLineNumber)
{
}
Ejemplo n.º 12
0
  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());
  }
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 15
0
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 "";
}
Ejemplo n.º 16
0
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();
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
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());
}
Ejemplo n.º 19
0
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
       );
}
Ejemplo n.º 20
0
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());
}
Ejemplo n.º 21
0
inline
std::string
to_string(const std::wstring &s)
{
    using namespace std;
    string buffer;
    copy(s.begin(), s.end(), wctomb_inserter(buffer));

    return buffer;
}
Ejemplo n.º 22
0
	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;
			}
		});
	}
Ejemplo n.º 23
0
    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;
    }
Ejemplo n.º 24
0
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);
}
Ejemplo n.º 25
0
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;
}
Ejemplo n.º 26
0
// 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;
}
Ejemplo n.º 27
0
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;
}
Ejemplo n.º 28
0
    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
    }
Ejemplo n.º 29
0
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);
	}
}
Ejemplo n.º 30
0
    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;
        }
    }