当前位置:网站首页>d改进翻译
d改进翻译
2022-06-21 16:00:00 【fqbqrr】
原文结构可以是函子:
private @safe struct TranslatableStringPlural
{
string _str, _strpl;
this(string s1, string s2) {
// 必须的!
_str = s1;
_strpl = s2;
}
string opCall(int n)
{
auto fmt = ngettext(_str, _strpl, n);
if (countFormatSpecifiers(fmt) == 0)
// 改进该行.
return ()@trusted{
return fromStringz(&(format(fmt~"\0%s", n)[0])); }();
return format(fmt, n);
}
}
现在,变成:
private @safe struct Strplusarg {
this(string s) {
fmt = s;
auto fs = countFormatSpecifiers(fmt);
//修复这句.
assert(fs==0||fs==1,"无效");
hasArg = fs == 1;
}
string fmt;
bool hasArg;
}
private @safe struct TranslatableStringPlural
{
//...前略
string opCall(int n)
{
auto f = n == 1 ? _str : _strpl;
return f.hasArg ? format(f.fmt, n) : f.fmt;
}
}
原代码:
@safe: private:
int countFormatSpecifiers(string fmt) pure
{
int count = 0;
auto f = FormatSpec!char(fmt);
if (!__ctfe)
{
//有ctfe
while (f.writeUpToNextSpec(nullSink))
count++;
} else {
auto a = appender!string;
while (f.writeUpToNextSpec(a))
count++;
}
return count;
}
修复为:
@safe: private:
int countFormatSpecifiers(string fmt) pure
{
static void ns(const(char)[] arr) {
}
// 最简输出区间.
auto nullSink = &ns;
int count = 0;
auto f = FormatSpec!char(fmt);
while (f.writeUpToNextSpec(nullSink))
count++;
return count;
}
边栏推荐
- WDS must know and know
- Some thoughts learned recently are attached with answers, and further study and development of knowledge are required in the future.
- VNC Viewer方式的远程连接树莓派
- 关于cookie和session的一些理解
- string类的模拟实现
- 我敢闯 我会创!第八届“互联网 +”大赛GaussDB命题开放报名啦!
- Analysis on development details of NFT card chain game system
- Wechat applet tabbar usage
- Online shopping website (final assignment)
- 如何编写测试用例
猜你喜欢

How to write test cases

微信小程序开发入门教程-文本组件介绍

Cisco(59)——Hub&Spoke MPLS

Online JSON to yaml tool

Cisco(59)——Hub&Spoke MPLS

Serious illness insurance covers serious illness. Which product is the best in the market? Please recommend it

Google Play Academy 组队 PK 赛,正式开赛!
Go语言开发代码自测绝佳go fuzzing用法详解

The "learning link" database of the learning software is suspected to have leaked information, revealing more than 100million pieces of student information

Show you how to distinguish several kinds of parallelism
随机推荐
Web page automation practice 5. get the name, price and rating information of all hotels and write them into the file
2022年Q1手机银行用户规模达6.5亿,加强ESG个人金融产品创新
Esp8266 / esp32 obtenir la méthode NTP time via la Bibliothèque timelib
云原生监控系统·夜莺近期新功能一览,解决多个生产痛点
Web网页自动化实战《3.在艺龙网中,根据城市+日期+关键词精准匹配了酒店》下篇
Some understanding of cookies and sessions
Web page automation practice "3. in elong, hotels are accurately matched according to city + date + keyword" part 2
Advanced performance test series 6. problem solving and application development
聪明人:三不管、四不说、五不帮,古人为人处世之道
Go language development code self test excellent go fuzzing usage explanation
去中心化挖矿LP流动性DAPP系统开发案例
Web page automation practice "1. use the PY third-party library selenium to complete the access operation of elong"
Growth is not necessarily related to age
Daily appointment queue assistant | user manual
Development case of decentralized mining LP liquidity DAPP system
Google Earth engine (GEE) - sentinel-1 comprehensively check the difference between automatic landslide monitoring before and after two months (Guatemala as an example)
叩富网可以开期货账户吗?安全吗?
谷歌 Chrome 浏览器全新下载窗口将支持文件拖拽,Edge 已经支持
高级性能测试系列《1.思维差异、性能的概念、性能测试》
addslashes,stripslashes