{ yeah : 必须哒 } No place to place should record our youth?

2Aug/103

编译Ice-3.4.1出现undefined reference to `libiconv’的错误

Posted by alacner

编译到最high处,突然出现了这个错误
[cc lang='bash']
ransformVisitor.o Transformer.o transformdb.o ../FreezeScript/Grammar.o Scanner.o AssignVisitor.o Data.o Error.o Functions.o Exception.o Parser.o Print.o Util.o -lSlice -lIceXML -lFreeze -lIce -lIceUtil -lpthread -lrt -L/usr/lib64/db48 -ldb_cxx
../../lib/libIce.so: undefined reference to `libiconv'
../../lib/libIce.so: undefined reference to `libiconv_close'
../../lib/libIce.so: undefined reference to `libiconv_open'
[/cc]
ldconfig等等都试过了,都是对牛弹琴,愤怒了我,找到哪些地方用到了,发现一个 cpp/include/Ice/IconvStringConverter.h,呵呵include 了一个 iconv.h,然后我找到Makefile,他支持多系统make,找到cpp/config/Make.rules.Linux,在最显眼的地方【143行】在最后加上一个 -liconv,再次编译,通过了,
就这么纠结吗?不会自己加呀!

PS:Ice的网址:http://www.zeroc.com/icephp.html

Tagged as: , , , 3 Comments
2Aug/101

php字符转换全角转半角

Posted by ofeng

今天遇到字符转换的问题,发现用iconv(“gb2312”,”utf-8”,$string)这个函数的时候,如果string中含有全角字符,函数就会返回空。

首先查了下手册

string iconv ( string $in_charset , string $out_charset , string $str )

in_charset
The input charset.

out_charset
The output charset.

If you append the string //TRANSLIT to out_charset transliteration is activated. This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character.

加上 //TRANSLIT ,当一个字符无法被要转化的编码描述,找一个或者几个类似的字符替代,如果用 //IGNORE ,特殊字符会被直接丢弃,不加则会从非法字符后截断。果然会被咔嚓掉……

再看看string中的字符集,为啥会变成illegal character呢?

怀疑是string中的全角标点符号引起的,网上google了个php转换函数,试了一把,果然可以了

php全角转半角函数

/**
* 将一个字串中含有全角的数字字符、字母、空格或'%+-()'字符转换为相应半角字符
*
* @access public
* @param string $str 待转换字串
*
* @return string $str 处理后字串
*/
function make_semiangle($str)
{
$arr = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4',
'5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9',
'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E',
'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J',
'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O',
'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T',
'U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y',
'Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd',
'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i',
'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n',
'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's',
't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x',
'y' => 'y', 'z' => 'z',
'(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[',
'】' => ']', '〖' => '[', '〗' => ']', '“' => '[', '”' => ']',
'‘' => '[', '’' => ']', '{' => '{', '}' => '}', '《' => '<',
'》' => '>',
'%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-',
':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.',
';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|',
'”' => '"', '’' => '`', '‘' => '`', '|' => '|', '〃' => '"',
' ' => ' ');

return strtr($str, $arr);
}

全角与半角之区别(来自中文维基百科)

全角,又称全形、全宽,是电脑字符的一种格式,字面意思是比普通字符(或半角字符)宽的字符。

传统上,英语或拉丁字母语言使用一字节的空间来存储,而汉字、日语等常使用两字节存储,在使用固定宽度文字的地方,为了使字体看起来整齐,英文字母、数字及其他符号,也由原来只占用一个字空间,改为一概占用两个字的空间来显示,并且使用两个字节来存储。

回头想想,为啥全角就会出现问题呢?难道是字符集不一致……再度google

http://hi.baidu.com/clx2575167/blog/item/2f10071f3abdc3fee1fe0bfb.html

按照上面的介绍,utf-8的字符集应该是大于gb2312的,所以引起上述原因的肯定不是全角标点字符

狗日的,终于搜索到了,居然是iconv的bug,在转换到gb2312的过程中,如果碰到破折号'—'就会出现!