语言环境无关实施的strtod [英] Locale-independent strtod implementation

查看:146
本文介绍了语言环境无关实施的strtod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有需要解析双号,它总是用一个点的库'。作为小数点分隔符。不幸的是,这种情况下,strtod()做它尊重可能会使用不同的分隔的语言环境,因此分析可能会失败。我不能setlocale()的 - 它不是线程安全的。所以,我现在正在寻找一个干净的语言环境无关的strtod实现。我发现多个实现,到目前为止,但所有的人都看哈克或者仅仅是想坏code。
有人可以推荐一个经过良好测试,工作,清洁(ANSI)的C实现我?

I have a library which needs to parse double numbers which always use a point '.' as decimal separator. Unfortunately for this case, strtod() respects the locale which might use a different separator and thus parsing can fail. I can't setlocale() - it isn't thread-safe. So I'm searching for a clean locale-independent strtod implementation now. I have found multiple implementations so far, but all of them look hacky or just like bad code. Can someone recommend a well-tested, working, clean (ANSI) C implementation for me?

推荐答案

抓住一些已知的执行(即不依赖于 ATOF ),如一个分布式红宝石:
ruby​​_1_8 /失踪/ strtod.c

Grab some known implementation (that doesn't depend on atof), such as the one distributed with ruby: ruby_1_8/missing/strtod.c.

这篇关于语言环境无关实施的strtod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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