1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <nel/misc/types_nl.h>
22 #include <nel/misc/ucstring.h>
23 #include <nel/misc/utf_string_view.h>
24 #include <nel/misc/common.h>
25 #include <nel/misc/sstring.h>
26 #include <nel/misc/i18n.h>
29 using namespace NLMISC
;
33 printf("uni_conv [option] <output_mode> <input_file> <output_file>\n");
34 printf("output_mode is one of:\n");
35 printf("\t-8 output in UTF-8\n");
36 printf("\t-16 output in UTF-16\n");
37 printf("\t-a output in ascii, non ascii char are silently removed\n");
39 printf("\t-x minimal support for XML : encode &, < and > in XML chat tag\n");
42 int main(int argc
, char *argv
[])
44 new NLMISC::CApplicationContext
;
46 bool xmlSupport
= false;
47 enum TOutMode
{UNDEF
, UTF8
, UTF16
, ASCII
};
50 TOutMode outMode
= UNDEF
;
57 for (int i
=1; i
<argc
; ++i
)
59 CSString arg
= argv
[i
];
64 else if (arg
== "-16")
74 if (outputFile
.empty() || inputFile
.empty() || outMode
== UNDEF
)
81 CI18N::readTextFile(inputFile
, str
, false, false);
86 temp
.reserve(str
.size());
87 for (uint i
=0; i
<str
.size(); ++i
)
110 CI18N::writeTextFile(outputFile
, str
, true);
113 CI18N::writeTextFile(outputFile
, str
, false);
118 res
.reserve(str
.size());
119 for (ucstring::const_iterator
it(str
.begin()), end(str
.end()); it
!= end
; ++it
)
125 FILE *fp
= nlfopen(outputFile
, "wt");
126 fwrite(res
.data(), res
.size(), 1, fp
);