Correct ascii behaviour in tool

develop
kaetemi 4 years ago
parent c770191bef
commit cb949ae13a

@ -17,6 +17,7 @@
#include <nel/misc/types_nl.h> #include <nel/misc/types_nl.h>
#include <nel/misc/ucstring.h> #include <nel/misc/ucstring.h>
#include <nel/misc/utf_string_view.h>
#include <nel/misc/common.h> #include <nel/misc/common.h>
#include <nel/misc/sstring.h> #include <nel/misc/sstring.h>
#include <nel/misc/i18n.h> #include <nel/misc/i18n.h>
@ -76,21 +77,10 @@ int main(int argc, char *argv[])
ucstring str; ucstring str;
CI18N::readTextFile(inputFile, str, false, false); CI18N::readTextFile(inputFile, str, false, false);
if (outMode == ASCII)
{
// remove any outof ascii char
ucstring temp;
for (uint i=0; i<str.size(); ++i)
{
if (str[i] < 256)
temp += str[i];
}
str = temp;
}
if (xmlSupport) if (xmlSupport)
{ {
ucstring temp; ucstring temp;
temp.reserve(str.size());
for (uint i=0; i<str.size(); ++i) for (uint i=0; i<str.size(); ++i)
{ {
switch(str[i]) switch(str[i])
@ -121,9 +111,16 @@ int main(int argc, char *argv[])
break; break;
case ASCII: case ASCII:
{ {
string s = str.toString(); std::string res;
res.reserve(str.size());
for (ucstring::const_iterator it(str.begin()), end(str.end()); it != end; ++it)
{
ucchar c = *it;
if (c < 0x80)
res += (char)c;
}
FILE *fp = nlfopen(outputFile, "wt"); FILE *fp = nlfopen(outputFile, "wt");
fwrite(s.data(), s.size(), 1, fp); fwrite(res.data(), res.size(), 1, fp);
fclose(fp); fclose(fp);
} }
break; break;

Loading…
Cancel
Save