区域设置与编码(终端)之间有什么区别? [英] What is the difference between locale and Encoding ( Terminal )

查看:171
本文介绍了区域设置与编码(终端)之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了一些方法从c ++程序设置终端'encoding'。
我可以做的只是改变语言环境。或LANG变量。



仍然可以输入与LANG不同编码的字符(和nl_langinfo(CODESET)的输出)



但是,如果我去终端>设置字符编码> ISO-8859-15(或某事),那么它只允许ISO-8859-15。
我可以从我的C ++程序中获得同样的东西(从GUI设置)吗?



我用setlocale(LC_CTYPE,)来设置编码到终端编码,但它只是使用LANG变量,并允许其他字符。



(终端后设置字符编码> ISO-8859-1(Latin1) )

 > setenv LANG en_US.iso885915  - > latin9 
> ./ a.out
当前语言环境:C
Lang信息:ANSI_X3.4-1968
尝试将语言环境从C更改为
当前区域设置:en_US.iso885915
朗信息:ISO-8859-15
输入一些字符串:¤|¨'¸¼½¾dfsafas - >但这些都是拉丁文字符
输入的字符串:¤|¨'¸¼½¾dfsafas - >他们甚至打印回来!

所以,如果我对于语言环境和编码的理解是正确的话,这就引起了我的关注



有人可以澄清差异吗?

解决方案

编码是只有一部分区域设置和终端才会影响终端显示和处理输入。



终端编码和区域设置运行终端的程序几乎独立,可能不会匹配或可能配置错误。



setlocale()将设置或查询程序的当前区域设置。



终端通常产生一个新的shell,并且设置LANG或LC_ *环境变量将仅影响将使用此shell运行的程序。



同时设置区域设置或编码不会阻止其他字符要输入。



回答 shou ld帮助澄清事情。


I have tried a few ways to set the terminal 'encoding' from a c++ program. All I could do is to change the locale. or the LANG variable.

Still I am able to enter characters which are of different encoding than the LANG ( and output of nl_langinfo(CODESET) )

But , if I go to Terminal > Set Character Encoding > ISO-8859-15 ( or something ) then it is allowing only ISO-8859-15 . Can I achive the same thing ( setting from GUI ) from my C++ program as well ?

I used setlocale(LC_CTYPE,"") to set the encoding to the terminal encoding , but it just uses the LANG variable.And allows other characters too.

( After Terminal > Set Character Encoding > ISO-8859-1 ( Latin1 ) )

>setenv LANG en_US.iso885915 --> latin9
>./a.out 
Current Locale : C
Lang info : ANSI_X3.4-1968
Trying to change locale from C to ""
Current Locale : en_US.iso885915 
Lang info : ISO-8859-15
Enter some string :¤¦¨´¸¼½¾ dfsafas  --> but these are Latin1 charaters !!
Entered string : ¤¦¨´¸¼½¾ dfsafas --> They are even printed back !!

So , this brought me down to the question if my understanding about the locale and encoding are correct or not.

Can someone please clarify the difference?

解决方案

Encoding is only a part of locale settings and for terminals it affects how terminal displays and process input.

Terminal encoding and locale setting for a program running withing terminal pretty much independent and might not match or can be misconfigured.

setlocale() will set or query the program's current locale.

Terminals usually spawns a new shell and setting LANG or LC_* environment variables will affect only programs that will run withing this shell.

Also setting locale or encoding does not prevent "other" characters to be entered.

This answer should help to clarify things.

这篇关于区域设置与编码(终端)之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆