[nim-dev] Re: Code page 65001

  • From: zolern <entopalov@xxxxxxxxx>
  • To: nim-dev@xxxxxxxxxxxxx
  • Date: Tue, 25 Oct 2016 09:27:30 +0000

frwite works perfect in local codepages (non 65001). fwrite works perfect in 
files. fwrite outputs incorrect only when non ASCII symbols are outputed to 
stdout.

Example:
```nim
proc getConsoleOutputCP(): cint {. importc: "GetConsoleOutputCP", stdcall, 
dynlib: "kernel32" .}
proc setConsoleOutputCP(codepage: cint): cint {. stdcall, dynlib: "kernel32", 
importc: "SetConsoleOutputCP", discardable .}

let originalOutCP = getConsoleOutputCP()

setConsoleOutputCP(65001)

echo "Hello, ", "world! ", "Best regards from Nim!"
echo "Здравей, ", "свят! ", "Поздравява Ñ‚е Nim" # same 
in buglarian
echo "Hallo Welt, liebe Gr", "üße von Nim"      # same in German
echo ""

write(stdout, "Hello, ", "world! ", "Best regards from Nim!\n")
write(stdout, "Здравей, ", "свят! ", "Поздравява Ñ‚е 
Nim\n") # same in buglarian
write(stdout, "Hallo Welt, liebe Gr", "üße von Nim\n")      # same in German

setConsoleOutputCP(originalOutCP)
```

Output: (Nim 0.15.2)
```nim
Hello, world! Best regards from Nim!
Здравей, ÑÐ²ÑÑ‚! ÐŸÐ¾Ð·Ð´Ñ€Ð°Ð²ÑÐ²Ð° Ñ‚е Nim
Hallo Welt, liebe Grüße von Nim

Hello, world! Best regards from Nim!
��дравей, ï¿½ï¿½Ð²ÑÑ‚! ï¿½ï¿½Ð¾Ð·Ð´Ñ€Ð°Ð²ÑÐ²Ð° Ñ‚е Nim
Hallo Welt, liebe Gr��ße von Nim
```

Other related posts: