Pagini recente » Profil vexxato | Cod sursa (job #2753691) | Cod sursa (job #2683390) | Cod sursa (job #1175982) | Cod sursa (job #1359514)
#include <fstream>
#include <string>
using namespace std;
int main()
{
string line;
string keyArray, valueArray;
ifstream f("convertor.in");
ofstream g("convertor.out");
string::size_type index, left, right;
bool firstObject = true, key = false;
while (getline(f, line))
{
do
{
if (!key)
{
index = line.find_first_of("}\"");
if (index != string::npos)
{
if (line[index] == '}')
{
if (firstObject)
{
g << keyArray << '\n';
firstObject = false;
}
left = right = index;
g << valueArray << '\n';
valueArray = "";
}
else
{
left = index;
right = line.find("\"", left + 1);
if (firstObject)
keyArray += line.substr(left + 1, right - left - 1) + ",";
key = true;
}
index = right + 1;
}
}
else
{
index = line.find_first_of("0123456789\"");
if (index != string::npos)
{
if (line[index] >= '0' && line[index] <= '9')
{
left = index;
right = line.find_first_not_of("0123456789", left + 1);
valueArray += line.substr(left, right - left) + ",";
index = right;
}
else
{
left = index;
right = line.find("\"", index + 1);
valueArray += line.substr(left + 1, right - left - 1) + ",";
index = right + 1;
}
key = false;
}
}
if (index != string::npos)
line = line.substr(index);
} while (index != string::npos);
}
f.close();
g.close();
return 0;
}