Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22609.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Text.Encoding.Extensions.Tests", "tests\System.Text.Encoding.Extensions.Tests.csproj", "{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}"
ProjectSection(ProjectDependencies) = postProject
{} = {}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<IsNETCoreApp>true</IsNETCoreApp>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp;
uap;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,166 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ------------------------------------------------------------------------------
// Changes to this file must follow the http://aka.ms/api-review process.
// ------------------------------------------------------------------------------
namespace System.Text
{
public partial class ASCIIEncoding : System.Text.Encoding
{
public ASCIIEncoding() { }
public override bool IsSingleByte { get { throw null; } }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetByteCount(char* chars, int count) { throw null; }
public override int GetByteCount(char[] chars, int index, int count) { throw null; }
public override int GetByteCount(string chars) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { throw null; }
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
public override int GetBytes(string chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetCharCount(byte* bytes, int count) { throw null; }
public override int GetCharCount(byte[] bytes, int index, int count) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { throw null; }
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { throw null; }
public override System.Text.Decoder GetDecoder() { throw null; }
public override System.Text.Encoder GetEncoder() { throw null; }
public override int GetMaxByteCount(int charCount) { throw null; }
public override int GetMaxCharCount(int byteCount) { throw null; }
public override string GetString(byte[] bytes, int byteIndex, int byteCount) { throw null; }
}
public partial class UnicodeEncoding : System.Text.Encoding
{
public const int CharSize = 2;
public UnicodeEncoding() { }
public UnicodeEncoding(bool bigEndian, bool byteOrderMark) { }
public UnicodeEncoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes) { }
public override bool Equals(object value) { throw null; }
public override int GetByteCount(char[] chars, int index, int count) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetByteCount(char* chars, int count) { throw null; }
public override int GetByteCount(string s) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { throw null; }
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetCharCount(byte* bytes, int count) { throw null; }
public override int GetCharCount(byte[] bytes, int index, int count) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { throw null; }
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { throw null; }
public override System.Text.Decoder GetDecoder() { throw null; }
public override System.Text.Encoder GetEncoder() { throw null; }
public override int GetHashCode() { throw null; }
public override int GetMaxByteCount(int charCount) { throw null; }
public override int GetMaxCharCount(int byteCount) { throw null; }
public override byte[] GetPreamble() { throw null; }
public override string GetString(byte[] bytes, int index, int count) { throw null; }
}
public sealed partial class UTF32Encoding : System.Text.Encoding
{
public UTF32Encoding() { }
public UTF32Encoding(bool bigEndian, bool byteOrderMark) { }
public UTF32Encoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidCharacters) { }
public override bool Equals(object value) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetByteCount(char* chars, int count) { throw null; }
public override int GetByteCount(char[] chars, int index, int count) { throw null; }
public override int GetByteCount(string s) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { throw null; }
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetCharCount(byte* bytes, int count) { throw null; }
public override int GetCharCount(byte[] bytes, int index, int count) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { throw null; }
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { throw null; }
public override System.Text.Decoder GetDecoder() { throw null; }
public override System.Text.Encoder GetEncoder() { throw null; }
public override int GetHashCode() { throw null; }
public override int GetMaxByteCount(int charCount) { throw null; }
public override int GetMaxCharCount(int byteCount) { throw null; }
public override byte[] GetPreamble() { throw null; }
public override string GetString(byte[] bytes, int index, int count) { throw null; }
}
public partial class UTF7Encoding : System.Text.Encoding
{
public UTF7Encoding() { }
public UTF7Encoding(bool allowOptionals) { }
public override bool Equals(object value) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetByteCount(char* chars, int count) { throw null; }
public override int GetByteCount(char[] chars, int index, int count) { throw null; }
public override int GetByteCount(string s) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { throw null; }
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetCharCount(byte* bytes, int count) { throw null; }
public override int GetCharCount(byte[] bytes, int index, int count) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { throw null; }
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { throw null; }
public override System.Text.Decoder GetDecoder() { throw null; }
public override System.Text.Encoder GetEncoder() { throw null; }
public override int GetHashCode() { throw null; }
public override int GetMaxByteCount(int charCount) { throw null; }
public override int GetMaxCharCount(int byteCount) { throw null; }
public override string GetString(byte[] bytes, int index, int count) { throw null; }
}
public partial class UTF8Encoding : System.Text.Encoding
{
public UTF8Encoding() { }
public UTF8Encoding(bool encoderShouldEmitUTF8Identifier) { }
public UTF8Encoding(bool encoderShouldEmitUTF8Identifier, bool throwOnInvalidBytes) { }
public override bool Equals(object value) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetByteCount(char* chars, int count) { throw null; }
public override int GetByteCount(char[] chars, int index, int count) { throw null; }
public override int GetByteCount(string chars) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount) { throw null; }
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
public override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetCharCount(byte* bytes, int count) { throw null; }
public override int GetCharCount(byte[] bytes, int index, int count) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount) { throw null; }
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) { throw null; }
public override System.Text.Decoder GetDecoder() { throw null; }
public override System.Text.Encoder GetEncoder() { throw null; }
public override int GetHashCode() { throw null; }
public override int GetMaxByteCount(int charCount) { throw null; }
public override int GetMaxCharCount(int byteCount) { throw null; }
public override byte[] GetPreamble() { throw null; }
public override string GetString(byte[] bytes, int index, int count) { throw null; }
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="System.Text.Encoding.Extensions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.Text.Encoding\ref\System.Text.Encoding.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
net463-Windows_NT;
netcoreapp;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<AssemblyName>System.Text.Encoding.Extensions</AssemblyName>
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
</PropertyGroup>
<!-- Help VS understand available configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(TargetGroup)' == 'netcore50aot'">
<ProjectJson>netcore50aot/project.json</ProjectJson>
<ProjectLockJson>netcore50aot/project.lock.json</ProjectLockJson>
</PropertyGroup>
<ItemGroup>
<TargetingPackReference Include="mscorlib" Condition="'$(TargetGroup)' == 'net463'" />
<TargetingPackReference Include="System.Private.CoreLib" Condition="'$(TargetGroup)' == 'netcoreapp'" />
</ItemGroup>
<ItemGroup>
<ReferenceFromRuntime Include="System.Private.CoreLib" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netstandard1.3;
netstandard;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,160 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Xunit;
using System;
using System.Text;
namespace EncodingTests
{
public static class Fallback
{
private static readonly string s_asciiInputStringWithFallback = "\u00abX\u00bb"; // DOUBLE ANGLE QUOTATION MARK (U+00AB), 'X' (U+0058), and RIGHT POINTING DOUBLE ANGLE QUOTATION MARK (U+00BB).
private static readonly string s_asciiInputStringWinNoFallback = "abc";
[Fact]
public static void TestEncoderReplacementFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderReplacementFallback("(unknown)"), new DecoderReplacementFallback(""));
byte[] encodedBytes = new byte[asciiEncoding.GetByteCount(s_asciiInputStringWithFallback)];
int numberOfEncodedBytes = asciiEncoding.GetBytes(s_asciiInputStringWithFallback, 0, s_asciiInputStringWithFallback.Length, encodedBytes, 0);
Assert.Equal(
encodedBytes,
new byte[] {0x28, 0x75, 0x6E, 0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x29, 0x58, 0x28, 0x75, 0x6E, 0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x29 });
string decodedString = asciiEncoding.GetString(encodedBytes);
Assert.Equal(decodedString, "(unknown)X(unknown)");
// Test when the fallback will not occur
encodedBytes = new byte[asciiEncoding.GetByteCount(s_asciiInputStringWinNoFallback)];
numberOfEncodedBytes = asciiEncoding.GetBytes(s_asciiInputStringWinNoFallback, 0, s_asciiInputStringWinNoFallback.Length, encodedBytes, 0);
Assert.Equal(encodedBytes, new byte[] { (byte)'a', (byte)'b', (byte)'c' });
decodedString = asciiEncoding.GetString(encodedBytes);
Assert.Equal(decodedString, s_asciiInputStringWinNoFallback);
}
[Fact]
public static void TestDecoderReplacementFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderReplacementFallback("(unknown)"), new DecoderReplacementFallback("Error"));
Assert.Equal(asciiEncoding.GetString(new byte [] { 0xAA, (byte)'x', 0xAB }), "ErrorxError");
}
[Fact]
public static void TestEncoderExceptionFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderExceptionFallback(), new DecoderExceptionFallback());
Assert.Throws<EncoderFallbackException>(() => asciiEncoding.GetByteCount(s_asciiInputStringWithFallback));
}
[Fact]
public static void TestDecoderExceptionFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderExceptionFallback(), new DecoderExceptionFallback());
Assert.Throws<DecoderFallbackException>(() => asciiEncoding.GetString(new byte [] { 0xAA, (byte)'x', 0xAB }));
}
[Fact]
public static void TestCustomFallback()
{
Encoding asciiEncoding = Encoding.GetEncoding("us-ascii", new EncoderCustomFallback(), new DecoderReplacementFallback(""));
byte[] encodedBytes = new byte[asciiEncoding.GetByteCount(s_asciiInputStringWithFallback)];
int numberOfEncodedBytes = asciiEncoding.GetBytes(s_asciiInputStringWithFallback, 0, s_asciiInputStringWithFallback.Length, encodedBytes, 0);
Assert.Equal(
encodedBytes,
new byte[] {(byte) 'a', 0x58, (byte) 'b'});
string decodedString = asciiEncoding.GetString(encodedBytes);
Assert.Equal(decodedString, "aXb");
}
}
// a simple fallback class which fallback using the character sequence 'a', 'b', 'c',...etc.
internal sealed class EncoderCustomFallback : EncoderFallback
{
public EncoderCustomFallback()
{
}
public string DefaultString
{
get { return " "; }
}
public override EncoderFallbackBuffer CreateFallbackBuffer()
{
return new EncoderCustomFallbackBuffer();
}
public override int MaxCharCount
{
get { return 1; }
}
public override bool Equals(Object value)
{
return value is EncoderCustomFallback;
}
public override int GetHashCode()
{
return "EncoderCustomFallback".GetHashCode();
}
}
internal sealed class EncoderCustomFallbackBuffer : EncoderFallbackBuffer
{
private int _nextChar;
private bool _fallback;
public EncoderCustomFallbackBuffer()
{
_fallback = false;
_nextChar = (int)'a' - 1;
}
public override bool Fallback(char charUnknown, int index)
{
_fallback = true;
return true;
}
public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
{
_fallback = true;
return true;
}
public override char GetNextChar()
{
if (!_fallback)
return (char)0;
_fallback = false;
return (char)++_nextChar;
}
public override bool MovePrevious()
{
return --_nextChar >= (int)'a' - 1;
}
public override int Remaining
{
get { return 0; }
}
public override void Reset()
{
_fallback = false;
_nextChar = (int)'a' - 1;
}
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.Text.Encoding.Extensions.Tests.csproj" />
<Project Include="System.Text.Encoding.Extensions.Tests.csproj">
<TargetGroup>netstandard1.3</TargetGroup>
<TestTFMs>netcoreapp1.0</TestTFMs>
</Project>
<Project Include="System.Text.Encoding.Extensions.Tests.csproj">
<TargetGroup>netstandard1.3</TargetGroup>
<OSGroup>Windows_NT</OSGroup>
<TestTFMs>netcore50;net46</TestTFMs>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{9574CEEC-5554-411B-B44C-6CA9EC1CEB08}</ProjectGuid>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="Fallback.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>