- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如函数的 C 引用页所述,c16rtomb
,来自 CPPReference ,在注释部分下:
In C11 as published, unlike
mbrtoc16
, which converts variable-width multibyte (such as UTF-8) to variable-width 16-bit (such as UTF-16) encoding, this function can only convert single-unit 16-bit encoding, meaning it cannot convert UTF-16 to UTF-8 despite that being the original intent of this function. This was corrected by the post-C11 defect report DR488.
在这段话的下方,C 引用页面提供了一个示例源代码,上面有以下句子:
Note: this example assumes the fix for the defect report 488 is applied.
这句话暗示有一种方法可以采用 DR488 并以某种方式将修复程序“应用”到 C11 标准函数 c16rtomb
.
我想知道如何为 GCC 应用修复程序。因为在我看来,从 v141 开始,该修复程序已应用于 Visual Studio 2017 Visual C++。
在 GCC 中看到的行为,在 GDB 中调试代码时,与在 DR488 中发现的一致,如下所示:
Section 7.28.1 describes the function c16rtomb(). In particular, it states "When c16 is not a valid wide character, an encoding error occurs". "wide character" is defined in section 3.7.3 as "value representable by an object of type wchar_t, capable of representing any character in the current locale". This wording seems to imply that, e.g. for the common cases (e.g, an implementation that defines __STDC_UTF_16__ and a program that uses an UTF-8 locale), c16rtomb() will return -1 when it encounters a character that is encoded as multiple char16_t (for UTF-16 a wide character can be encoded as a surrogate pair consisting of two char16_t). In particular, c16rtomb() will not be able to process strings generated by mbrtoc16().
粗体文字是所描述的行为。
#include
#include
#define __STD_UTF_16__
int chính() {
char16_t* ptr_string = (char16_t*) u"我是誰";
//C++ disallows variable-length arrays.
//GCC uses GNUC++, which has a C++ extension for variable length arrays.
//It is not a truly standard feature in C++ pedantic mode at all.
//https://stackoverflow.com/questions/40633344/variable-length-arrays-in-c14
char buffer[64];
char* bufferOut = buffer;
//Must zero this object before attempting to use mbstate_t at all.
mbstate_t multiByteState = {};
//c16 = 16-bit Characters or char16_t typed characters
//r = representation
//tomb = to Multi-Byte Strings
while (*ptr_string) {
char16_t character = *ptr_string;
size_t size = c16rtomb(bufferOut, character, &multiByteState);
if (size == (size_t) -1)
phá vỡ;
bufferOut += size;
ptr_string++;
}
size_t bufferOutSize = bufferOut - buffer;
printf("Size: %zu - ", bufferOutSize);
for (int i = 0; i < bufferOutSize; i++) {
printf("%#x ", +(unsigned char) buffer[i]);
}
//This statement is used to set a breakpoint. It does not do anything else.
int debug = 0;
trả về 0;
}
Size: 9 - 0xe6 0x88 0x91 0xe6 0x98 0xaf 0xe8 0xaa 0xb0
Size: 0 -
1 Câu trả lời
在 Linux 中,您应该可以通过调用 setlocale(LC_ALL, "en_US.utf8");
Về ideone 的示例
此函数将执行以下操作,如 Microsoft documentation Như đã nêu trong:
Convert a UTF-16 wide character into a multibyte character in the current locale.
POSIX 文档类似。 __STD_UTF_16__
在这两个编译器中似乎都没有效果。它应该指定源的编码,应该是 UTF16。它没有指定目的地的编码。
Windows 文档似乎更不一致,因为它似乎暗示 thiết lập ngôn ngữ
是必需的或转换为 ANSI 代码页是一个选项
关于C 统一码 : How do I apply C11 standard amendment DR488 fix to C11 standard function c16rtomb()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53148386/
我被这种奇怪的事情难住了。 假设我有这个数组: var array = [{ something: 'special' }, 'and', 'a', 'bunch', 'of', 'paramet
假设我们有这样的代码: let fn1 = Function.apply.bind(Math.max, null); fn1([1, 10, 5]); // returns 10 我知道它是 ES6
所以我尝试通过数据绑定(bind)调用我的 viewModel 原型(prototype)上的方法。我通过“单击”将两个不同的元素数据绑定(bind)到同一方法。当我单击第一个按钮(“新游戏”按钮)时
观察以下代码 trait Example { type O def apply(o: O) def f(o: O) = this.apply(o) } 在Scala中编译良好。我希望我可以
我知道 apply f in H 可用于将假设应用于函数,并且我知道 apply f with a b c 可用于提供参数直接应用 f 时,它无法自行推断。 是否可以以某种方式将两者结合使用? 最佳答
这个问题已经有答案了: How to override apply in a case class companion (10 个回答) 已关闭 6 年前。 我正在尝试重载案例类的 apply 方法:
我有一个自定义的Grails 4.x配置文件。我想为我的应用程序生成一个“apply from”条目。 apply from:"${rootProject.projectDir}/gradle/clo
传统上对象继承如下所示: function Parent() { console.log('parent constructor'); } Parent.prototype.method = f
今天在检查Jasmine 的源代码时here我偶然发现了以下内容: if (queueableFn.timeout) { timeoutId = Function.prototype.appl
据我所知,关键字new会使用this创建一个包含函数中定义的属性的对象。但我不知道如何应用 使用 apply 将其他函数链接到该函数。并且创建的对象在这些函数中具有属性。有人能弄清楚代码中发生了什么吗
我一直在我的 InitComponent 中使用 Ext.Apply,就像这样 Ext.apply(that, { xtype: 'form', items: [.
我们有数百个存储库,并定期从上游接收补丁。作业应用这些补丁 git apply --check .如果没有错误,则应用补丁 git apply 并且更改已提交。如果有任何错误,补丁将标记为 conf
我最近通过调用 console.log.toString() 查看了 firebugs console.log 的代码并得到了这个: function () { return Function.app
拿这个代码: $scope.$apply(function(){ $scope.foo = 'test'; }); 对比这个: $scope.foo = 'test'; $scope.$app
我在 Oracle-12c 中有一个类似于典型论坛的架构 accounts , posts , comments .我正在编写一个查询来获取... 一位用户 该用户的所有帖子 对每个帖子的评论 以及每
我试图更好地理解在 Angular 中使用 $timeout 服务作为一种“安全 $apply”方法的细微差别。基本上在一段代码可以运行以响应 Angular 事件或非 Angular 事件(例如 j
到目前为止,我使用的是 this当我有多个时间序列要预测时,我使用了 Hyndman 教授的方法。但是当我有大量的 ts 时它相当慢。 现在我正在尝试使用 apply() 函数,如下所示 librar
我听说过很多关于 pandas apply 很慢的说法,应该尽可能少用。 我这里有个情况: df = pd.DataFrame({'Date': ['2019-01-02', '2019-01-03'
在学习Javascript时,我尝试重新声明函数的apply属性。到目前为止没有问题。 function foo() { return 1; } alert(foo()); // 1 alert(fo
所以我正在做 learnRx http://reactive-extensions.github.io/learnrx/我有一个关于制作 mergeAll() 函数的问题(问题 10)。 这是我的答案
Tôi là một lập trình viên xuất sắc, rất giỏi!