heksterb / Encoding-Explorer

Home Page:https://www.hekster.org/Professional/ConsoleEncoding/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Encoding Explorer

Simple utility for testing the effect of different ways of generating text output.

Usage

encexp method mode [options...]

method defines the basic API category used and is one of:

  • winapi: use Windows API methods (OpenFile(), WriteFile(), WriteConsole())
  • posix: use ‘POSIX style’ methods (_open(), _write())
  • unformatted: use unformatted C stream I/O (fopen() and fwrite())
  • formatted: use formatted C stream I/O (fopen() and fprintf())
  • unformatted++: use unformatted C++ stream I/O (std::basic_ostream and .write())
  • formatted++: use formatted C++ stream I/O (std::basic_ostream and <<)

mode selects different options within the API and is one of:

  • binary: data as non-text binary
  • text: data as narrow-character (8-bit) text
  • wide: data as wide-character (16-bit) text
  • unicode: output as ‘Unicode mode’; this is something variously described in Microsoft documentation as accepting wide-character (i.e. UTF-16) and converted internally to UTF-8
  • wideunicode: even less well documented, vaguely described as accepting UTF-16 and outputting UTF-16

Not every mode is supported by every method (as described in the table, below).

Supported options are:

  • cp####: set the Console Output Code Page (through a call to SetConsoleOutputPage()) prior to generating output
  • l####: set the locale prior to generating output; the specific method used depends on the selected Method and is
  • file: output directly to a file named output as opposed to standard output

Summary of Supported Modes and Methods

Method Binary Text Wide Unicode Wide Unicode
Windows API WriteFile() WriteConsoleA() WriteConsoleW() n/a n/a
‘POSIX’ style _open(_O_BINARY) _open(_O_TEXT) _open(_O_WTEXT) _open(_O_U8TEXT) _open(_O_U16TEXT)
C unformatted fopen("wb")
fwrite()
fopen("w")
fwrite()
fopen("w,ccs=unicode")
fwrite()
fopen("w,ccs=utf-8")
fwrite()
fopen("w,ccs=utf-16le")
fwrite()
C formatted fopen("wb")
fprintf()
fopen("w")
fprintf()
fopen("w,ccs=unicode")
fwprintf()
fopen("w,ccs=utf-8")
fwprintf()
fopen("w,ccs=utf-16le")
fwprintf()
C++ unformatted ostream(ios::binary)
.write()
ostream()
.write()
wostream()
.write()
fopen("w,ccs=utf-8")
wostream(FILE)
.write()
fopen("w,ccs=utf-16le")
wostream(FILE)
codecvt_utf16
.write()
C++ formatted ostream(ios::binary)
<<
ostream()
<<
wostream()
<<
fopen("w,ccs=utf-8")
wostream(FILE)
<<
fopen("w,ccs=utf-16le")
wostream(FILE)
codecvt_utf16
<<

Summary of Locale

  • Windows API: n/a
  • POSIX style: n/a
  • C (unformatted and formatted): setlocale(LC_ALL, ####)
  • C++ (unformatted and formatted):
    • binary, text (narrow input and output): std::ostream::imbue(std::locale(####))
    • wide, unicode (wide input, narrow output): std::wostream::imbue(std::locale(####))
    • wide unicode (wide input and output): std::wostream::imbue(std::locale()) with std::codecvt_utf16

About

https://www.hekster.org/Professional/ConsoleEncoding/

License:GNU General Public License v3.0


Languages

Language:C 70.7%Language:C++ 29.3%