Pagini recente » Cod sursa (job #2988379) | Cod sursa (job #26517) | Cod sursa (job #1334185) | Cod sursa (job #2531014) | Cod sursa (job #1357424)
//
// main.cpp
// convertor2
//
// Created by Alex Petrache on 23/02/15.
// Copyright (c) 2015 Alex Petrache. All rights reserved.
//
#include <iostream>
#include <fstream>
using namespace std;
string linie;
string keys, values;
int main(int argc, const char * argv[]) {
ifstream f("convertor.in");
ofstream g("convertor.out");
// ifstream f("/Users/alexpetrache/Documents/Programare/Xcode/convertor2/convertor2/convertor.in");
// ofstream g("/Users/alexpetrache/Documents/Programare/Xcode/convertor2/convertor2/convertor.out");
int sz,i;
bool obj=false,firstTime=true;
bool key=false,expectKey=false;
bool value=false,expectValue=false;
while(getline(f,linie)){
sz=linie.size();
for(i=0;i<sz;i++){
if(linie[i]=='}'){
// cout<<'\n';
// cout<<"KEYS: "<<keys<<'\n';
// cout<<"VALEUS: "<<values<<'\n';
// cout<<"END OBJECT\n";
if(firstTime)
g<<keys<<'\n';
g<<values<<'\n';
firstTime=false;
keys="";
values="";
key=false;
expectKey=false;
value=false;
expectValue=false;
}
if(key){
//cout<<"[BAG "<<linie[i]<<" ]";
if(linie[i]=='"'){
//finalul key
key=false;
keys.push_back(',');
expectValue=true;
continue;
}
else{
keys.push_back(linie[i]);
continue;
}
}
if(value){
cout<<"[[VALUE: "<<linie[i]<<" ]]";
if(linie[i]=='"' || linie[i]==',' || linie[i]=='}' || linie[i]=='}'){
//finalul value
value=false;
values.push_back(',');
if(linie[i]==',' || (linie[i]=='"' && linie[i+1]==','))
expectKey=true;
continue;
}
values.push_back(linie[i]);
continue;
}
if(expectValue){
//cout<<"[Sunt la "<<linie[i]<<" ]";
if(linie[i]==':' || linie[i]==' '){
continue;
}
if(linie[i]=='"'){
expectValue=false;
value=true;
continue;
}
// cout<<"AMTRECUT";
expectValue=false;
value=true;
values.push_back(linie[i]);
continue;
}
if(expectKey){
// cout<<"[[ASTEPT KEY]]";
if(linie[i]=='"'){
key=true;
expectKey=false;
continue;
}
}
if(linie[i]=='{'){
obj=true;
expectKey=true;
}
// if(linie[i]==':')
// expectValue=true;
}
// cout<<keys;
}
return 0;
}