好的C字符串库 [英] Good C string library

查看:227
本文介绍了好的C字符串库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近受到启发,开始了一个我想编码一段时间的项目.我想在C语言中执行此操作,因为内存处理是此应用程序的关键.我一直在寻找C语言中字符串的良好实现,因为我知道我自己这样做可能会导致一些凌乱的缓冲区溢出,并且我希望处理大量字符串.

I recently got inspired to start up a project I've been wanting to code for a while. I want to do it in C, because memory handling is key this application. I was searching around for a good implementation of strings in C, since I know me doing it myself could lead to some messy buffer overflows, and I expect to be dealing with a fairly big amount of strings.

我发现这篇文章详细介绍了每篇文章,但似乎每篇文章都有一个有很多缺点(不要误会我的意思,这篇文章对您很有帮助,但仍然令我担心的是,即使我选择其中之一,也不会尽我所能).我也不知道这篇文章是最新的,因此我目前不满意.

I found this article which gives details on each, but they each seem like they have a good amount of cons going for them (don't get me wrong, this article is EXTREMELY helpful, but it still worries me that even if I were to choose one of those, I wouldn't be using the best I can get). I also don't know how up to date the article is, hence my current plea.

我正在寻找的东西可能包含大量字符,并简化了搜索字符串的过程.如果允许我以任何方式标记字符串,那就更好了.而且,它应该具有一些相当不错的I/O性能.打印和格式化打印不是最优先考虑的事情.我知道我不应该期望图书馆为我做所有的工作,但是只是徘徊着是否有一个记录在案的字符串函数可以为我节省一些时间和一些工作.

What I'm looking for is something that may hold a large amount of characters, and simplifies the process of searching through the string. If it allows me to tokenize the string in any way, even better. Also, it should have some pretty good I/O performance. Printing, and formatted printing isn't quite a top priority. I know I shouldn't expect a library to do all the work for me, but was just wandering if there was a well documented string function out there that could save me some time and some work.

任何帮助将不胜感激.预先感谢!

Any help is greatly appreciated. Thanks in advance!

有人问我我喜欢的许可证.任何形式的开源许可证都可以,但最好是GPL(v2或v3).

I was asked about the license I prefer. Any sort of open source license will do, but preferably GPL (v2 or v3).

EDIt2:我找到了BetterString(bstring)库,它看起来还不错.良好的文档资料,小的但多功能的功能,并且易于与c字符串混合使用.有人对此有好还是不好的故事?我唯一了解到的缺点是它缺少Unicode(再次阅读有关内容,尚未见过它),但是其他所有内容似乎都还不错.

EDIt2: I found betterString (bstring) library and it looks pretty good. Good documentation, small yet versatile amount of functions, and easy to mix with c strings. Anyone have any good or bad stories about it? The only downside I've read about it is that it lacks Unicode (again, read about this, haven't seen it face to face just yet), but everything else seems pretty good.

而且,最好是它的纯C.

Also, preferable that its pure C.

推荐答案

这是一个古老的问题,希望您已经找到了一个有用的问题.如果没有,请在 github 简单动态字符串库. >.我在此处复制并粘贴作者的描述:

It's an old question, I hope you have already found a useful one. In case you didn't, please check out the Simple Dynamic String library on github. I copy&paste the author's description here:

SDS是用于C的字符串库,旨在增强有限的libc字符串 通过添加堆分配的字符串来处理功能:

SDS is a string library for C designed to augment the limited libc string handling functionalities by adding heap allocated strings that are:

  • 简单易用.
  • 二进制保险箱.
  • 计算效率更高.
  • 但是...与普通的C字符串函数兼容.

这是通过使用替代设计来实现的,其中使用C代替 表示字符串的结构,我们使用存储的二进制前缀 在指向由SDS返回给用户的字符串的实际指针之前.

This is achieved using an alternative design in which instead of using a C structure to represent a string, we use a binary prefix that is stored before the actual pointer to the string that is returned by SDS to the user.

+--------+-------------------------------+-----------+
| Header | Binary safe C alike string... | Null term |
+--------+-------------------------------+-----------+
         |
         `-> Pointer returned to the user.

由于元数据存储在实际返回的指针之前作为前缀, 并且由于每个SDS字符串在末尾隐式添加一个空项 字符串,无论字符串的实际内容如何,​​SDS字符串均有效 很好地与C字符串一起使用,用户可以自由地互换使用它们 带有以只读方式访问字符串的实时函数.

Because of meta data stored before the actual returned pointer as a prefix, and because of every SDS string implicitly adding a null term at the end of the string regardless of the actual content of the string, SDS strings work well together with C strings and the user is free to use them interchangeably with real-only functions that access the string in read-only.

这篇关于好的C字符串库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆