Exemple #1
0
string EncodeDicti( const CAtomDicti &x )
{
	map<string, CAtom *> mapDicti = x.getValue( );

	string strDest;

	strDest += "d";

	for( map<string, CAtom *> :: iterator i = mapDicti.begin( ); i != mapDicti.end( ); i++ )
	{
		strDest += EncodeString( CAtomString( (*i).first ) );

		if( dynamic_cast<CAtomInt *>( (*i).second ) )
			strDest += EncodeInt( *dynamic_cast<CAtomInt *>( (*i).second ) );
		else if( dynamic_cast<CAtomLong *>( (*i).second ) )
			strDest += EncodeLong( *dynamic_cast<CAtomLong *>( (*i).second ) );
		else if( dynamic_cast<CAtomString *>( (*i).second ) )
			strDest += EncodeString( *dynamic_cast<CAtomString *>( (*i).second ) );
		else if( dynamic_cast<CAtomList *>( (*i).second ) )
			strDest += EncodeList( *dynamic_cast<CAtomList *>( (*i).second ) );
		else if( dynamic_cast<CAtomDicti *>( (*i).second ) )
			strDest += EncodeDicti( *dynamic_cast<CAtomDicti *>( (*i).second ) );
	}

	strDest += "e";

	return strDest;
}
Exemple #2
0
void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const
{
	TIXML_STRING n, v;

	EncodeString( name, &n );
	EncodeString( value, &v );

	if (value.find ('\"') == TIXML_STRING::npos) {
		if ( cfile ) {
		fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
		}
		if ( str ) {
			(*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
		}
	}
	else {
#if 0
		// disabled for the UIDesigner
		//if ( cfile ) {
		//fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() );
		//}
		//if ( str ) {
		//	(*str) += n; (*str) += "='"; (*str) += v; (*str) += "'";
		//}
#else
		if ( cfile ) {
		fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
		}
		if ( str ) {
			(*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
		}
#endif
	}
}
    /**
        Write a new name/value pair.

        \param[in]  name    Name of value.
        \param[in] value    Value.
    */
    void SCXFilePersistDataWriter::WriteValue(const std::wstring& name, const std::wstring& value)
    {
        std::wostringstream os;
        os << m_Indentation  << L"<Value Name=\""   << EncodeString(name)
           << L"\" Value=\"" << EncodeString(value) << L"\"/>" << std::endl;
        SCXStream::WriteAsUTF8(*m_Stream, os.str());
    }
Exemple #4
0
void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const
{
	TIXML_STRING n, v;
	
	EncodeString( name, &n );
	EncodeString( value, &v );
	
	if ( value.find ( '\"' ) == TIXML_STRING::npos ) {
		if ( cfile ) {
			fprintf ( cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
		}
		if ( str ) {
			( *str ) += n;
			( *str ) += "=\"";
			( *str ) += v;
			( *str ) += "\"";
		}
	} else {
		if ( cfile ) {
			fprintf ( cfile, "%s='%s'", n.c_str(), v.c_str() );
		}
		if ( str ) {
			( *str ) += n;
			( *str ) += "='";
			( *str ) += v;
			( *str ) += "'";
		}
	}
}
Exemple #5
0
void TiXmlAttribute::Print( FileOps *f, int /*depth*/, TIXML_STRING* str ) const
{
	TIXML_STRING n, v;

	EncodeString( name, &n );
	EncodeString( value, &v );

	if (value.find ('\"') == TIXML_STRING::npos) {
		const char *startVal = "=\"";
		const char *endVal = "\"";
		if (f) {
			f->write(n.c_str(), n.size(), 1);
			f->write(startVal, 2, 1);
			f->write(v.c_str(), v.size(), 1);
			f->write(endVal, 1, 1);
		}
		if ( str ) {
			(*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
		}
	}
	else {
		const char *startVal = "='";
		const char *endVal = "'";
		if (f) {
			f->write(n.c_str(), n.size(), 1);
			f->write(startVal, 2, 1);
			f->write(v.c_str(), v.size(), 1);
			f->write(endVal, 1, 1);
		}
		if ( str ) {
			(*str) += n; (*str) += "='"; (*str) += v; (*str) += "'";
		}
	}
}
Exemple #6
0
/* EncodeElement is called by cat(), write.table() and deparsing. */
const char *EncodeElement(SEXP x, int indx, int quote, char dec)
{
    int w, d, e, wi, di, ei;
    const char *res;

    switch(TYPEOF(x)) {
    case LGLSXP:
	formatLogical(&LOGICAL(x)[indx], 1, &w);
	res = EncodeLogical(LOGICAL(x)[indx], w);
	break;
    case INTSXP:
	formatInteger(&INTEGER(x)[indx], 1, &w);
	res = EncodeInteger(INTEGER(x)[indx], w);
	break;
    case REALSXP:
	formatReal(&REAL(x)[indx], 1, &w, &d, &e, 0);
	res = EncodeReal(REAL(x)[indx], w, d, e, dec);
	break;
    case STRSXP:
	formatString(&STRING_PTR(x)[indx], 1, &w, quote);
	res = EncodeString(STRING_ELT(x, indx), w, quote, Rprt_adj_left);
	break;
    case CPLXSXP:
	formatComplex(&COMPLEX(x)[indx], 1, &w, &d, &e, &wi, &di, &ei, 0);
	res = EncodeComplex(COMPLEX(x)[indx], w, d, e, wi, di, ei, dec);
	break;
    case RAWSXP:
	res = EncodeRaw(RAW(x)[indx]);
	break;
    default:
	res = NULL; /* -Wall */
	UNIMPLEMENTED_TYPE("EncodeElement", x);
    }
    return res;
}
Exemple #7
0
void TiXmlText::Print( FileOps *f, int depth ) const
{
	const char *newLine = "\n";
	const char *tabSpacer = "   ";
	const char *start = "<![CDATA[";
	const char *end = "]]>\n";
	assert( f );
	if ( cdata )
	{
		int i;
		f->write(newLine, strlen(newLine), 1);
		for ( i=0; i<depth; i++ ) {
			f->write(tabSpacer, 3, 1);
		}
		f->write(start, strlen(start), 1);
		f->write(value.c_str(), value.size(), 1);
		f->write(end, strlen(end), 1);
	}
	else
	{
		TIXML_STRING buffer;
		EncodeString( value, &buffer );
		f->write(buffer.c_str(), buffer.size(), 1);
	}
}
Exemple #8
0
string EncodeList( const CAtomList &x )
{
	vector<CAtom *> v = x.getValue( );

	string strDest;

	strDest += "l";

	for( vector<CAtom *> :: iterator i = v.begin( ); i != v.end( ); i++ )
	{
		if( dynamic_cast<CAtomInt *>( *i ) )
			strDest += EncodeInt( *dynamic_cast<CAtomInt *>( *i ) );
		else if( dynamic_cast<CAtomLong *>( *i ) )
			strDest += EncodeLong( *dynamic_cast<CAtomLong *>( *i ) );
		else if( dynamic_cast<CAtomString *>( *i ) )
			strDest += EncodeString( *dynamic_cast<CAtomString *>( *i ) );
		else if( dynamic_cast<CAtomList *>( *i ) )
			strDest += EncodeList( *dynamic_cast<CAtomList *>( *i ) );
		else if( dynamic_cast<CAtomDicti *>( *i ) )
			strDest += EncodeDicti( *dynamic_cast<CAtomDicti *>( *i ) );
	}

	strDest += "e";

	return strDest;
}
Exemple #9
0
void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const
{
    TIXML_STRING n, v;

    EncodeString( name, &n );
    EncodeString( value, &v );

    if ( cfile ) {
        fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
    }
    if ( str ) {
        (*str) += n;
        (*str) += "=\"";
        (*str) += v;
        (*str) += "\"";
    }
}
    /**
        Mark the start of a new group.

        \param[in]  name     Name of group.
    */
    void SCXFilePersistDataWriter::WriteStartGroup(const std::wstring& name)
    {
        std::wostringstream os;
        os << m_Indentation << L"<Group Name=\"" << EncodeString(name) << L"\">" << std::endl;
        SCXStream::WriteAsUTF8(*m_Stream, os.str());    
        m_StartedGroups.push_front(name);
        m_Indentation.append(L"  ");
    }
Exemple #11
0
static void cat_newline(SEXP labels, int *width, int lablen, int ntot)
{
    Rprintf("\n");
    *width = 0;
    if (labels != R_NilValue) {
	Rprintf("%s ", EncodeString(STRING_ELT(labels, ntot % lablen),
				    1, 0, Rprt_adj_left));
	*width += Rstrlen(STRING_ELT(labels, ntot % lablen), 0) + 1;
    }
}
void IOPropertyMappingCollection::Write(MdfStream& fd, PropertyMappingCollection* propMappings, Version* version, const std::string& name, MgTab& tab)
{
    _ASSERT(NULL != propMappings);

    fd << tab.tab() << startStr(name) << std::endl;
    tab.inctab();

    for (int i = 0; i < propMappings->GetCount(); ++i)
    {
       fd << tab.tab() << startStr(sPropertyMapping) << std::endl;
       tab.inctab();

        PropertyMapping* propMapping = dynamic_cast<PropertyMapping*>(propMappings->GetAt(i));
        _ASSERT(NULL != propMapping);

        // Property: TargetProperty
        fd << tab.tab() << startStr(sTargetProperty);
        fd << EncodeString(propMapping->GetTargetProperty());
        fd << endStr(sTargetProperty) << std::endl;

        // Property: SourceProperty
        fd << tab.tab() << startStr(sSourceProperty);
        fd << EncodeString(propMapping->GetSourceProperty());
        fd << endStr(sSourceProperty) << std::endl;

        // Property: SourceUnits
        fd << tab.tab() << startStr(sSourceUnits);
        fd << EncodeString(propMapping->GetSourceUnits());
        fd << endStr(sSourceUnits) << std::endl;

        // Write any unknown XML / extended data
        IOUnknown::Write(fd, propMapping->GetUnknownXml(), version, tab);

        tab.dectab();
        fd << tab.tab() << endStr(sPropertyMapping) << std::endl;
    }

    tab.dectab();
    fd << tab.tab() << endStr(name) << std::endl;
}
Exemple #13
0
std::string Game::GetEncodeString(const char* str)
{
    const Settings & conf = Settings::Get();
    std::string str1(str);
    std::string str2(_(str));

    // encode name
    if(str1 == str2 && str1.size() &&
            conf.Unicode() && conf.MapsCharset().size())
        str2 = EncodeString(str1, conf.MapsCharset().c_str());

    return str2;
}
Exemple #14
0
void TiXmlText::Print(FILE* cfile, int depth) const {
	assert(cfile);
	if (cdata) {
		int i;
		fprintf(cfile, "\n");
		for (i = 0; i < depth; i++) {
			fprintf(cfile, "    ");
		}
		fprintf(cfile, "<![CDATA[%s]]>\n", value.c_str()); // unformatted output
	} else {
		TIXML_STRING buffer;
		EncodeString(value, &buffer);
		fprintf(cfile, "%s", buffer.c_str());
	}
}
Exemple #15
0
	std::string ToStringOption() {
		std::string ret;
		for( std::vector<TreeItem>::const_iterator i = TreeItems.begin() ; i != TreeItems.end(); i++ ) {
			const TreeItem& item = *i;
			if( item.Value != item.Defalut ) {
				std::string name;
				TVPUtf16ToUtf8( name, item.Parameter );
				ret += name;
				ret += "=";
				ret += EncodeString( item.Select[item.Value].first );
				ret += "\r\n";
			}
		}
		return ret;
	}
Exemple #16
0
string Encode( CAtom *pAtom )
{
	if( dynamic_cast<CAtomInt *>( pAtom ) )
		return EncodeInt( *dynamic_cast<CAtomInt *>( pAtom ) );
	else if( dynamic_cast<CAtomLong *>( pAtom ) )
		return EncodeLong( *dynamic_cast<CAtomLong *>( pAtom ) );
	else if( dynamic_cast<CAtomString *>( pAtom ) )
		return EncodeString( *dynamic_cast<CAtomString *>( pAtom ) );
	else if( dynamic_cast<CAtomList *>( pAtom ) )
		return EncodeList( *dynamic_cast<CAtomList *>( pAtom ) );
	else if( dynamic_cast<CAtomDicti *>( pAtom ) )
		return EncodeDicti( *dynamic_cast<CAtomDicti *>( pAtom ) );

	return string( );
}
Exemple #17
0
BOOL BEEncoder::EncodeDict(LPDICTIONARY d)
{
    BeginDictionary();					// begin dictionary

    DictIterator it = d->GetIterator();
    while (it.HasNext()) {
        Dictionary::ObjectEntry entry = it.GetNext();
        EncodeString(entry.first);
        EncodeObject(entry.second);
    }

    EndObject();

    return TRUE;
}
static void LeftMatrixColumnLabel(SEXP cl, int j, int w)
{
    int l;
    SEXP tmp;

    if (!isNull(cl)) {
        tmp= STRING_ELT(cl, j);
        if(tmp == NA_STRING) l = R_print.na_width_noquote;
        else l = Rstrlen(tmp, 0);
        Rprintf("%*s%s%*s", R_print.gap, "",
                EncodeString(tmp, l, 0, Rprt_adj_left), w-l, "");
    }
    else {
        Rprintf("%*s[,%ld]%*s", R_print.gap, "", j+1, w-IndexWidth(j+1)-3, "");
    }
}
void main( void )
{
 uchar str[80];

 while ( 1 )
 {
  printf("Enter string:");
  gets(str);
  printf("\n");

  EncodeString( str );
  printf("Encoded:%s\n", str );
  DecodeString( str );
  printf("Decoded:%s\n\n", str );

 }
}
static void MatrixRowLabel(SEXP rl, int i, int rlabw, int lbloff)
{
    int l;
    SEXP tmp;

    if (!isNull(rl)) {
        tmp= STRING_ELT(rl, i);
        if(tmp == NA_STRING) l = R_print.na_width_noquote;
        else l = Rstrlen(tmp, 0);
        Rprintf("\n%*s%s%*s", lbloff, "",
                EncodeString(tmp, l, 0, Rprt_adj_left),
                rlabw-l-lbloff, "");
    }
    else {
        Rprintf("\n%*s[%ld,]", rlabw-3-IndexWidth(i + 1), "", i+1);
    }
}
Exemple #21
0
static void printStringVector(SEXP *x, R_xlen_t n, int quote, int indx)
{
    int w, labwidth=0, width;

    DO_first_lab;
    formatString(x, n, &w, quote);

    for (R_xlen_t i = 0; i < n; i++) {
	if (i > 0 && width + w + R_print.gap > R_print.width) {
	    DO_newline;
	}
	Rprintf("%*s%s", R_print.gap, "",
		EncodeString(x[i], w, quote, R_print.right));
	width += w + R_print.gap;
    }
    Rprintf("\n");
}
Exemple #22
0
long SjCPlugin::CallMaster(UINT msg, LPARAM param1, LPARAM param2, LPARAM param3)
{
	wxASSERT( msg >= 20000 && msg <= 29999 );

	if( g_mainFrame == NULL || g_tools == NULL )
		return 0;

	// thread-safe mesages
	switch( msg )
	{
		case SJ_GET_VERSION:
			return SjTools::VersionString2Long(SJ_VERSION_ASCII);
	}

	if( ! wxThread::IsMain() )
		return 0;

	// no thread-save message
	switch( msg )
	{
		case SJ_EXECUTE:
			#if SJ_USE_SCRIPTS
				if( m_see == NULL )
				{
					m_see = new SjSee();
					m_see->m_plugin = this;
					m_see->SetExecutionScope(m_file);
				}

				m_see->Execute(DecodeString(param1));   // seems to work recursively ;-)
				// ExecuteAsFunction() is no good idea - this avoids to define _any_ globals!
				if( param2 )
					return EncodeString(m_see->GetResultString());
				else
					return m_see->GetResultLong();
			#else
				return 0;
			#endif
	}

	// not supported
	return 0;
}
static void printStringMatrix(SEXP sx, int offset, int r_pr, int r, int c,
                              int quote, int right, SEXP rl, SEXP cl,
                              const char *rn, const char *cn)
{
    _PRINT_INIT_rl_rn;
    SEXP *x = STRING_PTR(sx)+offset;

    for (j = 0; j < c; j++) {
        formatString(&x[j * r], (R_xlen_t) r, &w[j], quote);
        _PRINT_SET_clabw;
        if (w[j] < clabw)
            w[j] = clabw;
    }
    _PRINT_DEAL_c_eq_0;
    while (jmin < c) {
        width = rlabw;
        do {
            width += w[jmax] + R_print.gap;
            jmax++;
        }
        while (jmax < c && width + w[jmax] + R_print.gap < R_print.width);

        _PRINT_ROW_LAB;

        if (right) {
            for (j = jmin; j < jmax ; j++)
                RightMatrixColumnLabel(cl, j, w[j]);
        }
        else {
            for (j = jmin; j < jmax ; j++)
                LeftMatrixColumnLabel(cl, j, w[j]);
        }
        for (i = 0; i < r_pr; i++) {
            MatrixRowLabel(rl, i, rlabw, lbloff);
            for (j = jmin; j < jmax; j++) {
                Rprintf("%*s%s", R_print.gap, "",
                        EncodeString(x[i + j * r], w[j], quote, right));
            }
        }
        Rprintf("\n");
        jmin = jmax;
    }
}
Exemple #24
0
BOOL BEEncoder::EncodeObject(LPBEOBJECT pObject)
{
    switch (pObject->GetType()) {
    case BEObject::BET_DICT:
        return EncodeDict(static_cast<LPDICTIONARY>(pObject));
        break;
    case BEObject::BET_LIST:
        return EncodeList(static_cast<LPLIST>(pObject));
        break;
    case BEObject::BET_INTEGER:
        return EncodeInt(static_cast<LPINTEGER>(pObject));
        break;
    case BEObject::BET_STRING:
        return EncodeString(static_cast<LPSTRING>(pObject));
        break;
    }

    return FALSE;
}
static void RightMatrixColumnLabel(SEXP cl, int j, int w)
{
    int l;
    SEXP tmp;

    if (!isNull(cl)) {
        tmp = STRING_ELT(cl, j);
        if(tmp == NA_STRING) l = R_print.na_width_noquote;
        else l = Rstrlen(tmp, 0);
        /* This does not work correctly at least on FC3
        Rprintf("%*s", R_print.gap+w,
        	EncodeString(tmp, l, 0, Rprt_adj_right)); */
        Rprintf("%*s%s", R_print.gap+w-l, "",
                EncodeString(tmp, l, 0, Rprt_adj_right));
    }
    else {
        Rprintf("%*s[,%ld]%*s", R_print.gap, "", j+1, w-IndexWidth(j+1)-3, "");
    }
}
void IOMapViewportDefinition::Write(MdfStream& fd, MapViewportDefinition* mapViewportDef, Version* version, MgTab& tab)
{
    _ASSERT(NULL != mapViewportDef);

    // Set the expected version
    MdfString strVersion = L"2.0.0";

    fd << tab.tab() << "<PrintLayoutElementDefinition xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"PrintLayoutDefinition-" << EncodeString(strVersion) << ".xsd\" version=\"" << EncodeString(strVersion) << "\">" << std::endl; // NOXLATE
    tab.inctab();

    fd << tab.tab() << startStr(sMapViewportDefinition) << std::endl;
    tab.inctab();

    IOPrintLayoutElementDefinition::Write(fd, mapViewportDef, version, tab);

    // Property: MapName
    fd << tab.tab() << startStr(sMapName);
    fd << EncodeString(mapViewportDef->GetMapName());
    fd << endStr(sMapName) << std::endl;

    // Property: HiddenLayerNames
    IOStringObjectCollection::Write(fd, mapViewportDef->GetHiddenLayerNames(), version, sHiddenLayerNames, sName, tab);

    // Property: Locked
    fd << tab.tab() << startStr(sLocked);
    fd << BoolToStr(mapViewportDef->GetIsLocked());
    fd << endStr(sLocked) << std::endl;

    // Property: On
    fd << tab.tab() << startStr(sOn);
    fd << BoolToStr(mapViewportDef->GetIsOn());
    fd << endStr(sOn) << std::endl;

    // Property: MapView
    IOMapView::Write(fd, mapViewportDef->GetMapView(), version, tab);

    tab.dectab();
    fd << tab.tab() << endStr(sMapViewportDefinition) << std::endl;

    tab.dectab();
    fd << tab.tab() << "</PrintLayoutElementDefinition>" << std::endl; // NOXLATE
}
Exemple #27
0
void TiXmlText::Print( FILE* cfile, int depth ) const
{
	assert( cfile );
	if ( cdata )
	{
		int i;
		fprintf( cfile, "\n" );
        const char* indent = GetDocument() 
            ? GetDocument()->GetIndentChars()
            : DefaultIndentChars;
	    for ( i=0; i<depth; i++ )
		    fprintf( cfile, "%s", indent );

		fprintf( cfile, "<![CDATA[%s]]>\n", value.c_str() );	// unformatted output
	}
	else
	{
		String buffer;
        // sherm: Third argument says OK to keep quotes here 
		EncodeString( value, &buffer, true );
		fprintf( cfile, "%s", buffer.c_str() );
	}
}
Exemple #28
0
nsresult
Key::EncodeJSVal(JSContext* aCx, const jsval aVal, PRUint8 aTypeOffset)
{
  PR_STATIC_ASSERT(eMaxType * MaxArrayCollapse < 256);

  if (JSVAL_IS_STRING(aVal)) {
    nsDependentJSString str;
    if (!str.init(aCx, aVal)) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    EncodeString(str, aTypeOffset);
    return NS_OK;
  }

  if (JSVAL_IS_INT(aVal)) {
    EncodeNumber((double)JSVAL_TO_INT(aVal), eFloat + aTypeOffset);
    return NS_OK;
  }

  if (JSVAL_IS_DOUBLE(aVal)) {
    double d = JSVAL_TO_DOUBLE(aVal);
    if (DOUBLE_IS_NaN(d)) {
      return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
    }
    EncodeNumber(d, eFloat + aTypeOffset);
    return NS_OK;
  }

  if (!JSVAL_IS_PRIMITIVE(aVal)) {
    JSObject* obj = JSVAL_TO_OBJECT(aVal);
    if (JS_IsArrayObject(aCx, obj)) {
      aTypeOffset += eMaxType;

      if (aTypeOffset == eMaxType * MaxArrayCollapse) {
        mBuffer.Append(aTypeOffset);
        aTypeOffset = 0;
      }
      NS_ASSERTION((aTypeOffset % eMaxType) == 0 &&
                   aTypeOffset < (eMaxType * MaxArrayCollapse),
                   "Wrong typeoffset");

      jsuint length;
      if (!JS_GetArrayLength(aCx, obj, &length)) {
        return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
      }

      for (jsuint index = 0; index < length; index++) {
        jsval val;
        if (!JS_GetElement(aCx, obj, index, &val)) {
          return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
        }

        nsresult rv = EncodeJSVal(aCx, val, aTypeOffset);
        NS_ENSURE_SUCCESS(rv, rv);

        aTypeOffset = 0;
      }

      mBuffer.Append(eTerminator + aTypeOffset);

      return NS_OK;
    }

    if (JS_ObjectIsDate(aCx, obj)) {
      EncodeNumber(js_DateGetMsecSinceEpoch(aCx, obj), eDate + aTypeOffset);
      return NS_OK;
    }
  }

  return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
}
Exemple #29
0
bool CGUL::Network::HTTPRequest::PerformRequest(UInt32 timeout)
{
    response = "";
    responseHead = "";
    responseBody = "";

    if (!sock->IsConnected())
    {
        throw NetworkException(NetworkExceptionCode::FAILED_HTTP_REQUEST, NetworkExceptionReason::SOCKET_INVALID);
    }

    sock->Send((const void*)request.GetCString(), request.GetSize());

    char buffer[1024];

    // Wait for the response.
    Timer timeoutTimer;
    timeoutTimer.Start();
    while (sock->Peek(buffer, 1) == 0 && (timeoutTimer.GetElapsedMilliseconds() < timeout || timeout == 0))
    {
        if (!sock->IsConnected())
        {
            throw NetworkException(NetworkExceptionCode::FAILED_HTTP_REQUEST, NetworkExceptionReason::SOCKET_INVALID);
        }
    }
    timeoutTimer.Stop();

    if (timeoutTimer.GetElapsedMilliseconds() >= timeout && timeout != 0)
    {
        throw NetworkException(NetworkExceptionCode::FAILED_HTTP_REQUEST, NetworkExceptionReason::TIMEOUT);
    }

    //Get the headers length.
    int headSize = 0;
    sock->Peek(buffer, 1024);
    CGUL::String bufferString = buffer;
    headSize = bufferString.FindFirstOf("\r\n\r\n")+4;

    //Get the reponse's head.
    char* bufferHead = new char[headSize];
    sock->Receive(bufferHead, headSize);
    responseHead += bufferHead;

    //Parse the Response Header
    ParseResponseHead();

    //Get the reponse's body.
    int amount = 0;

    switch (header.transferEncoding)
    {
        case HTTPTransferEncoding::CONTENT_LENGTH:
        {
            unsigned int count = 0;
            while (sock->IsConnected())
            {
                unsigned int size = 1024;
                if (count + size > header.contentLength)
                {
                    size = header.contentLength - count;
                }

                char* buff = new char[size];
                amount = sock->Receive((void*)buff, size);
                count += amount;
                if (amount > 0)
                {
                    responseBody += EncodeString(buff, size);
                }

                if (count >= header.contentLength)
                {
                    break;
                }
            }
            break;
        }

        case HTTPTransferEncoding::CHUNKED:
        {
            char * sizeBuffer = new char[64];

            while (sock->IsConnected())
            {
                //Get the size.
                amount = sock->Peek(sizeBuffer, 64);
                if (amount <= 0)
                {
                    break;
                }

                String sizeString = "";
                for (int i = 0; i < amount; i++)
                {
                    if (sizeBuffer[i] == '\r')
                    {
                        if (sizeBuffer[i+1] == '\n')
                        {
                            break;
                        }
                        throw NetworkException(NetworkExceptionCode::FAILED_HTTP_REQUEST, NetworkExceptionReason::UNKNOWN);
                    }
                    else
                    {
                        sizeString += sizeBuffer[i];
                    }
                }
                //Convert from hex to decimal
                unsigned int size = 0;
                for (unsigned j = 0; j < sizeString.GetLength(); j++)
                {
                    char code = sizeString[sizeString.GetLength()-j-1];
                    if (code >= 48 && code <= 57) //Number
                    {
                        size += (code - 48)*((j == 0) ? 1 : 16*j);
                    }
                    if (code >= 65 && code <= 70) //A-F
                    {
                        size += (code - 55)*((j == 0) ? 1 : 16*j);
                    }
                    if (code >= 97 && code <= 102) //a-f
                    {
                        size += (code - 87)*((j == 0) ? 1 : 16*j);
                    }
                }
                sock->Receive(sizeBuffer, sizeString.GetLength()+2);

                if (size == 0) //If the size is 0, then we are done
                {
                    break;
                }
                size += 2;

                //Otherwise receive the next chunk and add a new line (\r\n)
                char* buff = new char[size];
                amount = sock->Receive((void*)buff, size);
                responseBody += EncodeString(buff, size);
            }
            break;
        }

        default:
        {
            throw NetworkException(NetworkExceptionCode::FAILED_HTTP_REQUEST, NetworkExceptionReason::UNKNOWN_TRANSFER_ENCODING);
            break;
        }
    }

    response = responseHead + responseBody;

    if (header.connection == Network::HTTPConnections::CLOSE)
    {
        Close();
    }

    return true;
}
//attribute_hidden
const char *EncodeChar(SEXP x)
{
    return EncodeString(x, 0, 0, Rprt_adj_left);
}