Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use regular expression instead of hand written strchr search #22

Open
microcai opened this issue Jul 24, 2013 · 11 comments
Open

use regular expression instead of hand written strchr search #22

microcai opened this issue Jul 24, 2013 · 11 comments

Comments

@microcai
Copy link

I seen a lot of hand written code to match the returning results of webqq server. However, such code can be easily replaced by one line regular expression match.

example:
get_verify_code can use this regular expression

"ptui_checkVC('([\d])',[ ]?'([\d\A\a!])',[ ]?'([\d\a\A\])'"

and to parse the do_login result, this regular expression can be used

"ptuiCB('([\d])',[ ]?'([\d])',[ ]?'([^'])',[ ]?'([\d])',[ ]?'([^'])',[ ]?'([^'])'[ ]);"

@mathslinux
Copy link
Owner

Cc xiehuc, the maintainer of lwqq/pidgin-lwqq

On Wed, Jul 24, 2013 at 10:33 AM, microcai [email protected] wrote:

I seen a lot of hand written code to match the returning results of webqq
server. However, such code can be easily replaced by one line regular
expression match.

example:
get_verify_code can use this regular expression

"ptui_checkVC('([\d])',[ ]?'([\d\A\a!])',[ ]?'([\d\a\A])'"

and to parse the do_login result, this regular expression can be used

"ptuiCB('([\d])',[ ]?'([\d])',[ ]?'([^'])',[ ]?'([\d])',[ ]?'([^'])',[
]?'([^'])'[ ]);"


Reply to this email directly or view it on GitHubhttps://github.com//issues/22
.

Best Regards,

Dunrong Huang

Homepage: http://mathslinux.org

@mathslinux
Copy link
Owner

Cc xiehuc, the maintainer of lwqq/pidgin-lwqq

On Wed, Jul 24, 2013 at 10:35 AM, microcai [email protected] wrote:

you can see example code in

https://github.com/avplayer/avbot/blob/master/libwebqq/impl/webqq_login.hpp

and in

https://github.com/avplayer/avbot/blob/master/libwebqq/impl/webqq_check_login.hpp


Reply to this email directly or view it on GitHubhttps://github.com//issues/22#issuecomment-21460157
.

Best Regards,

Dunrong Huang

Homepage: http://mathslinux.org

@xiehuc
Copy link
Collaborator

xiehuc commented Jul 24, 2013

do simple job strstr is enough. and speed is much faster than regular
expression.
and you don't need import huge regex library into lwqq.

2013/7/24 mathslinux [email protected]

Cc xiehuc, the maintainer of lwqq/pidgin-lwqq

On Wed, Jul 24, 2013 at 10:35 AM, microcai [email protected]
wrote:

you can see example code in

https://github.com/avplayer/avbot/blob/master/libwebqq/impl/webqq_login.hpp

and in

https://github.com/avplayer/avbot/blob/master/libwebqq/impl/webqq_check_login.hpp


Reply to this email directly or view it on GitHub<
https://github.com/mathslinux/lwqq/issues/22#issuecomment-21460157>
.

Best Regards,

Dunrong Huang

Homepage: http://mathslinux.org

Reply to this email directly or view it on GitHubhttps://github.com//issues/22#issuecomment-21461229
.

@microcai
Copy link
Author

@xiehuc

well the "speed exclusive" is just BS.

and you won't even import huge regex library into lwqq, posix just have it. glibc has regex functionality right from the start.

the code seem to be simple, but definitely not elegant .

@xiehuc
Copy link
Collaborator

xiehuc commented Jul 24, 2013

  1. 如果很多地方重度的依赖正则,那肯定是应该的。比如 "合并漫游记录" 就的确需要正则。
  2. 既然现在工作的比较好,那就没有动力去用一种等价的形式去重写它,而且是在目标基本上不更改的频率下。
  3. 需要考虑到跨平台之类的,在windows上用posix还是glibc的正则,效果未知
  4. 我并不熟悉posix和glibc的正则,要是改写的话,不仅不能保证正确性,还可能造成反面的效果。
  5. 如果使用正则并不会引入库的话,那就应该不会和 @mathslinux 的设计原则相冲突。
    不是不用正则,而是考虑到更换成正则需要的精力太多。要是有人贡献代码的话,那就另当别论了。

2013/7/24 microcai [email protected]

@xiehuc https://github.com/xiehuc

well the "speed exclusive" is just BS.

and you won't even import huge regex library into lwqq, posix just have
it. glibc has regex functionality right from the start.

the code seem to be simple, but definitely not elegant .


Reply to this email directly or view it on GitHubhttps://github.com//issues/22#issuecomment-21472979
.

@microcai
Copy link
Author

如果当心 windows 下的 libc 没有 regex 支持, 可以使用 glib. pidgin 依赖 glib , 因此完全可以使用 glib 里的 regex

@xiehuc
Copy link
Collaborator

xiehuc commented Jul 24, 2013

edo,

虽然pidgin-lwqq是依赖的glib,
但是lwqq并不依赖glib @mathslinux 一开始就是这样打算的。

2013/7/24 microcai [email protected]

如果当心 windows 下的 libc 没有 regex 支持, 可以使用 glib. pidgin 依赖 glib , 因此完全可以使用
glib 里的 regex


Reply to this email directly or view it on GitHubhttps://github.com//issues/22#issuecomment-21480021
.

@mathslinux
Copy link
Owner

2013/7/24 xiehuc [email protected]

edo,

虽然pidgin-lwqq是依赖的glib,
但是lwqq并不依赖glib @mathslinux 一开始就是这样打算的。

因为当时我觉得没有必要, 这么一个小东西(解析 webqq2/3 协议, 还有什么?), lwqq 最开始设想的就是一个简单的C库,
没必要依赖那么多东西, 我之前也参与了gtkqq的开发,
那个libqq依赖关系太差了.

而且我当时还设想让 lwqq 在没有 glib 的环境下用(有的机器除了kernel和基本的开发库, 就什么也没有了, 比如我们公司的某些服务器)

当时的 API 由于时间关系我没有设计异步的版本, 而且很多 hardcode, 但是这点 @xiehuc 已经解决得很好了, 参见他的
pidgin-lwqq 项目.

anyway, patches are welcome!

2013/7/24 microcai [email protected]

如果当心 windows 下的 libc 没有 regex 支持, 可以使用 glib. pidgin 依赖 glib , 因此完全可以使用
glib 里的 regex


Reply to this email directly or view it on GitHub<
https://github.com/mathslinux/lwqq/issues/22#issuecomment-21480021>
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/22#issuecomment-21481726
.

Best Regards,

Dunrong Huang

Homepage: http://mathslinux.org

@microcai
Copy link
Author

@xiehuc 如今 lwqq 都依赖上 js 引擎了, 区区一个 regex 就不在话下了吧。。。。。。

@xiehuc
Copy link
Collaborator

xiehuc commented Mar 13, 2015

是, 但是还是感觉用了regex 没有什么本质的变化啊. 其实现在这样也挺易读的. 性能方面也没什么问题.

2015-03-13 12:54 GMT+08:00 microcai [email protected]:

@xiehuc https://github.com/xiehuc 如今 lwqq 都依赖上 js 引擎了, 区区一个 regex
就不在话下了吧。。。。。。


Reply to this email directly or view it on GitHub
#22 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants