An error occurred while loading the file. Please try again.
-
Reto Flütsch authored31191de7
/*
Copyright (c) 2012 digitalSTROM.org, Zurich, Switzerland
Author: Christian Hitz, aizo AG <christian.hitz@aizo.com>
This file is part of po2json.
po2json is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
po2json is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with po2json. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <fstream>
#include <iostream>
#include <stdlib.h>
using namespace std;
string quotedPart(string& line)
{
int strStart = line.find("\"");
if ((strStart == line.npos) ||
(line[line.length() - 1] != '"') ||
(strStart == (line.length() - 1))) {
cerr << "quote error: " << line << endl;
exit(1);
}
return line.substr(strStart);
}
string splitHeader(string& line)
{
int strStart = line.find("\"");
if (strStart != 0) {
cerr << "quote error: " << line << endl;
exit(1);
}
int strEnd = line.find("\\n\"");
if (strEnd == line.npos) {
cerr << "quote error: " << line << endl;
exit(1);
}
int colonPos = line.find(":");
if (colonPos == line.npos) {
cerr << "format error: " << line << endl;
exit(1);
}
return line.substr(0, colonPos) + "\":\"" + line.substr(colonPos + 1, strEnd - colonPos - 1) + "\"";
}
typedef enum {
eStart,
eMessageId,
eMessageIdFirst,
eMessageString,
eMessageStringContinue,
eHeaderSkip,
eHeader,
eHeaderFirst,
eFinish,