Skip to content

Instantly share code, notes, and snippets.

@jpzhu
Last active August 29, 2015 14:01
Show Gist options
  • Save jpzhu/be45a44a58ad17341d99 to your computer and use it in GitHub Desktop.
Save jpzhu/be45a44a58ad17341d99 to your computer and use it in GitHub Desktop.
utf8 code gbk

在代码编译时,会碰到源码里有gbk编码的中文的注释,能够正常编译,但是warning 很多。
烦人啊~

iconv工具可以进行转码,但是我们得先判断某文件是否为标准utf8编码。
isutf8 命令可以可以做这个判断。 该命令来自于moreutils软件包。

for file in $(find . -name "*.[ch]" -o -name "*.cpp"  -o -name "*.java")
do
    if isutf8 $file
       then :
    else
       iconv -f gbk -t utf-8 $file  -o tmpfile
       cp tmpfile $file
    fi;
done

if [ -f tmpfile ]
    then rm tmpfile
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment