Skip to content

Commit

Permalink
rc: support wide strings in inline block data for html, rcdata, user-…
Browse files Browse the repository at this point in the history
…defined
  • Loading branch information
nico committed Oct 14, 2024
1 parent 0e2ee6a commit e0d5f9b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
21 changes: 16 additions & 5 deletions res/rc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1867,13 +1866,25 @@ bool Parser::ParseRawData(std::vector<uint8_t>* 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
Expand Down
4 changes: 2 additions & 2 deletions res/test/custom_inline.rc
Original file line number Diff line number Diff line change
@@ -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" }
Expand All @@ -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
Expand Down
Binary file modified res/test/custom_inline.res
Binary file not shown.
4 changes: 1 addition & 3 deletions res/test/html_inline.rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
1 HTML { "foo" }
1 HTML { L"foo" }
1 HTML { "foo" "b" } // No trailing \0!
1 HTML { "foo" "ba" }
1 HTML { "foo" "bar" }
Expand All @@ -14,9 +15,6 @@
9 HTML { 8 "val1", 9 }
10 HTML { 8, "val1", 9 }

// FIXME:
//1 HTML { L"foo" }

11 HTML { 4L, 2L } // 32
12 HTML { 4l, 2L } // 32
13 HTML { 4labdf, 2L } // 32
Expand Down
Binary file modified res/test/html_inline.res
Binary file not shown.
4 changes: 1 addition & 3 deletions res/test/rcdata_inline.rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
1 RCDATA { "foo" }
1 RCDATA { L"foo" }
1 RCDATA { "foo" "b" } // No trailing \0!
1 RCDATA { "foo" "ba" }
1 RCDATA { "foo" "bar" }
Expand All @@ -14,9 +15,6 @@
9 RCDATA { 8 "val1", 9 }
10 RCDATA { 8, "val1", 9 }

// FIXME:
//1 RCDATA { L"foo" }

11 RCDATA { 4L, 2L } // 32
12 RCDATA { 4l, 2L } // 32
13 RCDATA { 4labdf, 2L } // 32
Expand Down
Binary file modified res/test/rcdata_inline.res
Binary file not shown.

0 comments on commit e0d5f9b

Please sign in to comment.