mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 12:58:00 +03:00
feat: rewrite toSting to std::string
This commit is contained in:
@@ -97,32 +97,32 @@ void toml_node::setMapArray(TOMLMapArray *map_array)
|
||||
}
|
||||
|
||||
|
||||
std::string *toml_node::toString(void) const
|
||||
std::string toml_node::toString(void) const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case STRING:
|
||||
{
|
||||
return (value.str);
|
||||
return (*value.str);
|
||||
}
|
||||
case NUM:
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << value.integer;
|
||||
std::string *result = new std::string();
|
||||
ss >> *result;
|
||||
std::string result;
|
||||
ss >> result;
|
||||
return (result);
|
||||
}
|
||||
case ARRAY:
|
||||
{
|
||||
TOMLArray::iterator it;
|
||||
std::string *result = new std::string("[ ");
|
||||
std::string result("[ ");
|
||||
for (it = value.array->begin(); it != value.array->end(); ++it)
|
||||
{
|
||||
*result += *((*it)->toString());
|
||||
*result += ", ";
|
||||
result += ((*it)->toString());
|
||||
result += ", ";
|
||||
}
|
||||
*result += " ]";
|
||||
result += " ]";
|
||||
return (result);
|
||||
}
|
||||
case MAP:
|
||||
@@ -132,41 +132,41 @@ std::string *toml_node::toString(void) const
|
||||
case MAPARRAY:
|
||||
{
|
||||
std::stringstream ss;
|
||||
std::string *result = new std::string();
|
||||
std::string result;
|
||||
TOMLMapArray::iterator it;
|
||||
TOMLMapArray *map_array = value.map_array;
|
||||
|
||||
ss << "[\n";
|
||||
for (it = map_array->begin(); it != map_array->end(); ++it)
|
||||
{
|
||||
ss << (*TOMLMap_to_string(*it));
|
||||
ss << (TOMLMap_to_string(*it));
|
||||
ss << ", " << std::endl;
|
||||
}
|
||||
ss << "]\n";
|
||||
|
||||
|
||||
/* ss >> *result; */
|
||||
*result = ss.str();
|
||||
result = ss.str();
|
||||
return (result);
|
||||
}
|
||||
case BOOL:
|
||||
{
|
||||
std::string *result;
|
||||
std::string result;
|
||||
if (value.boolean)
|
||||
result = new std::string("true");
|
||||
result = std::string("true");
|
||||
else
|
||||
result = new std::string("false");
|
||||
result = std::string("false");
|
||||
return (result);
|
||||
}
|
||||
default:
|
||||
return ( new std::string("Not implemented :)"));
|
||||
return (std::string("Not implemented :)"));
|
||||
}
|
||||
}
|
||||
|
||||
std::string *toml_node::TOMLMap_to_string(TOMLMap *map)
|
||||
std::string toml_node::TOMLMap_to_string(TOMLMap *map)
|
||||
{
|
||||
std::stringstream ss;
|
||||
std::string *result = new std::string();
|
||||
std::string result;
|
||||
TOMLMap::iterator it;
|
||||
|
||||
ss << "{\n";
|
||||
@@ -174,13 +174,13 @@ std::string *toml_node::TOMLMap_to_string(TOMLMap *map)
|
||||
{
|
||||
ss << it->first
|
||||
<< ": "
|
||||
<< *(it->second->toString())
|
||||
<< (it->second->toString())
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
ss << "}" << std::endl;
|
||||
|
||||
/* ss >> *result; */
|
||||
*result = ss.str();
|
||||
result = ss.str();
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ class toml_node
|
||||
void setObject(TOMLMap *obj);
|
||||
void setMapArray(TOMLMapArray *map_array);
|
||||
|
||||
std::string *toString(void) const;
|
||||
static std::string *TOMLMap_to_string(TOMLMap *map);
|
||||
std::string toString(void) const;
|
||||
static std::string TOMLMap_to_string(TOMLMap *map);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -20,19 +20,18 @@
|
||||
/* } */
|
||||
namespace config
|
||||
{
|
||||
|
||||
void display(TOMLMap *root_map)
|
||||
{
|
||||
std::cout << ">>> printing config: <<<" << std::endl;
|
||||
DBOUT << ">>> printing config: <<<" << std::endl;
|
||||
|
||||
TOMLMap::iterator it;
|
||||
|
||||
for (it = root_map->begin(); it != root_map->end(); ++it)
|
||||
{
|
||||
std::cout << it->first
|
||||
DBOUT << it->first
|
||||
<< ": "
|
||||
<< *(it->second->toString());
|
||||
std::cout << ", " << std::endl;
|
||||
<< (it->second->toString());
|
||||
DBOUT << ", " << std::endl;
|
||||
/* << std::endl << "-------" << std::endl; */
|
||||
}
|
||||
}
|
||||
@@ -42,6 +41,7 @@ namespace config
|
||||
TOMLMap::iterator it;
|
||||
|
||||
DBOUT << ">>> cleaning up: <<<" << std::endl;
|
||||
DBOUT << root << ENDL;
|
||||
if (!root)
|
||||
return;
|
||||
for (it = root->begin(); it != root->end(); ++it)
|
||||
@@ -52,7 +52,7 @@ namespace config
|
||||
|
||||
clean_generic(it->second);
|
||||
/* delete it->second; */
|
||||
std::cout << ", " << std::endl;
|
||||
DBOUT << ", " << std::endl;
|
||||
}
|
||||
DBOUT << YELLO << "end of clean" << ENDL;
|
||||
root->clear();
|
||||
|
||||
@@ -8,6 +8,5 @@
|
||||
#include "TOMLParser.hpp"
|
||||
|
||||
TOMLMap *parse(char *filename);
|
||||
void display(TOMLMap *config);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,7 +9,7 @@ typedef std::vector<toml_node *> TOMLArray;
|
||||
|
||||
namespace config
|
||||
{
|
||||
|
||||
void display(TOMLMap *config);
|
||||
void clean_parsed(TOMLMap *root);
|
||||
void clean_generic(toml_node *node);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user