pip_vtt support special characters
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
|||||||
project(PIP)
|
project(PIP)
|
||||||
set(PIP_MAJOR 3)
|
set(PIP_MAJOR 3)
|
||||||
set(PIP_MINOR 15)
|
set(PIP_MINOR 15)
|
||||||
set(PIP_REVISION 2)
|
set(PIP_REVISION 3)
|
||||||
set(PIP_SUFFIX )
|
set(PIP_SUFFIX )
|
||||||
set(PIP_COMPANY SHS)
|
set(PIP_COMPANY SHS)
|
||||||
set(PIP_DOMAIN org.SHS)
|
set(PIP_DOMAIN org.SHS)
|
||||||
|
|||||||
@@ -77,6 +77,34 @@ void printError(const PIString & msg) {
|
|||||||
PISet<PIString> strings;
|
PISet<PIString> strings;
|
||||||
PIMap<uint, PIString> locations;
|
PIMap<uint, PIString> locations;
|
||||||
|
|
||||||
|
PIString mask(const PIString & in) {
|
||||||
|
static PIVector<PIPair<PIString, PIString>> map = {
|
||||||
|
{"&", "&" },
|
||||||
|
{"<", "<" },
|
||||||
|
{">", ">" },
|
||||||
|
{"'", "'"},
|
||||||
|
{"\"", """},
|
||||||
|
};
|
||||||
|
PIString ret = in;
|
||||||
|
for (const auto & i: map)
|
||||||
|
ret.replaceAll(i.first, i.second);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
PIString unmask(const PIString & in) {
|
||||||
|
static PIVector<PIPair<PIString, PIString>> map = {
|
||||||
|
{"<", "<" },
|
||||||
|
{">", ">" },
|
||||||
|
{"'", "'"},
|
||||||
|
{"\"", """},
|
||||||
|
{"&", "&" },
|
||||||
|
};
|
||||||
|
PIString ret = in;
|
||||||
|
for (const auto & i: map)
|
||||||
|
ret.replaceAll(i.second, i.first);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void addString(const PIString & s, const PIString & loc) {
|
void addString(const PIString & s, const PIString & loc) {
|
||||||
if (s.isEmpty()) return;
|
if (s.isEmpty()) return;
|
||||||
strings << s;
|
strings << s;
|
||||||
@@ -138,7 +166,7 @@ PIMap<PIString, TSMessage> readTS(const PIString & path) {
|
|||||||
phase = 2;
|
phase = 2;
|
||||||
} else if (line.startsWith("<source>")) {
|
} else if (line.startsWith("<source>")) {
|
||||||
line.cutLeft(8).cutRight(9);
|
line.cutLeft(8).cutRight(9);
|
||||||
msg.source = line;
|
msg.source = unmask(line);
|
||||||
} else if (line.startsWith("<location")) {
|
} else if (line.startsWith("<location")) {
|
||||||
PIString trs = line.takeRange('<', '>').cutLeft(8);
|
PIString trs = line.takeRange('<', '>').cutLeft(8);
|
||||||
while (trs.isNotEmpty()) {
|
while (trs.isNotEmpty()) {
|
||||||
@@ -158,7 +186,7 @@ PIMap<PIString, TSMessage> readTS(const PIString & path) {
|
|||||||
if (t == "type") msg.type = v;
|
if (t == "type") msg.type = v;
|
||||||
}
|
}
|
||||||
line.cutRight(14);
|
line.cutRight(14);
|
||||||
msg.translation = line;
|
msg.translation = unmask(line);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -236,7 +264,7 @@ int main(int argc, char * argv[]) {
|
|||||||
PIIOTextStream ts(&outf);
|
PIIOTextStream ts(&outf);
|
||||||
auto writeTSMessage = [&ts](const PIString & s, const TSMessage & m) {
|
auto writeTSMessage = [&ts](const PIString & s, const TSMessage & m) {
|
||||||
ts << " <message>\n";
|
ts << " <message>\n";
|
||||||
ts << " <source>" << s << "</source>\n";
|
ts << " <source>" << mask(s) << "</source>\n";
|
||||||
if (m.filename.isNotEmpty()) {
|
if (m.filename.isNotEmpty()) {
|
||||||
ts << " <location filename=\"" << m.filename << "\"";
|
ts << " <location filename=\"" << m.filename << "\"";
|
||||||
if (m.line.isNotEmpty()) ts << " line=\"" << m.line << "\"";
|
if (m.line.isNotEmpty()) ts << " line=\"" << m.line << "\"";
|
||||||
@@ -248,7 +276,7 @@ int main(int argc, char * argv[]) {
|
|||||||
} else {
|
} else {
|
||||||
if (m.type.isNotEmpty()) ts << " type=\"" << m.type << "\"";
|
if (m.type.isNotEmpty()) ts << " type=\"" << m.type << "\"";
|
||||||
}
|
}
|
||||||
ts << ">" << m.translation << "</translation>\n";
|
ts << ">" << mask(m.translation) << "</translation>\n";
|
||||||
ts << " </message>\n";
|
ts << " </message>\n";
|
||||||
};
|
};
|
||||||
ts << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
|
ts << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user