Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Windows active code page instead of UTF8 for decoding narrow characters #764

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Microsoft.Windows.CsWin32/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4938,15 +4938,15 @@ private IEnumerable<MethodDeclarationSyntax> DeclareFriendlyOverloads(MethodDefi
parameters[param.SequenceNumber - 1] = externParam
.WithType(PredefinedType(TokenWithSpace(SyntaxKind.StringKeyword)));

// fixed (byte* someLocal = some is object ? System.Text.Encoding.UTF8.GetBytes(some) : null)
// fixed (byte* someLocal = some is object ? System.Text.Encoding.Default.GetBytes(some) : null)
fixedBlocks.Add(VariableDeclaration(PointerType(PredefinedType(Token(SyntaxKind.ByteKeyword)))).AddVariables(
VariableDeclarator(localName.Identifier).WithInitializer(EqualsValueClause(
ConditionalExpression(
BinaryExpression(SyntaxKind.IsExpression, origName, PredefinedType(Token(SyntaxKind.ObjectKeyword))),
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
ParseTypeName("global::System.Text.Encoding.UTF8"),
ParseTypeName("global::System.Text.Encoding.Default"),
IdentifierName(nameof(Encoding.GetBytes))))
.WithArgumentList(
ArgumentList(
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Windows.CsWin32/templates/PCSTR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal int Length
/// Returns a <see langword="string"/> with a copy of this character array, decoding as UTF-8.
/// </summary>
/// <returns>A <see langword="string"/>, or <see langword="null"/> if <see cref="Value"/> is <see langword="null"/>.</returns>
public override string ToString() => this.Value is null ? null : new string((sbyte*)this.Value, 0, this.Length, global::System.Text.Encoding.UTF8);
public override string ToString() => this.Value is null ? null : new string((sbyte*)this.Value, 0, this.Length, global::System.Text.Encoding.Default);

#if canUseSpan
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Windows.CsWin32/templates/PCZZSTR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal int Length
/// Returns a <see langword="string"/> with a copy of this character array, decoding as UTF-8.
/// </summary>
/// <returns>A <see langword="string"/>, or <see langword="null"/> if <see cref="Value"/> is <see langword="null"/>.</returns>
public override string ToString() => this.Value is null ? null : new string((sbyte*)this.Value, 0, this.Length, global::System.Text.Encoding.UTF8);
public override string ToString() => this.Value is null ? null : new string((sbyte*)this.Value, 0, this.Length, global::System.Text.Encoding.Default);

#if canUseSpan
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion test/GenerationSandbox.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public void StructCharFieldsMarshaledAsUtf16()
}

[Fact]
public void CHAR_MarshaledAsUtf8()
public void CHAR_MarshaledAsAnsi()
{
Assert.Equal(1, Marshal.SizeOf<CHAR>());
}
Expand Down