file error / encoding

来源:互联网 发布:淘宝申请延长收货时间 编辑:程序博客网 时间:2024/06/05 00:17
feof
*检测file是否遇到EOF
*返回0 没遇到结尾
*返回非0 file遇到结尾


ferror
*检测file目前是否有错误
*返回0 目前没有错误
*返回非0 有错误发生


clearerr
*reset error flag 以及EOF indicate
*没返回值
--------------------------------------------------------------
GB2312 ANSI DBCS 每个字1-2Bytes
Big5 ANSI DBCS 1-2Bytes
UTF-16 Unicode编码一种 UCS2 Wide Character 每个字2Bytes
UTF-8 Unicode编码一种 每个字1-6Bytes

---------------------------------------------------------------------------------------------------------------------

Double Byte Character System 有时专门指CJK

*有些字1Byte 有些字2Bytes

*第一个byte大于0x7F的话 后面的byte当成trail Byte

*例如 CE CC 31 32 33(翁123)

----------------------------------------------------------------------------------------------------------------------

UTF-8

每个字1-6Bytes 要看第一个Byte的8bit长相(开头有少个1 就有多少个车厢 包括自己在内)

*1: 0xxxxxxx

*2: 110xxxxx  10xxxxxx

*3: 1110xxxx 10xxxxxx 10xxxxxx

*4: 11110xxx 10xxxxxx  10xxxxxx 10xxxxxxx

*5: 111110xx  10xxxxx   10xxxxxx  10xxxxxxx  10xxxxxxx

*6: 1111110x  10xxxxx    10xxxxxx  10xxxxxxx  10xxxxxxx  10xxxxxxx

--------------------------------------------------------------------------------------------------------------------

wchar_t   2bytes

wcscpy(s, L"123")  类比 strcpy()

wcslen(返回告诉有多少个字 不是Byte, 1word = 2bytes) strlen


--------------------------------------------------------------------------------------------

File开头的BOM(Byte order mark)

前三个bytes EF BB BF    UTF-8

前两个bytes  FF FE   UCS2 big endian

前两个Bytes  FE FF UCS2 litttle endian

没找到  DBCS

-----------------------------------------------------------------------------------

怎么知道是GB2312 还是Big 5

办不到 不许事先知道

CE CC 31 32 33 (GB2312) 翁123

CE CC  31 32 33 (Big5) 123

AF CE 31 32 33 在Big5  翁123

AF CE 31 32 33 GB2312  ??123

---------------------------------------------------------------------

UTF-8 跟 UCS2  one-on-one mapping

DBCS 转 UCS2 查表 library

DBCS 转 UTF-8 查表UCS2 在转UTF-8 / library


Linux下 iconv

iconv -f UTF-8 -t UTF-16LE input.txt -o output.txt

iconv -f gb2312 -t UTF-8 input.txt -o output.txt

iconv 提供command line 也提供library


UTF8 转GB2312 不保证成功 毕竟UTF-8里面各国文字

------------------------------------------------------------------------

Internationalization I18N

*软件设计符合国际化的标准

*基本上最好是One Binary run globally


Localization L10N


G11N