From e0d5f9bbfb399dbab065635531bec34afa5ba718 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 14 Oct 2024 14:18:23 -0400 Subject: [PATCH] rc: support wide strings in inline block data for html, rcdata, user-defined --- res/rc.cc | 21 ++++++++++++++++----- res/test/custom_inline.rc | 4 ++-- res/test/custom_inline.res | Bin 1380 -> 1492 bytes res/test/html_inline.rc | 4 +--- res/test/html_inline.res | Bin 1092 -> 1132 bytes res/test/rcdata_inline.rc | 4 +--- res/test/rcdata_inline.res | Bin 1092 -> 1132 bytes 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/res/rc.cc b/res/rc.cc index c5ec200..8fcbb90 100644 --- a/res/rc.cc +++ b/res/rc.cc @@ -12,7 +12,6 @@ bit-for-bit equal to what Microsoft rc.exe produces. It's ok if this program rejects some inputs that Microsoft rc.exe accepts. Missing for chromium: -- real string literal parser (L"\0") - preprocessor (but see pptest next to this; `pptest file | rc` kinda works) Also missing, but not yet for chromium: @@ -1867,13 +1866,25 @@ bool Parser::ParseRawData(std::vector* data) { } bool is_text_token = Is(Token::kString); if (is_text_token) { + bool is_wide = cur_token().value_[0] == 'L'; + std::string_view value_val = StringContents(Consume()); - // FIXME: 1-byte strings for "asdf", 2-byte for L"asdf". - for (size_t j = 0; j < value_val.size(); ++j) { - // FIXME: Real UTF16 support. - data->push_back(value_val[j]); + if (is_wide) { + C16string value_val_utf16; + if (!ToUTF16(&value_val_utf16, value_val, encoding_, &err_)) + return false; + + for (size_t j = 0; j < value_val_utf16.size(); ++j) { + // FIXME: This is gross and assumes little-endian-ness. + data->push_back(value_val_utf16[j] & 0xFF); + data->push_back(value_val_utf16[j] >> 8); + } + } else { + for (size_t j = 0; j < value_val.size(); ++j) + data->push_back(value_val[j]); } + // No implicit \0-termination in raw blocks. } else { // FIXME: The Is(Token::kInt) should probably be IsIntExprStart diff --git a/res/test/custom_inline.rc b/res/test/custom_inline.rc index 1e3824e..46a3190 100644 --- a/res/test/custom_inline.rc +++ b/res/test/custom_inline.rc @@ -1,4 +1,6 @@ 1 CUSTOM { "foo" } +1 CUSTOM { L"foo" } +1 CUSTOM { L"foo" "bar" L"baz" } 1 CSTOM { "foo" "b" } // No trailing \0! 1 CUOM { "foo" "ba" } 1 CUS { "foo" "bar" } @@ -14,8 +16,6 @@ 9 CUSTOM { 8 "val1", 9 } 10 CUSTOM { 8, "val1", 9 } -// FIXME: -//1 CUSTOM { L"foo" } 11 CUSTOM { 4L, 2L } // 32 12 CUSTOM { 4l, 2L } // 32 diff --git a/res/test/custom_inline.res b/res/test/custom_inline.res index 018d6d7fb51a11b3021fe4abe940d758415e8f61..461d243c7b96ece23a1c42c56322d584cd126bcb 100644 GIT binary patch delta 42 rcmaFDb%lFE03+K(MI8=?d>~|C;0Ln#!0e>Nq9leyhAM`Q{-Ue^;RFfZ delta 10 Rcmcb@{e){mz{Ue2tN~|CV3{~kd1J;MW&mlH2bBN- delta 15 XcmaFEafD-n3nR~|CV3{~kd1J;MW&mlH2bBN- delta 15 XcmaFEafD-n3nR