存档

‘开源’ 分类的存档

实现c++中类似php的explode函数

2010年11月27日 没有评论

20110316更新:发现自己太土了,居然不知道有strtok 这么一个函数,可以实现类似的功能。 strtok 函数描述如下:(下面英文内容,完全来自于http://www.cplusplus.com/reference/clibrary/cstring/strtok/ ,更多内容和代码示例参加此处)

char * strtok ( char * str, const char * delimiters );

Split string into tokens
A sequence of calls to this function split str into tokens, which are sequences of contiguous characters separated by any of the characters that are part of delimiters.

On a first call, the function expects a C string as argument for str, whose first character is used as the starting location to scan for tokens. In subsequent calls, the function expects a null pointer and uses the position right after the end of last token as the new starting location for scanning.

To determine the beginning and the end of a token, the function first scans from the starting location for the first character not contained in delimiters (which becomes thebeginning of the token). And then scans starting from this beginning of the token for the first character contained in delimiters, which becomes the end of the token.

This end of the token is automatically replaced by a null-character by the function, and the beginning of the token is returned by the function.

Once the terminating null character of str has been found in a call to strtok, all subsequent calls to this function with a null pointer as the first argument return a null pointer.

Parameters

str
C string to truncate. The contents of this string are modified and broken into smaller strings (tokens).
Alternativelly, a null pointer may be specified, in which case the function continues scanning where a previous successful call to the function ended.
delimiters
C string containing the delimiters.
These may vary from one call to another.

Return Value

A pointer to the last token found in string.
A null pointer is returned if there are no tokens left to retrieve.

—————————-我是华丽的分界线—————————————————————
写习惯了php,发现explode很好用,而c++中没有,写了一个。

1
2
3
4
5
6
7
8
9
10
11
12
13
vector<string> explode(const char * probe,  char * data)
{
 string dataStr(data);
 int pos1 = 0;
 int pos2 = 0;
 vector<string> result;
 while((pos2=dataStr.find(probe,pos1)) != string::npos){
 result.push_back(dataStr.substr(pos1,pos2-(pos1+1)));
 pos1=pos2+1;
 }
 result.push_back(dataStr.substr(pos1));
 return result;
}

Popularity: 12%

分类: 开源, C++ 标签:

LinuxQuestions.org评出的2009年开源系统

2010年3月3日 没有评论

LinuxQuestions.org的注册成员评出了2009年开源系统、软件方面的佼佼者。在这里我仅对各个奖项简单翻译了一下。

2009 LinuxQuestions.org Members Choice Award Winners

The polls are closed and the results are in. We had a record number of votes cast for the ninth straight year. Congratulations should go to each and every nominee. We once again had some extremely close races and a couple multi-year winners were unseated. The official results:

Desktop Distribution of the Year(桌面系统) – Ubuntu (30.13%)
Server Distribution of the Year(服务器) – Debian (24.24%)
Security/Forensic/Rescue Distribution of the Year(系统恢复盘) – BackTrack (43.48%)
Database of the Year – MySQL(数据库) (60.81%)
Office Suite of the Year (办公套件)- OpenOffice.org (90.76%)
Browser of the Year(浏览器) – Firefox (65.21%)
Desktop Environment of the Year(桌面环境) – Gnome (41.96%)
Window Manager of the Year(窗口管理器) – Compiz (23.10%)
Messaging App of the Year(即时通讯) – Pidgin (48.74%)
Mail Client of the Year(邮件客户端) – Thunderbird (53.48%)
Virtualization Product of the Year(虚拟机产品) – VirtualBox (67.43%)
Audio Media Player Application of the Year(音频播放器) – Amarok (38.81%)
Audio Authoring Application of the Year(音频编辑器) – Audacity (77.26%)
Video Media Player Application of the Year(视频播放器) – VLC (46.05%)
Video Authoring Application of the Year(视频编辑器) – FFmpeg (21.94%)
Multimedia Utility of the Year (多媒体工具)- GStreamer (32.84%)
Graphics Application of the Year(图像软件) – GIMP (66.48%)
Network Security Application of the Year(网络安全) – Nmap Security Scanner (29.85%)
Host Security Application of the Year(主机安全) – SELinux (39.26%)
Network Monitoring Application of the Year(网络监视) – Nagios (51.11%)
IDE/Web Development Editor of the Year(IDE/网页开发) – Eclipse (23.28%)
Text Editor of the Year(文本编辑器) – vim (35.29%)
File Manager of the Year(文件管理器) – Nautilus (24.92%)
Open Source Game of the Year(开源游戏) – Battle for Wesnoth (15.45%)
Programming Language of the Year(编程语言) – Python (27.59%)
Backup Application of the Year(备份工具) – rsync (48.99%)
Open Source CMS/Blogging platform of the Year(开源内容管理系统/博客平台) – WordPress (45.20%)

If you have any questions or suggestions on how we can improve the MCA’s next year, do let me know. Visit http://www.linuxquestions.org/questi…ice-awards-91/ for the full poll results.
–jeremy

无觅相关文章插件

Popularity: 3%

分类: 开源 标签: ,