diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index ef0d3ca..c5f7e90 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -60,7 +60,7 @@ representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at devcommunity@dodopizza.com. +reported to the community leaders responsible for enforcement at r.bukin@dodobrands.io. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index ad17960..d37fd33 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -34,4 +34,4 @@ This project has adopted the [Code of Conduct](./CODE_OF_CONDUCT.md). ## NuGet package release process for repository owners and collaborators -You can find latest releases on the [releases pane](https://github.com/dodopizza/primitives/releases) or NuGet repository. \ No newline at end of file +You can find latest releases on the [releases pane](https://github.com/dodobrands/primitives/releases) or NuGet repository. \ No newline at end of file diff --git a/.github/images/logo.png b/.github/images/logo.png index afea41e..0cfecd4 100644 Binary files a/.github/images/logo.png and b/.github/images/logo.png differ diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index 09302f4..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - schedule: - - cron: "37 1 * * 3" - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ csharp ] - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - queries: +security-and-quality - - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index d57d8c0..47c8012 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -6,14 +6,14 @@ on: jobs: compare-version: name: Compare versions in current branch and main - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest if: ${{ !contains(github.event.commits[0].message, '[skip ci]') }} env: DOTNET_NOLOGO: true DOTNET_CLI_TELEMETRY_OPTOUT: true steps: - name: Checkout source branch - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.sha }} - name: Get source branch version @@ -34,7 +34,7 @@ jobs: echo "version_with_suffix_src=${version_with_suffix}" >> $GITHUB_ENV echo "has_suffix_src=${has_suffix}" >> $GITHUB_ENV - name: Checkout target branch - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.base_ref }} - name: Get target branch version @@ -54,12 +54,12 @@ jobs: fi echo "version_with_suffix_dst=${version_with_suffix}" >> $GITHUB_ENV echo "has_suffix_dst=${has_suffix}" >> $GITHUB_ENV - - name: Setup .NET Core SDK 7.0.400 - uses: actions/setup-dotnet@v3 + - name: Setup .NET Core SDK 8.0.101 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 7.0.400 + dotnet-version: 8.0.101 - name: Checkout source branch back - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.sha }} - name: Compare versions @@ -69,7 +69,7 @@ jobs: shell: bash run: | dotnet publish -c Release ./tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj - source_more_than_target=$(dotnet ./tools/Dodo.Primitives.Tools.CompareVersions/bin/Release/net7.0/publish/Dodo.Primitives.Tools.CompareVersions.dll "${source_version}" "${target_version}") + source_more_than_target=$(dotnet ./tools/Dodo.Primitives.Tools.CompareVersions/bin/Release/net8.0/publish/Dodo.Primitives.Tools.CompareVersions.dll "${source_version}" "${target_version}") last_exit_code=$(printf "%d" $?) source_more_than_target=$(printf "%s" $source_more_than_target) if [ "$last_exit_code" -ne 0 ] @@ -97,24 +97,24 @@ jobs: run-tests: name: Run tests needs: compare-version - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest if: ${{ !contains(github.event.commits[0].message, '[skip ci]') }} env: DOTNET_NOLOGO: true DOTNET_CLI_TELEMETRY_OPTOUT: true steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.sha }} - - name: Setup .NET Core SDK 6.0.413 - uses: actions/setup-dotnet@v3 + - name: Setup .NET Core SDK 6.0.418 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.413 - - name: Setup .NET Core SDK 7.0.400 - uses: actions/setup-dotnet@v3 + dotnet-version: 6.0.418 + - name: Setup .NET Core SDK 8.0.101 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 7.0.400 + dotnet-version: 8.0.101 - name: Create coverage directory and promote absolute paths to env shell: bash run: | @@ -130,18 +130,20 @@ jobs: echo "cover_net6_hw=${PATH_NET6_HW}" >> $GITHUB_ENV echo "cover_net6_hw_merge=${PATH_NET6_HW}.net6.0.json" >> $GITHUB_ENV - PATH_NET7_NOHW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net7nohw" - echo "cover_net7_nohw=${PATH_NET7_NOHW}" >> $GITHUB_ENV - echo "cover_net7_nohw_merge=${PATH_NET7_NOHW}.net7.0.json" >> $GITHUB_ENV + PATH_NET8_NOHW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net8nohw" + echo "cover_net8_nohw=${PATH_NET8_NOHW}" >> $GITHUB_ENV + echo "cover_net8_nohw_merge=${PATH_NET8_NOHW}.net8.0.json" >> $GITHUB_ENV - PATH_NET7_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net7hw" - echo "cover_net7_hw=${PATH_NET7_HW}" >> $GITHUB_ENV - echo "cover_net7_hw_merge=${PATH_NET7_HW}.net7.0.info" >> $GITHUB_ENV + PATH_NET8_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net8hw" + echo "cover_net8_hw=${PATH_NET8_HW}" >> $GITHUB_ENV + echo "cover_net8_hw_merge=${PATH_NET8_HW}.net8.0.info" >> $GITHUB_ENV - name: Run .NET 6 tests without Hardware Intrinsics shell: bash run: | export COMPlus_EnableHWIntrinsic=0 + export DOTNET_EnableHWIntrinsic=0 export COMPlus_ReadyToRun=0 + export DOTNET_ReadyToRun=0 export CollectCoverage=true export CoverletOutputFormat=json export CoverletOutput=${{ env.cover_net6_nohw }} @@ -150,33 +152,41 @@ jobs: shell: bash run: | export COMPlus_EnableHWIntrinsic=1 + export DOTNET_EnableHWIntrinsic=1 unset COMPlus_ReadyToRun + unset DOTNET_ReadyToRun export CollectCoverage=true export CoverletOutputFormat=json export CoverletOutput=${{ env.cover_net6_hw }} export MergeWith=${{ env.cover_net6_nohw_merge }} dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net6.0 - - name: Run .NET 7 tests without Hardware Intrinsics + - name: Run .NET 8 tests without Hardware Intrinsics shell: bash run: | export COMPlus_EnableHWIntrinsic=0 + export DOTNET_EnableHWIntrinsic=0 + export COMPlus_ReadyToRun=0 + export DOTNET_ReadyToRun=0 export CollectCoverage=true export CoverletOutputFormat=json - export CoverletOutput=${{ env.cover_net7_nohw }} + export CoverletOutput=${{ env.cover_net8_nohw }} export MergeWith=${{ env.cover_net6_hw_merge }} - dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net7.0 - - name: Run .NET 7 tests with Hardware Intrinsics + dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net8.0 + - name: Run .NET 8 tests with Hardware Intrinsics shell: bash run: | export COMPlus_EnableHWIntrinsic=1 + export DOTNET_EnableHWIntrinsic=1 + unset COMPlus_ReadyToRun + unset DOTNET_ReadyToRun export CollectCoverage=true export CoverletOutputFormat=lcov - export CoverletOutput=${{ env.cover_net7_hw }} - export MergeWith=${{ env.cover_net7_nohw_merge }} - dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net7.0 - - name: Publish coverage report to coveralls.io - uses: coverallsapp/github-action@1.1.3 + export CoverletOutput=${{ env.cover_net8_hw }} + export MergeWith=${{ env.cover_net8_nohw_merge }} + dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net8.0 + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ${{ env.cover_net7_hw_merge }} - + files: ${{ env.cover_net8_hw_merge }} \ No newline at end of file diff --git a/.github/workflows/push_to_main.yml b/.github/workflows/push_to_main.yml index 362e799..8b91bf7 100644 --- a/.github/workflows/push_to_main.yml +++ b/.github/workflows/push_to_main.yml @@ -6,10 +6,10 @@ on: jobs: validate-version: name: Validate package version - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.sha }} - name: Validate version @@ -34,24 +34,24 @@ jobs: run-tests: name: Run tests needs: validate-version - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest if: ${{ !contains(github.event.commits[0].message, '[skip ci]') }} env: DOTNET_NOLOGO: true DOTNET_CLI_TELEMETRY_OPTOUT: true steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.sha }} - - name: Setup .NET Core SDK 6.0.413 - uses: actions/setup-dotnet@v3 + - name: Setup .NET Core SDK 6.0.418 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.413 - - name: Setup .NET Core SDK 7.0.400 - uses: actions/setup-dotnet@v3 + dotnet-version: 6.0.418 + - name: Setup .NET Core SDK 8.0.101 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 7.0.400 + dotnet-version: 8.0.101 - name: Create coverage directory and promote absolute paths to env shell: bash run: | @@ -67,18 +67,20 @@ jobs: echo "cover_net6_hw=${PATH_NET6_HW}" >> $GITHUB_ENV echo "cover_net6_hw_merge=${PATH_NET6_HW}.net6.0.json" >> $GITHUB_ENV - PATH_NET7_NOHW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net7nohw" - echo "cover_net7_nohw=${PATH_NET7_NOHW}" >> $GITHUB_ENV - echo "cover_net7_nohw_merge=${PATH_NET7_NOHW}.net7.0.json" >> $GITHUB_ENV + PATH_NET8_NOHW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net8nohw" + echo "cover_net8_nohw=${PATH_NET8_NOHW}" >> $GITHUB_ENV + echo "cover_net8_nohw_merge=${PATH_NET8_NOHW}.net8.0.json" >> $GITHUB_ENV - PATH_NET7_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net7hw" - echo "cover_net7_hw=${PATH_NET7_HW}" >> $GITHUB_ENV - echo "cover_net7_hw_merge=${PATH_NET7_HW}.net7.0.info" >> $GITHUB_ENV + PATH_NET8_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net8hw" + echo "cover_net8_hw=${PATH_NET8_HW}" >> $GITHUB_ENV + echo "cover_net8_hw_merge=${PATH_NET8_HW}.net8.0.info" >> $GITHUB_ENV - name: Run .NET 6 tests without Hardware Intrinsics shell: bash run: | export COMPlus_EnableHWIntrinsic=0 + export DOTNET_EnableHWIntrinsic=0 export COMPlus_ReadyToRun=0 + export DOTNET_ReadyToRun=0 export CollectCoverage=true export CoverletOutputFormat=json export CoverletOutput=${{ env.cover_net6_nohw }} @@ -87,43 +89,52 @@ jobs: shell: bash run: | export COMPlus_EnableHWIntrinsic=1 + export DOTNET_EnableHWIntrinsic=1 unset COMPlus_ReadyToRun + unset DOTNET_ReadyToRun export CollectCoverage=true export CoverletOutputFormat=json export CoverletOutput=${{ env.cover_net6_hw }} export MergeWith=${{ env.cover_net6_nohw_merge }} dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net6.0 - - name: Run .NET 7 tests without Hardware Intrinsics + - name: Run .NET 8 tests without Hardware Intrinsics shell: bash run: | export COMPlus_EnableHWIntrinsic=0 + export DOTNET_EnableHWIntrinsic=0 + export COMPlus_ReadyToRun=0 + export DOTNET_ReadyToRun=0 export CollectCoverage=true export CoverletOutputFormat=json - export CoverletOutput=${{ env.cover_net7_nohw }} + export CoverletOutput=${{ env.cover_net8_nohw }} export MergeWith=${{ env.cover_net6_hw_merge }} - dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net7.0 - - name: Run .NET 7 tests with Hardware Intrinsics + dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net8.0 + - name: Run .NET 8 tests with Hardware Intrinsics shell: bash run: | export COMPlus_EnableHWIntrinsic=1 + export DOTNET_EnableHWIntrinsic=1 + unset COMPlus_ReadyToRun + unset DOTNET_ReadyToRun export CollectCoverage=true export CoverletOutputFormat=lcov - export CoverletOutput=${{ env.cover_net7_hw }} - export MergeWith=${{ env.cover_net7_nohw_merge }} - dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net7.0 - - name: Publish coverage report to coveralls.io - uses: coverallsapp/github-action@1.1.3 + export CoverletOutput=${{ env.cover_net8_hw }} + export MergeWith=${{ env.cover_net8_nohw_merge }} + dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net8.0 + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ${{ env.cover_net7_hw_merge }} + files: ${{ env.cover_net8_hw_merge }} release: name: Create release - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest needs: run-tests if: ${{ !contains(github.event.commits[0].message, '[skip ci]') }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.sha }} - name: Extract version @@ -144,11 +155,11 @@ jobs: echo "release_version_with_suffix=${version_with_suffix}" >> $GITHUB_ENV echo "release_has_suffix=${has_suffix}" >> $GITHUB_ENV - name: Create release - uses: actions/create-release@v1 + uses: ncipollo/release-action@v1.13.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ env.release_version_with_suffix }} + tag: ${{ env.release_version_with_suffix }} release_name: Release ${{ env.release_version_with_suffix }} draft: true prerelease: ${{ env.release_has_suffix }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9321440..7431191 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,23 +5,23 @@ on: jobs: build-test-and-publish: name: Build and publish library to NuGet - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest env: DOTNET_NOLOGO: true DOTNET_CLI_TELEMETRY_OPTOUT: true steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.sha }} - - name: Setup .NET Core SDK 6.0.413 - uses: actions/setup-dotnet@v3 + - name: Setup .NET Core SDK 6.0.418 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.413 - - name: Setup .NET Core SDK 7.0.400 - uses: actions/setup-dotnet@v3 + dotnet-version: 6.0.418 + - name: Setup .NET Core SDK 8.0.101 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 7.0.400 + dotnet-version: 8.0.101 - name: Create coverage directory and promote absolute paths to env shell: bash run: | @@ -37,18 +37,20 @@ jobs: echo "cover_net6_hw=${PATH_NET6_HW}" >> $GITHUB_ENV echo "cover_net6_hw_merge=${PATH_NET6_HW}.net6.0.json" >> $GITHUB_ENV - PATH_NET7_NOHW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net7nohw" - echo "cover_net7_nohw=${PATH_NET7_NOHW}" >> $GITHUB_ENV - echo "cover_net7_nohw_merge=${PATH_NET7_NOHW}.net7.0.json" >> $GITHUB_ENV + PATH_NET8_NOHW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net8nohw" + echo "cover_net8_nohw=${PATH_NET8_NOHW}" >> $GITHUB_ENV + echo "cover_net8_nohw_merge=${PATH_NET8_NOHW}.net8.0.json" >> $GITHUB_ENV - PATH_NET7_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net7hw" - echo "cover_net7_hw=${PATH_NET7_HW}" >> $GITHUB_ENV - echo "cover_net7_hw_merge=${PATH_NET7_HW}.net7.0.info" >> $GITHUB_ENV + PATH_NET8_HW="${PATH_TO_COVERAGE_DIRECTORY}/cover_net8hw" + echo "cover_net8_hw=${PATH_NET8_HW}" >> $GITHUB_ENV + echo "cover_net8_hw_merge=${PATH_NET8_HW}.net8.0.info" >> $GITHUB_ENV - name: Run .NET 6 tests without Hardware Intrinsics shell: bash run: | export COMPlus_EnableHWIntrinsic=0 + export DOTNET_EnableHWIntrinsic=0 export COMPlus_ReadyToRun=0 + export DOTNET_ReadyToRun=0 export CollectCoverage=true export CoverletOutputFormat=json export CoverletOutput=${{ env.cover_net6_nohw }} @@ -57,54 +59,63 @@ jobs: shell: bash run: | export COMPlus_EnableHWIntrinsic=1 + export DOTNET_EnableHWIntrinsic=1 unset COMPlus_ReadyToRun + unset DOTNET_ReadyToRun export CollectCoverage=true export CoverletOutputFormat=json export CoverletOutput=${{ env.cover_net6_hw }} export MergeWith=${{ env.cover_net6_nohw_merge }} dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net6.0 - - name: Run .NET 7 tests without Hardware Intrinsics + - name: Run .NET 8 tests without Hardware Intrinsics shell: bash run: | export COMPlus_EnableHWIntrinsic=0 + export DOTNET_EnableHWIntrinsic=0 + export COMPlus_ReadyToRun=0 + export DOTNET_ReadyToRun=0 export CollectCoverage=true export CoverletOutputFormat=json - export CoverletOutput=${{ env.cover_net7_nohw }} + export CoverletOutput=${{ env.cover_net8_nohw }} export MergeWith=${{ env.cover_net6_hw_merge }} - dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net7.0 - - name: Run .NET 7 tests with Hardware Intrinsics + dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net8.0 + - name: Run .NET 8 tests with Hardware Intrinsics shell: bash run: | export COMPlus_EnableHWIntrinsic=1 + export DOTNET_EnableHWIntrinsic=1 + unset COMPlus_ReadyToRun + unset DOTNET_ReadyToRun export CollectCoverage=true export CoverletOutputFormat=lcov - export CoverletOutput=${{ env.cover_net7_hw }} - export MergeWith=${{ env.cover_net7_nohw_merge }} - dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net7.0 - - name: Publish coverage report to coveralls.io - uses: coverallsapp/github-action@1.1.3 + export CoverletOutput=${{ env.cover_net8_hw }} + export MergeWith=${{ env.cover_net8_nohw_merge }} + dotnet test -c Release ./src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj -f net8.0 + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ${{ env.cover_net7_hw_merge }} + files: ${{ env.cover_net8_hw_merge }} - name: Build and publish library to NuGet shell: bash run: | dotnet publish ./src/Dodo.Primitives/Dodo.Primitives.csproj -c Release -f net6.0 - dotnet publish ./src/Dodo.Primitives/Dodo.Primitives.csproj -c Release -f net7.0 + dotnet publish ./src/Dodo.Primitives/Dodo.Primitives.csproj -c Release -f net8.0 dotnet pack -c Release --no-restore --no-build --output out ./src/Dodo.Primitives/Dodo.Primitives.csproj rm ./out/*.symbols.nupkg PATH_TO_PACKAGE=$(readlink -f ./out/*.nupkg) dotnet nuget push "$PATH_TO_PACKAGE" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: NuGet package path: out/ upload-release-assets: name: Upload release assets - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest needs: build-test-and-publish steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: NuGet package path: out diff --git a/README.md b/README.md index 6d400db..0857dfc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Dodo.Primitives -[![Latest release](https://img.shields.io/badge/nuget-2.0.1-blue?&kill_cache=1)](https://www.nuget.org/packages/Dodo.Primitives/2.0.1) -[![Coverage Status](https://coveralls.io/repos/github/dodopizza/primitives/badge.svg?branch=refs/tags/2.0.1&kill_cache=1)](https://coveralls.io/github/dodopizza/primitives?branch=refs/tags/2.0.1) +[![Latest release](https://img.shields.io/badge/nuget-3.0.0-blue?&kill_cache=1)](https://www.nuget.org/packages/Dodo.Primitives/3.0.0) +[![codecov](https://codecov.io/gh/dodobrands/primitives/graph/badge.svg?token=7ILQPREIVA)](https://codecov.io/gh/dodobrands/primitives) Library provides .NET primitive types: @@ -15,7 +15,7 @@ and utils to work with types: The main goal is Uuid implementation according to the [RFC4122](https://tools.ietf.org/html/rfc4122). -.NET provides [System.Guid](https://docs.microsoft.com/en-us/dotnet/api/system.guid) struct which is special case of the RFC4122 implementation. System.Guid has [little-endian layout](https://github.com/dotnet/runtime/blob/v7.0.0/src/libraries/System.Private.CoreLib/src/System/Guid.cs#L30-L32) for the first 8 bytes (int32, int16, int16). +.NET provides [System.Guid](https://docs.microsoft.com/en-us/dotnet/api/system.guid) struct which is special case of the RFC4122 implementation. System.Guid has [little-endian layout](https://github.com/dotnet/runtime/blob/v8.0.0/src/libraries/System.Private.CoreLib/src/System/Guid.cs#L33-L35) for the first 8 bytes (int32, int16, int16). Our goal is to provide Uuid fully compliant with RFC4122 (big-endian layout) and preserve System.Guid-like behaviour. Also project contains generators to create different Uuid variants. Currently supported variants: @@ -35,6 +35,6 @@ Our goal is to provide Uuid fully compliant with RFC4122 (big-endian layout) and ## Project documentation -- [Prerequisites, build and development](https://github.com/dodopizza/primitives/wiki/Prerequisites,-build-and-development) -- [Benchmarks](https://github.com/dodopizza/primitives/wiki/Benchmarks) +- [Prerequisites, build and development](https://github.com/dodobrands/primitives/wiki/Prerequisites,-build-and-development) +- [Benchmarks](https://github.com/dodobrands/primitives/wiki/Benchmarks) diff --git a/global.json b/global.json index e944ed0..cb33872 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.400", + "version": "8.0.101", "rollForward": "latestPatch" } } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 8e6cff3..8e60057 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@ - 2.0.1 + 3.0.0 diff --git a/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj b/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj index 2efba26..0890069 100644 --- a/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj +++ b/src/Dodo.Primitives.Benchmarks/Dodo.Primitives.Benchmarks.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 288ccf26-65fb-4cc8-932b-01f0a458940a enable disable @@ -15,7 +15,7 @@ - + diff --git a/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj b/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj index c9523f9..263a062 100644 --- a/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj +++ b/src/Dodo.Primitives.Tests/Dodo.Primitives.Tests.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0 + net6.0;net8.0 4c9485a5-fcb5-4361-8c46-c99669d5b22e 11.0 enable @@ -18,11 +18,11 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - - + + diff --git a/src/Dodo.Primitives.Tests/Uuids/UuidTryFormatTests.cs b/src/Dodo.Primitives.Tests/Uuids/UuidTryFormatTests.cs index 052a425..9f99811 100644 --- a/src/Dodo.Primitives.Tests/Uuids/UuidTryFormatTests.cs +++ b/src/Dodo.Primitives.Tests/Uuids/UuidTryFormatTests.cs @@ -1,4 +1,5 @@ using System; +using System.Text; using Dodo.Primitives.Tests.Uuids.Data; using NUnit.Framework; @@ -261,4 +262,128 @@ public void SpanFormattableTryFormatSmallDestination(byte[] correctBytes) } #endregion + + #region IUtf8SpanFormattable.TryFormat + + [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))] + public void Utf8SpanFormattableTryFormatEmptyFormat(byte[] correctBytes) + { + var uuid = new Uuid(correctBytes); + string expectedString = UuidTestsUtils.GetStringN(correctBytes); + byte* bufferPtr = stackalloc byte[32]; + var spanBuffer = new Span(bufferPtr, 32); + Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, ReadOnlySpan.Empty, null)); + Assert.AreEqual(32, charsWritten); + Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten)); + } + + + [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))] + public void Utf8SpanFormattableTryFormatIncorrectFormat(byte[] correctBytes) + { + var uuid = new Uuid(correctBytes); + Span buffer = stackalloc byte[68]; + Assert.False(uuid.TryFormat(buffer, out int charsWritten, "Ъ".AsSpan(), null)); + Assert.AreEqual(0, charsWritten); + } + + + [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))] + public void Utf8SpanFormattableTryFormatTooLongFormat(byte[] correctBytes) + { + var uuid = new Uuid(correctBytes); + Span buffer = stackalloc byte[68]; + Assert.False(uuid.TryFormat(buffer, out int charsWritten, "ЪЪ".AsSpan(), null)); + Assert.AreEqual(0, charsWritten); + } + + [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))] + public void Utf8SpanFormattableTryFormatNCorrect(byte[] correctBytes) + { + var uuid = new Uuid(correctBytes); + string expectedString = UuidTestsUtils.GetStringN(correctBytes); + byte* bufferPtr = stackalloc byte[32]; + var spanBuffer = new Span(bufferPtr, 32); + Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'N' }), null)); + Assert.AreEqual(32, charsWritten); + Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten)); + } + + [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))] + public void Utf8SpanFormattableTryFormatDCorrect(byte[] correctBytes) + { + var uuid = new Uuid(correctBytes); + string expectedString = UuidTestsUtils.GetStringD(correctBytes); + byte* bufferPtr = stackalloc byte[36]; + var spanBuffer = new Span(bufferPtr, 36); + Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'D' }), null)); + Assert.AreEqual(36, charsWritten); + Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten)); + } + + [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))] + public void Utf8SpanFormattableTryFormatBCorrect(byte[] correctBytes) + { + var uuid = new Uuid(correctBytes); + string expectedString = UuidTestsUtils.GetStringB(correctBytes); + byte* bufferPtr = stackalloc byte[38]; + var spanBuffer = new Span(bufferPtr, 38); + Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'B' }), null)); + Assert.AreEqual(38, charsWritten); + Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten)); + } + + [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))] + public void Utf8SpanFormattableTryFormatPCorrect(byte[] correctBytes) + { + var uuid = new Uuid(correctBytes); + string expectedString = UuidTestsUtils.GetStringP(correctBytes); + byte* bufferPtr = stackalloc byte[38]; + var spanBuffer = new Span(bufferPtr, 38); + Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'P' }), null)); + Assert.AreEqual(38, charsWritten); + Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten)); + } + + [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))] + public void Utf8SpanFormattableTryFormatXCorrect(byte[] correctBytes) + { + var uuid = new Uuid(correctBytes); + string expectedString = UuidTestsUtils.GetStringX(correctBytes); + byte* bufferPtr = stackalloc byte[68]; + var spanBuffer = new Span(bufferPtr, 68); + Assert.True(uuid.TryFormat(spanBuffer, out int charsWritten, new ReadOnlySpan(new[] { 'X' }), null)); + Assert.AreEqual(68, charsWritten); + Assert.AreEqual(expectedString, Encoding.UTF8.GetString(bufferPtr, charsWritten)); + } + + [TestCaseSource(typeof(UuidTestData), nameof(UuidTestData.CorrectUuidBytesArrays))] + public void Utf8SpanFormattableTryFormatSmallDestination(byte[] correctBytes) + { + Assert.Multiple(() => + { + var uuid = new Uuid(correctBytes); + Span buffer = stackalloc byte[10]; + var formats = new[] + { + 'N', + 'n', + 'D', + 'd', + 'B', + 'b', + 'P', + 'p', + 'X', + 'x' + }; + foreach (char format in formats) + { + Assert.False(uuid.TryFormat(buffer, out int charsWritten, new ReadOnlySpan(new[] { format }), null)); + Assert.AreEqual(0, charsWritten); + } + }); + } + + #endregion } diff --git a/src/Dodo.Primitives/Dodo.Primitives.csproj b/src/Dodo.Primitives/Dodo.Primitives.csproj index dd4b451..52edb44 100644 --- a/src/Dodo.Primitives/Dodo.Primitives.csproj +++ b/src/Dodo.Primitives/Dodo.Primitives.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0 + net6.0;net8.0 b9ecdb73-d6f3-4ec4-b4b4-a7ed2ae781b7 11.0 enable @@ -18,15 +18,15 @@ true Dodo.Primitives Roman Bukin - Dodo Engineering - Copyright 2022-2023 Dodo Engineering + Dodo Brands + Copyright 2022-2024 Dodo Brands The main goal of this library is to provide primitive types like Uuid, Hex converter, etc. Uuid Hex Dodo false LICENSE logo.png - https://github.com/dodopizza/primitives - https://github.com/dodopizza/primitives/releases + https://github.com/dodobrands/primitives + https://github.com/dodobrands/primitives/releases true true @@ -41,8 +41,4 @@ true - - - - diff --git a/src/Dodo.Primitives/Hex.cs b/src/Dodo.Primitives/Hex.cs index c259396..31030ff 100644 --- a/src/Dodo.Primitives/Hex.cs +++ b/src/Dodo.Primitives/Hex.cs @@ -10,13 +10,13 @@ namespace Dodo.Primitives; public static unsafe class Hex { private const ushort MaximalChar = InternalHexTables.MaximalChar; - private static readonly uint* TableToHex; - private static readonly byte* TableFromHexToBytes; + private static readonly uint* TableToHexUtf16; + private static readonly byte* TableFromHexToBytesUtf16; static Hex() { - TableToHex = InternalHexTables.TableToHex; - TableFromHexToBytes = InternalHexTables.TableFromHexToBytes; + TableToHexUtf16 = InternalHexTables.TableToHexUtf16; + TableFromHexToBytesUtf16 = InternalHexTables.TableFromHexToBytesUtf16; } /// @@ -42,9 +42,9 @@ public static bool IsHexString(string? possibleHexString) for (var i = 0; i < length;) { if (stringPtr[i] < MaximalChar - && TableFromHexToBytes[stringPtr[i]] != 0xFF + && TableFromHexToBytesUtf16[stringPtr[i]] != 0xFF && stringPtr[i + 1] < MaximalChar - && TableFromHexToBytes[stringPtr[i + 1]] != 0xFF) + && TableFromHexToBytesUtf16[stringPtr[i + 1]] != 0xFF) { i += 2; } @@ -86,9 +86,9 @@ public static bool IsHexString(string? possibleHexString) byte hexByteHi; byte hexByteLow; if (stringPtr[i] < MaximalChar - && (hexByteHi = TableFromHexToBytes[stringPtr[i]]) != 0xFF + && (hexByteHi = TableFromHexToBytesUtf16[stringPtr[i]]) != 0xFF && stringPtr[i + 1] < MaximalChar - && (hexByteLow = TableFromHexToBytes[stringPtr[i + 1]]) != 0xFF) + && (hexByteLow = TableFromHexToBytesUtf16[stringPtr[i + 1]]) != 0xFF) { var resultByte = (byte) ((byte) (hexByteHi << 4) | hexByteLow); resultPtr[resultIndex] = resultByte; @@ -129,7 +129,7 @@ public static bool IsHexString(string? possibleHexString) var destUints = (uint*) stringPtr; for (var i = 0; i < bytes.Length; i++) { - destUints[i] = TableToHex[bytes[i]]; + destUints[i] = TableToHexUtf16[bytes[i]]; } } diff --git a/src/Dodo.Primitives/Internal/InternalHexTables.cs b/src/Dodo.Primitives/Internal/InternalHexTables.cs index a406467..11e3ad0 100644 --- a/src/Dodo.Primitives/Internal/InternalHexTables.cs +++ b/src/Dodo.Primitives/Internal/InternalHexTables.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace Dodo.Primitives.Internal; @@ -6,22 +7,41 @@ namespace Dodo.Primitives.Internal; internal static unsafe class InternalHexTables { internal const ushort MaximalChar = 103; - internal static readonly uint* TableToHex; - internal static readonly byte* TableFromHexToBytes; + internal static readonly uint* TableToHexUtf16; + internal static readonly ushort* TableToHexUtf8; + internal static readonly byte* TableFromHexToBytesUtf16; + [SuppressMessage("ReSharper", "SuggestVarOrType_BuiltInTypes")] static InternalHexTables() { - TableToHex = (uint*) Marshal.AllocHGlobal(sizeof(uint) * 256).ToPointer(); - for (var i = 0; i < 256; i++) + const int bytesPerCharUtf16 = 2; + const int bytesPerCharUtf8 = 1; + const int charsPerTableToHexCell = 2; + const int charsPerTableToHex = 256; + + IntPtr tableToHexUtf16Buffer = Marshal.AllocHGlobal(bytesPerCharUtf16 * charsPerTableToHexCell * charsPerTableToHex); + IntPtr tableToHexUtf8Buffer = Marshal.AllocHGlobal(bytesPerCharUtf8 * charsPerTableToHexCell * charsPerTableToHex); + + void* tableToHexUtf16Pointer = tableToHexUtf16Buffer.ToPointer(); + void* tableToHexUtf8Pointer = tableToHexUtf8Buffer.ToPointer(); + + TableToHexUtf16 = (uint*) tableToHexUtf16Pointer; + TableToHexUtf8 = (ushort*) tableToHexUtf8Pointer; + for (var i = 0; i < charsPerTableToHex; i++) { string chars = Convert.ToString(i, 16).PadLeft(2, '0'); - TableToHex[i] = ((uint) chars[1] << 16) | chars[0]; + uint utf16 = ((uint) chars[1] << 16) | chars[0]; + ushort utf8 = (ushort) ((ushort) ((byte) chars[1] << 8) | (byte) chars[0]); + TableToHexUtf8[i] = utf8; + TableToHexUtf16[i] = utf16; } - TableFromHexToBytes = (byte*) Marshal.AllocHGlobal(103).ToPointer(); - for (var i = 0; i < 103; i++) + IntPtr tableFromHexToBytesUtf16Buffer = Marshal.AllocHGlobal(MaximalChar); + void* tableFromHexToBytesUtf16BufferPointer = tableFromHexToBytesUtf16Buffer.ToPointer(); + TableFromHexToBytesUtf16 = (byte*) tableFromHexToBytesUtf16BufferPointer; + for (var i = 0; i < MaximalChar; i++) { - TableFromHexToBytes[i] = (char) i switch + TableFromHexToBytesUtf16[i] = (char) i switch { '0' => 0x0, '1' => 0x1, diff --git a/src/Dodo.Primitives/Uuid.cs b/src/Dodo.Primitives/Uuid.cs index 642716d..16bbf44 100644 --- a/src/Dodo.Primitives/Uuid.cs +++ b/src/Dodo.Primitives/Uuid.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using System.Text.Json.Serialization; using Dodo.Primitives.Internal; -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER using System.Numerics; using System.Runtime.Intrinsics; #endif @@ -23,21 +23,23 @@ public unsafe struct Uuid : ISpanFormattable, IComparable, IComparable, - IEquatable -#if NET7_0_OR_GREATER - , ISpanParsable, IComparisonOperators + IEquatable, IFormattable +#if NET8_0_OR_GREATER + , ISpanParsable, IParsable, IUtf8SpanFormattable, IComparisonOperators #endif { static Uuid() { - TableToHex = InternalHexTables.TableToHex; - TableFromHexToBytes = InternalHexTables.TableFromHexToBytes; + TableToHexUtf16 = InternalHexTables.TableToHexUtf16; + TableToHexUtf8 = InternalHexTables.TableToHexUtf8; + TableFromHexToBytesUtf16 = InternalHexTables.TableFromHexToBytesUtf16; } - private const ushort MaximalChar = InternalHexTables.MaximalChar; + private const ushort MaximalCharUtf16 = InternalHexTables.MaximalChar; - private static readonly uint* TableToHex; - private static readonly byte* TableFromHexToBytes; + private static readonly uint* TableToHexUtf16; + private static readonly ushort* TableToHexUtf8; + private static readonly byte* TableFromHexToBytesUtf16; private readonly byte _byte0; private readonly byte _byte1; @@ -344,15 +346,14 @@ public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is Uuid other) { -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER if (Vector128.IsHardwareAccelerated) { - return Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in this))) - == Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in other))); + return Vector128.LoadUnsafe(ref Unsafe.As(ref this)) == Vector128.LoadUnsafe(ref Unsafe.As(ref other)); } #endif - ref long rA = ref Unsafe.As(ref Unsafe.AsRef(in this)); - ref long rB = ref Unsafe.As(ref Unsafe.AsRef(in other)); + ref long rA = ref Unsafe.As(ref this); + ref long rB = ref Unsafe.As(ref other); // Compare each element return rA == rB && Unsafe.Add(ref rA, 1) == Unsafe.Add(ref rB, 1); @@ -368,15 +369,14 @@ public override bool Equals([NotNullWhen(true)] object? obj) /// if is equal to this instance; otherwise, . public bool Equals(Uuid other) { -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER if (Vector128.IsHardwareAccelerated) { - return Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in this))) - == Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in other))); + return Vector128.LoadUnsafe(ref Unsafe.As(ref this)) == Vector128.LoadUnsafe(ref Unsafe.As(ref other)); } #endif - ref long rA = ref Unsafe.As(ref Unsafe.AsRef(in this)); - ref long rB = ref Unsafe.As(ref Unsafe.AsRef(in other)); + ref long rA = ref Unsafe.As(ref this); + ref long rB = ref Unsafe.As(ref other); // Compare each element return rA == rB && Unsafe.Add(ref rA, 1) == Unsafe.Add(ref rB, 1); @@ -388,7 +388,7 @@ public bool Equals(Uuid other) /// The hash code for this instance. public override int GetHashCode() { - ref int r = ref Unsafe.As(ref Unsafe.AsRef(in this)); + ref int r = ref Unsafe.As(ref this); return r ^ Unsafe.Add(ref r, 1) ^ Unsafe.Add(ref r, 2) ^ Unsafe.Add(ref r, 3); } @@ -400,15 +400,14 @@ public override int GetHashCode() /// if and are equal; otherwise, . public static bool operator ==(Uuid left, Uuid right) { -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER if (Vector128.IsHardwareAccelerated) { - return Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in left))) - == Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in right))); + return Vector128.LoadUnsafe(ref Unsafe.As(ref left)) == Vector128.LoadUnsafe(ref Unsafe.As(ref right)); } #endif - ref long rA = ref Unsafe.As(ref Unsafe.AsRef(in left)); - ref long rB = ref Unsafe.As(ref Unsafe.AsRef(in right)); + ref long rA = ref Unsafe.As(ref left); + ref long rB = ref Unsafe.As(ref right); // Compare each element return rA == rB && Unsafe.Add(ref rA, 1) == Unsafe.Add(ref rB, 1); @@ -425,15 +424,14 @@ public override int GetHashCode() /// public static bool operator !=(Uuid left, Uuid right) { -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER if (Vector128.IsHardwareAccelerated) { - return Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in left))) - != Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in right))); + return Vector128.LoadUnsafe(ref Unsafe.As(ref left)) != Vector128.LoadUnsafe(ref Unsafe.As(ref right)); } #endif - ref long rA = ref Unsafe.As(ref Unsafe.AsRef(in left)); - ref long rB = ref Unsafe.As(ref Unsafe.AsRef(in right)); + ref long rA = ref Unsafe.As(ref left); + ref long rB = ref Unsafe.As(ref right); // Compare each element return rA != rB || Unsafe.Add(ref rA, 1) != Unsafe.Add(ref rB, 1); @@ -457,7 +455,7 @@ public override int GetHashCode() public bool TryFormat( Span destination, out int charsWritten, -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif ReadOnlySpan format, @@ -486,7 +484,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatN(uuidChars); + FormatUtf16N(uuidChars); } charsWritten = 32; @@ -502,7 +500,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatD(uuidChars); + FormatUtf16D(uuidChars); } charsWritten = 36; @@ -518,7 +516,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatB(uuidChars); + FormatUtf16B(uuidChars); } charsWritten = 38; @@ -534,7 +532,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatP(uuidChars); + FormatUtf16P(uuidChars); } charsWritten = 38; @@ -550,7 +548,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatX(uuidChars); + FormatUtf16X(uuidChars); } charsWritten = 68; @@ -581,7 +579,7 @@ public bool TryFormat( public bool TryFormat( Span destination, out int charsWritten, -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif ReadOnlySpan format = default) @@ -609,7 +607,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatN(uuidChars); + FormatUtf16N(uuidChars); } charsWritten = 32; @@ -625,7 +623,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatD(uuidChars); + FormatUtf16D(uuidChars); } charsWritten = 36; @@ -641,7 +639,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatB(uuidChars); + FormatUtf16B(uuidChars); } charsWritten = 38; @@ -657,7 +655,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatP(uuidChars); + FormatUtf16P(uuidChars); } charsWritten = 38; @@ -673,7 +671,7 @@ public bool TryFormat( fixed (char* uuidChars = &destination.GetPinnableReference()) { - FormatX(uuidChars); + FormatUtf16X(uuidChars); } charsWritten = 68; @@ -687,6 +685,134 @@ public bool TryFormat( } } + // + // IUtf8SpanFormattable + // +#if NET8_0_OR_GREATER + /// +#else + /// Tries to format the value of the current instance as UTF-8 into the provided span of bytes. + /// When this method returns, this instance's value formatted as a span of bytes. + /// When this method returns, the number of bytes that were written in . + /// A span containing the characters that represent a standard or custom format string that defines the acceptable format for . + /// An optional object that supplies culture-specific formatting information for . + /// if the formatting was successful; otherwise, . + /// + /// An implementation of this interface should produce the same string of characters as an implementation of or + /// on the same type. TryFormat should return false only if there is not enough space in the destination buffer; any other failures should throw an exception. + /// +#endif + public bool TryFormat( + Span utf8Destination, + out int bytesWritten, +#if NET8_0_OR_GREATER + [StringSyntax(StringSyntaxAttribute.GuidFormat)] +#endif + ReadOnlySpan format, + IFormatProvider? provider) + { + if (format.Length == 0) + { + format = "N"; + } + + if (format.Length != 1) + { + bytesWritten = 0; + return false; + } + + switch ((char) (format[0] | 0x20)) + { + case 'n': + { + if (utf8Destination.Length < 32) + { + bytesWritten = 0; + return false; + } + + fixed (byte* uuidChars = &utf8Destination.GetPinnableReference()) + { + FormatUtf8N(uuidChars); + } + + bytesWritten = 32; + return true; + } + case 'd': + { + if (utf8Destination.Length < 36) + { + bytesWritten = 0; + return false; + } + + fixed (byte* uuidChars = &utf8Destination.GetPinnableReference()) + { + FormatUtf8D(uuidChars); + } + + bytesWritten = 36; + return true; + } + case 'b': + { + if (utf8Destination.Length < 38) + { + bytesWritten = 0; + return false; + } + + fixed (byte* uuidChars = &utf8Destination.GetPinnableReference()) + { + FormatUtf8B(uuidChars); + } + + bytesWritten = 38; + return true; + } + case 'p': + { + if (utf8Destination.Length < 38) + { + bytesWritten = 0; + return false; + } + + fixed (byte* uuidChars = &utf8Destination.GetPinnableReference()) + { + FormatUtf8P(uuidChars); + } + + bytesWritten = 38; + return true; + } + case 'x': + { + if (utf8Destination.Length < 68) + { + bytesWritten = 0; + return false; + } + + fixed (byte* uuidChars = &utf8Destination.GetPinnableReference()) + { + FormatUtf8X(uuidChars); + } + + bytesWritten = 68; + return true; + } + default: + { + bytesWritten = 0; + return false; + } + } + } + + /// /// Returns a string representation of the value of this instance. /// @@ -705,7 +831,7 @@ public override string ToString() /// /// The value of this , represented as a series of lowercase hexadecimal digits in the specified format. public string ToString( -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif string? format) @@ -729,7 +855,7 @@ public string ToString( /// "B", "P", or "X". /// public string ToString( -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif string? format, @@ -755,7 +881,7 @@ public string ToString( var uuidString = new string('\0', 32); fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatN(uuidChars); + FormatUtf16N(uuidChars); } return uuidString; @@ -765,7 +891,7 @@ public string ToString( var uuidString = new string('\0', 36); fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatD(uuidChars); + FormatUtf16D(uuidChars); } return uuidString; @@ -775,7 +901,7 @@ public string ToString( var uuidString = new string('\0', 38); fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatB(uuidChars); + FormatUtf16B(uuidChars); } return uuidString; @@ -785,7 +911,7 @@ public string ToString( var uuidString = new string('\0', 38); fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatP(uuidChars); + FormatUtf16P(uuidChars); } return uuidString; @@ -795,7 +921,7 @@ public string ToString( var uuidString = new string('\0', 68); fixed (char* uuidChars = &uuidString.GetPinnableReference()) { - FormatX(uuidChars); + FormatUtf16X(uuidChars); } return uuidString; @@ -807,143 +933,284 @@ public string ToString( } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - private void FormatN(char* dest) + private void FormatUtf8N(byte* dest) { // dddddddddddddddddddddddddddddddd - var destUints = (uint*) dest; - destUints[0] = TableToHex[_byte0]; - destUints[1] = TableToHex[_byte1]; - destUints[2] = TableToHex[_byte2]; - destUints[3] = TableToHex[_byte3]; - destUints[4] = TableToHex[_byte4]; - destUints[5] = TableToHex[_byte5]; - destUints[6] = TableToHex[_byte6]; - destUints[7] = TableToHex[_byte7]; - destUints[8] = TableToHex[_byte8]; - destUints[9] = TableToHex[_byte9]; - destUints[10] = TableToHex[_byte10]; - destUints[11] = TableToHex[_byte11]; - destUints[12] = TableToHex[_byte12]; - destUints[13] = TableToHex[_byte13]; - destUints[14] = TableToHex[_byte14]; - destUints[15] = TableToHex[_byte15]; + var destInt16 = (ushort*) dest; + destInt16[0] = TableToHexUtf8[_byte0]; + destInt16[1] = TableToHexUtf8[_byte1]; + destInt16[2] = TableToHexUtf8[_byte2]; + destInt16[3] = TableToHexUtf8[_byte3]; + destInt16[4] = TableToHexUtf8[_byte4]; + destInt16[5] = TableToHexUtf8[_byte5]; + destInt16[6] = TableToHexUtf8[_byte6]; + destInt16[7] = TableToHexUtf8[_byte7]; + destInt16[8] = TableToHexUtf8[_byte8]; + destInt16[9] = TableToHexUtf8[_byte9]; + destInt16[10] = TableToHexUtf8[_byte10]; + destInt16[11] = TableToHexUtf8[_byte11]; + destInt16[12] = TableToHexUtf8[_byte12]; + destInt16[13] = TableToHexUtf8[_byte13]; + destInt16[14] = TableToHexUtf8[_byte14]; + destInt16[15] = TableToHexUtf8[_byte15]; } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - private void FormatD(char* dest) + private void FormatUtf8D(byte* dest) { // dddddddd-dddd-dddd-dddd-dddddddddddd - var destUints = (uint*) dest; - var destUintsAsChars = (char**) &destUints; + var destInt16 = (ushort*) dest; + var destInt16AsInt8 = (byte**) &destInt16; + dest[8] = dest[13] = dest[18] = dest[23] = Utf8Dash; + destInt16[0] = TableToHexUtf8[_byte0]; + destInt16[1] = TableToHexUtf8[_byte1]; + destInt16[2] = TableToHexUtf8[_byte2]; + destInt16[3] = TableToHexUtf8[_byte3]; + destInt16[7] = TableToHexUtf8[_byte6]; + destInt16[8] = TableToHexUtf8[_byte7]; + destInt16[12] = TableToHexUtf8[_byte10]; + destInt16[13] = TableToHexUtf8[_byte11]; + destInt16[14] = TableToHexUtf8[_byte12]; + destInt16[15] = TableToHexUtf8[_byte13]; + destInt16[16] = TableToHexUtf8[_byte14]; + destInt16[17] = TableToHexUtf8[_byte15]; + *destInt16AsInt8 += 1; + destInt16[4] = TableToHexUtf8[_byte4]; + destInt16[5] = TableToHexUtf8[_byte5]; + destInt16[9] = TableToHexUtf8[_byte8]; + destInt16[10] = TableToHexUtf8[_byte9]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + private void FormatUtf8B(byte* dest) + { + // {dddddddd-dddd-dddd-dddd-dddddddddddd} + var destInt16 = (ushort*) dest; + var destInt16AsInt8 = (byte**) &destInt16; + dest[0] = Utf8LeftCurlyBracket; + dest[9] = dest[14] = dest[19] = dest[24] = Utf8Dash; + dest[37] = Utf8RightCurlyBracket; + destInt16[5] = TableToHexUtf8[_byte4]; + destInt16[6] = TableToHexUtf8[_byte5]; + destInt16[10] = TableToHexUtf8[_byte8]; + destInt16[11] = TableToHexUtf8[_byte9]; + *destInt16AsInt8 += 1; + destInt16[0] = TableToHexUtf8[_byte0]; + destInt16[1] = TableToHexUtf8[_byte1]; + destInt16[2] = TableToHexUtf8[_byte2]; + destInt16[3] = TableToHexUtf8[_byte3]; + destInt16[7] = TableToHexUtf8[_byte6]; + destInt16[8] = TableToHexUtf8[_byte7]; + destInt16[12] = TableToHexUtf8[_byte10]; + destInt16[13] = TableToHexUtf8[_byte11]; + destInt16[14] = TableToHexUtf8[_byte12]; + destInt16[15] = TableToHexUtf8[_byte13]; + destInt16[16] = TableToHexUtf8[_byte14]; + destInt16[17] = TableToHexUtf8[_byte15]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + private void FormatUtf8P(byte* dest) + { + // (dddddddd-dddd-dddd-dddd-dddddddddddd) + var destInt16 = (ushort*) dest; + var destInt16AsInt8 = (byte**) &destInt16; + dest[0] = Utf8LeftParenthesis; + dest[9] = dest[14] = dest[19] = dest[24] = Utf8Dash; + dest[37] = Utf8RightParenthesis; + destInt16[5] = TableToHexUtf8[_byte4]; + destInt16[6] = TableToHexUtf8[_byte5]; + destInt16[10] = TableToHexUtf8[_byte8]; + destInt16[11] = TableToHexUtf8[_byte9]; + *destInt16AsInt8 += 1; + destInt16[0] = TableToHexUtf8[_byte0]; + destInt16[1] = TableToHexUtf8[_byte1]; + destInt16[2] = TableToHexUtf8[_byte2]; + destInt16[3] = TableToHexUtf8[_byte3]; + destInt16[7] = TableToHexUtf8[_byte6]; + destInt16[8] = TableToHexUtf8[_byte7]; + destInt16[12] = TableToHexUtf8[_byte10]; + destInt16[13] = TableToHexUtf8[_byte11]; + destInt16[14] = TableToHexUtf8[_byte12]; + destInt16[15] = TableToHexUtf8[_byte13]; + destInt16[16] = TableToHexUtf8[_byte14]; + destInt16[17] = TableToHexUtf8[_byte15]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + private void FormatUtf8X(byte* dest) + { + const ushort zeroXUtf8 = ('x' << 8) | '0'; // 0x + const ushort commaBraceUtf8 = ('{' << 8) | ','; // ,{ + const ushort closeBracesUtf8 = ('}' << 8) | '}'; // }} + + // {0xdddddddd,0xdddd,0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}} + var destInt16 = (ushort*) dest; + var destInt16AsInt8 = (byte**) &destInt16; + dest[0] = Utf8LeftCurlyBracket; + dest[11] = dest[18] = dest[31] = dest[36] = dest[41] = dest[46] = dest[51] = dest[56] = dest[61] = Utf8Comma; + destInt16[6] = destInt16[16] = destInt16[21] = destInt16[26] = destInt16[31] = zeroXUtf8; // 0x + destInt16[7] = TableToHexUtf8[_byte4]; + destInt16[8] = TableToHexUtf8[_byte5]; + destInt16[17] = TableToHexUtf8[_byte9]; + destInt16[22] = TableToHexUtf8[_byte11]; + destInt16[27] = TableToHexUtf8[_byte13]; + destInt16[32] = TableToHexUtf8[_byte15]; + destInt16[33] = closeBracesUtf8; // }} + *destInt16AsInt8 += 1; + destInt16[0] = destInt16[9] = destInt16[13] = destInt16[18] = destInt16[23] = destInt16[28] = zeroXUtf8; // 0x + destInt16[1] = TableToHexUtf8[_byte0]; + destInt16[2] = TableToHexUtf8[_byte1]; + destInt16[3] = TableToHexUtf8[_byte2]; + destInt16[4] = TableToHexUtf8[_byte3]; + destInt16[10] = TableToHexUtf8[_byte6]; + destInt16[11] = TableToHexUtf8[_byte7]; + destInt16[12] = commaBraceUtf8; // ,{ + destInt16[14] = TableToHexUtf8[_byte8]; + destInt16[19] = TableToHexUtf8[_byte10]; + destInt16[24] = TableToHexUtf8[_byte12]; + destInt16[29] = TableToHexUtf8[_byte14]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + private void FormatUtf16N(char* dest) + { + // dddddddddddddddddddddddddddddddd + var destInt32 = (uint*) dest; + destInt32[0] = TableToHexUtf16[_byte0]; + destInt32[1] = TableToHexUtf16[_byte1]; + destInt32[2] = TableToHexUtf16[_byte2]; + destInt32[3] = TableToHexUtf16[_byte3]; + destInt32[4] = TableToHexUtf16[_byte4]; + destInt32[5] = TableToHexUtf16[_byte5]; + destInt32[6] = TableToHexUtf16[_byte6]; + destInt32[7] = TableToHexUtf16[_byte7]; + destInt32[8] = TableToHexUtf16[_byte8]; + destInt32[9] = TableToHexUtf16[_byte9]; + destInt32[10] = TableToHexUtf16[_byte10]; + destInt32[11] = TableToHexUtf16[_byte11]; + destInt32[12] = TableToHexUtf16[_byte12]; + destInt32[13] = TableToHexUtf16[_byte13]; + destInt32[14] = TableToHexUtf16[_byte14]; + destInt32[15] = TableToHexUtf16[_byte15]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + private void FormatUtf16D(char* dest) + { + // dddddddd-dddd-dddd-dddd-dddddddddddd + var destInt32 = (uint*) dest; + var destInt32AsInt16 = (char**) &destInt32; dest[8] = dest[13] = dest[18] = dest[23] = '-'; - destUints[0] = TableToHex[_byte0]; - destUints[1] = TableToHex[_byte1]; - destUints[2] = TableToHex[_byte2]; - destUints[3] = TableToHex[_byte3]; - destUints[7] = TableToHex[_byte6]; - destUints[8] = TableToHex[_byte7]; - destUints[12] = TableToHex[_byte10]; - destUints[13] = TableToHex[_byte11]; - destUints[14] = TableToHex[_byte12]; - destUints[15] = TableToHex[_byte13]; - destUints[16] = TableToHex[_byte14]; - destUints[17] = TableToHex[_byte15]; - *destUintsAsChars += 1; - destUints[4] = TableToHex[_byte4]; - destUints[5] = TableToHex[_byte5]; - destUints[9] = TableToHex[_byte8]; - destUints[10] = TableToHex[_byte9]; + destInt32[0] = TableToHexUtf16[_byte0]; + destInt32[1] = TableToHexUtf16[_byte1]; + destInt32[2] = TableToHexUtf16[_byte2]; + destInt32[3] = TableToHexUtf16[_byte3]; + destInt32[7] = TableToHexUtf16[_byte6]; + destInt32[8] = TableToHexUtf16[_byte7]; + destInt32[12] = TableToHexUtf16[_byte10]; + destInt32[13] = TableToHexUtf16[_byte11]; + destInt32[14] = TableToHexUtf16[_byte12]; + destInt32[15] = TableToHexUtf16[_byte13]; + destInt32[16] = TableToHexUtf16[_byte14]; + destInt32[17] = TableToHexUtf16[_byte15]; + *destInt32AsInt16 += 1; + destInt32[4] = TableToHexUtf16[_byte4]; + destInt32[5] = TableToHexUtf16[_byte5]; + destInt32[9] = TableToHexUtf16[_byte8]; + destInt32[10] = TableToHexUtf16[_byte9]; } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - private void FormatB(char* dest) + private void FormatUtf16B(char* dest) { // {dddddddd-dddd-dddd-dddd-dddddddddddd} - var destUints = (uint*) dest; - var destUintsAsChars = (char**) &destUints; + var destInt32 = (uint*) dest; + var destInt32AsInt16 = (char**) &destInt32; dest[0] = '{'; dest[9] = dest[14] = dest[19] = dest[24] = '-'; dest[37] = '}'; - destUints[5] = TableToHex[_byte4]; - destUints[6] = TableToHex[_byte5]; - destUints[10] = TableToHex[_byte8]; - destUints[11] = TableToHex[_byte9]; - *destUintsAsChars += 1; - destUints[0] = TableToHex[_byte0]; - destUints[1] = TableToHex[_byte1]; - destUints[2] = TableToHex[_byte2]; - destUints[3] = TableToHex[_byte3]; - destUints[7] = TableToHex[_byte6]; - destUints[8] = TableToHex[_byte7]; - destUints[12] = TableToHex[_byte10]; - destUints[13] = TableToHex[_byte11]; - destUints[14] = TableToHex[_byte12]; - destUints[15] = TableToHex[_byte13]; - destUints[16] = TableToHex[_byte14]; - destUints[17] = TableToHex[_byte15]; + destInt32[5] = TableToHexUtf16[_byte4]; + destInt32[6] = TableToHexUtf16[_byte5]; + destInt32[10] = TableToHexUtf16[_byte8]; + destInt32[11] = TableToHexUtf16[_byte9]; + *destInt32AsInt16 += 1; + destInt32[0] = TableToHexUtf16[_byte0]; + destInt32[1] = TableToHexUtf16[_byte1]; + destInt32[2] = TableToHexUtf16[_byte2]; + destInt32[3] = TableToHexUtf16[_byte3]; + destInt32[7] = TableToHexUtf16[_byte6]; + destInt32[8] = TableToHexUtf16[_byte7]; + destInt32[12] = TableToHexUtf16[_byte10]; + destInt32[13] = TableToHexUtf16[_byte11]; + destInt32[14] = TableToHexUtf16[_byte12]; + destInt32[15] = TableToHexUtf16[_byte13]; + destInt32[16] = TableToHexUtf16[_byte14]; + destInt32[17] = TableToHexUtf16[_byte15]; } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - private void FormatP(char* dest) + private void FormatUtf16P(char* dest) { // (dddddddd-dddd-dddd-dddd-dddddddddddd) - var destUints = (uint*) dest; - var destUintsAsChars = (char**) &destUints; + var destInt32 = (uint*) dest; + var destInt32AsInt16 = (char**) &destInt32; dest[0] = '('; dest[9] = dest[14] = dest[19] = dest[24] = '-'; dest[37] = ')'; - destUints[5] = TableToHex[_byte4]; - destUints[6] = TableToHex[_byte5]; - destUints[10] = TableToHex[_byte8]; - destUints[11] = TableToHex[_byte9]; - *destUintsAsChars += 1; - destUints[0] = TableToHex[_byte0]; - destUints[1] = TableToHex[_byte1]; - destUints[2] = TableToHex[_byte2]; - destUints[3] = TableToHex[_byte3]; - destUints[7] = TableToHex[_byte6]; - destUints[8] = TableToHex[_byte7]; - destUints[12] = TableToHex[_byte10]; - destUints[13] = TableToHex[_byte11]; - destUints[14] = TableToHex[_byte12]; - destUints[15] = TableToHex[_byte13]; - destUints[16] = TableToHex[_byte14]; - destUints[17] = TableToHex[_byte15]; - } - - private const uint ZeroX = 7864368; // 0x - private const uint CommaBrace = 8060972; // ,{ - private const uint CloseBraces = 8192125; // }} + destInt32[5] = TableToHexUtf16[_byte4]; + destInt32[6] = TableToHexUtf16[_byte5]; + destInt32[10] = TableToHexUtf16[_byte8]; + destInt32[11] = TableToHexUtf16[_byte9]; + *destInt32AsInt16 += 1; + destInt32[0] = TableToHexUtf16[_byte0]; + destInt32[1] = TableToHexUtf16[_byte1]; + destInt32[2] = TableToHexUtf16[_byte2]; + destInt32[3] = TableToHexUtf16[_byte3]; + destInt32[7] = TableToHexUtf16[_byte6]; + destInt32[8] = TableToHexUtf16[_byte7]; + destInt32[12] = TableToHexUtf16[_byte10]; + destInt32[13] = TableToHexUtf16[_byte11]; + destInt32[14] = TableToHexUtf16[_byte12]; + destInt32[15] = TableToHexUtf16[_byte13]; + destInt32[16] = TableToHexUtf16[_byte14]; + destInt32[17] = TableToHexUtf16[_byte15]; + } + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - private void FormatX(char* dest) + private void FormatUtf16X(char* dest) { + const uint zeroXUtf16 = ((uint) 'x' << 16) | '0'; // 0x + const uint commaBraceUtf16 = ((uint) '{' << 16) | ','; // ,{ + const uint closeBracesUtf16 = ((uint) '}' << 16) | '}'; // }} + // {0xdddddddd,0xdddd,0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}} - var destUints = (uint*) dest; - var uintDestAsChars = (char**) &destUints; + var destInt32 = (uint*) dest; + var destInt32AsInt16 = (char**) &destInt32; dest[0] = '{'; dest[11] = dest[18] = dest[31] = dest[36] = dest[41] = dest[46] = dest[51] = dest[56] = dest[61] = ','; - destUints[6] = destUints[16] = destUints[21] = destUints[26] = destUints[31] = ZeroX; // 0x - destUints[7] = TableToHex[_byte4]; - destUints[8] = TableToHex[_byte5]; - destUints[17] = TableToHex[_byte9]; - destUints[22] = TableToHex[_byte11]; - destUints[27] = TableToHex[_byte13]; - destUints[32] = TableToHex[_byte15]; - destUints[33] = CloseBraces; // }} - *uintDestAsChars += 1; - destUints[0] = destUints[9] = destUints[13] = destUints[18] = destUints[23] = destUints[28] = ZeroX; // 0x - destUints[1] = TableToHex[_byte0]; - destUints[2] = TableToHex[_byte1]; - destUints[3] = TableToHex[_byte2]; - destUints[4] = TableToHex[_byte3]; - destUints[10] = TableToHex[_byte6]; - destUints[11] = TableToHex[_byte7]; - destUints[12] = CommaBrace; // ,{ - destUints[14] = TableToHex[_byte8]; - destUints[19] = TableToHex[_byte10]; - destUints[24] = TableToHex[_byte12]; - destUints[29] = TableToHex[_byte14]; + destInt32[6] = destInt32[16] = destInt32[21] = destInt32[26] = destInt32[31] = zeroXUtf16; // 0x + destInt32[7] = TableToHexUtf16[_byte4]; + destInt32[8] = TableToHexUtf16[_byte5]; + destInt32[17] = TableToHexUtf16[_byte9]; + destInt32[22] = TableToHexUtf16[_byte11]; + destInt32[27] = TableToHexUtf16[_byte13]; + destInt32[32] = TableToHexUtf16[_byte15]; + destInt32[33] = closeBracesUtf16; // }} + *destInt32AsInt16 += 1; + destInt32[0] = destInt32[9] = destInt32[13] = destInt32[18] = destInt32[23] = destInt32[28] = zeroXUtf16; // 0x + destInt32[1] = TableToHexUtf16[_byte0]; + destInt32[2] = TableToHexUtf16[_byte1]; + destInt32[3] = TableToHexUtf16[_byte2]; + destInt32[4] = TableToHexUtf16[_byte3]; + destInt32[10] = TableToHexUtf16[_byte6]; + destInt32[11] = TableToHexUtf16[_byte7]; + destInt32[12] = commaBraceUtf16; // ,{ + destInt32[14] = TableToHexUtf16[_byte8]; + destInt32[19] = TableToHexUtf16[_byte10]; + destInt32[24] = TableToHexUtf16[_byte12]; + destInt32[29] = TableToHexUtf16[_byte14]; } /// @@ -1103,7 +1370,7 @@ public static Uuid Parse(ReadOnlySpan input) /// is not in the format specified by . public static Uuid ParseExact( string input, -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif string format) @@ -1181,7 +1448,7 @@ public static Uuid ParseExact( /// is not in the format specified by . public static Uuid ParseExact( ReadOnlySpan input, -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif ReadOnlySpan format) @@ -1372,7 +1639,7 @@ public static bool TryParse(ReadOnlySpan uuidUtf8String, out Uuid output) /// if the parse operation was successful; otherwise, . public static bool TryParseExact( [NotNullWhen(true)] string? input, -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif string format, @@ -1463,7 +1730,7 @@ public static bool TryParseExact( /// if the parse operation was successful; otherwise, . public static bool TryParseExact( ReadOnlySpan input, -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.GuidFormat)] #endif ReadOnlySpan format, @@ -1719,6 +1986,11 @@ private static bool ParseWithoutExceptionsX(uint uuidStringLength, char* uuidStr /// private const byte Utf8Comma = 0x2C; + /// + /// - + /// + private const byte Utf8Dash = 0x2D; + private static bool ParseWithoutExceptionsUtf8(ReadOnlySpan uuidUtf8String, byte* uuidUtf8StringPtr, byte* resultPtr) { var length = (uint) uuidUtf8String.Length; @@ -2059,115 +2331,115 @@ private static bool TryParsePtrN(char* value, byte* resultPtr) byte hi; byte lo; // 0 byte - if (value[0] < MaximalChar - && (hi = TableFromHexToBytes[value[0]]) != 0xFF - && value[1] < MaximalChar - && (lo = TableFromHexToBytes[value[1]]) != 0xFF) + if (value[0] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[0]]) != 0xFF + && value[1] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[1]]) != 0xFF) { resultPtr[0] = (byte) ((byte) (hi << 4) | lo); // 1 byte - if (value[2] < MaximalChar - && (hi = TableFromHexToBytes[value[2]]) != 0xFF - && value[3] < MaximalChar - && (lo = TableFromHexToBytes[value[3]]) != 0xFF) + if (value[2] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[2]]) != 0xFF + && value[3] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[3]]) != 0xFF) { resultPtr[1] = (byte) ((byte) (hi << 4) | lo); // 2 byte - if (value[4] < MaximalChar - && (hi = TableFromHexToBytes[value[4]]) != 0xFF - && value[5] < MaximalChar - && (lo = TableFromHexToBytes[value[5]]) != 0xFF) + if (value[4] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[4]]) != 0xFF + && value[5] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[5]]) != 0xFF) { resultPtr[2] = (byte) ((byte) (hi << 4) | lo); // 3 byte - if (value[6] < MaximalChar - && (hi = TableFromHexToBytes[value[6]]) != 0xFF - && value[7] < MaximalChar - && (lo = TableFromHexToBytes[value[7]]) != 0xFF) + if (value[6] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[6]]) != 0xFF + && value[7] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[7]]) != 0xFF) { resultPtr[3] = (byte) ((byte) (hi << 4) | lo); // 4 byte - if (value[8] < MaximalChar - && (hi = TableFromHexToBytes[value[8]]) != 0xFF - && value[9] < MaximalChar - && (lo = TableFromHexToBytes[value[9]]) != 0xFF) + if (value[8] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[8]]) != 0xFF + && value[9] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[9]]) != 0xFF) { resultPtr[4] = (byte) ((byte) (hi << 4) | lo); // 5 byte - if (value[10] < MaximalChar - && (hi = TableFromHexToBytes[value[10]]) != 0xFF - && value[11] < MaximalChar - && (lo = TableFromHexToBytes[value[11]]) != 0xFF) + if (value[10] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[10]]) != 0xFF + && value[11] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[11]]) != 0xFF) { resultPtr[5] = (byte) ((byte) (hi << 4) | lo); // 6 byte - if (value[12] < MaximalChar - && (hi = TableFromHexToBytes[value[12]]) != 0xFF - && value[13] < MaximalChar - && (lo = TableFromHexToBytes[value[13]]) != 0xFF) + if (value[12] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[12]]) != 0xFF + && value[13] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[13]]) != 0xFF) { resultPtr[6] = (byte) ((byte) (hi << 4) | lo); // 7 byte - if (value[14] < MaximalChar - && (hi = TableFromHexToBytes[value[14]]) != 0xFF - && value[15] < MaximalChar - && (lo = TableFromHexToBytes[value[15]]) != 0xFF) + if (value[14] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[14]]) != 0xFF + && value[15] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[15]]) != 0xFF) { resultPtr[7] = (byte) ((byte) (hi << 4) | lo); // 8 byte - if (value[16] < MaximalChar - && (hi = TableFromHexToBytes[value[16]]) != 0xFF - && value[17] < MaximalChar - && (lo = TableFromHexToBytes[value[17]]) != 0xFF) + if (value[16] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[16]]) != 0xFF + && value[17] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[17]]) != 0xFF) { resultPtr[8] = (byte) ((byte) (hi << 4) | lo); // 9 byte - if (value[18] < MaximalChar - && (hi = TableFromHexToBytes[value[18]]) != 0xFF - && value[19] < MaximalChar - && (lo = TableFromHexToBytes[value[19]]) != 0xFF) + if (value[18] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[18]]) != 0xFF + && value[19] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[19]]) != 0xFF) { resultPtr[9] = (byte) ((byte) (hi << 4) | lo); // 10 byte - if (value[20] < MaximalChar - && (hi = TableFromHexToBytes[value[20]]) != 0xFF - && value[21] < MaximalChar - && (lo = TableFromHexToBytes[value[21]]) != 0xFF) + if (value[20] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[20]]) != 0xFF + && value[21] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[21]]) != 0xFF) { resultPtr[10] = (byte) ((byte) (hi << 4) | lo); // 11 byte - if (value[22] < MaximalChar - && (hi = TableFromHexToBytes[value[22]]) != 0xFF - && value[23] < MaximalChar - && (lo = TableFromHexToBytes[value[23]]) != 0xFF) + if (value[22] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[22]]) != 0xFF + && value[23] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[23]]) != 0xFF) { resultPtr[11] = (byte) ((byte) (hi << 4) | lo); // 12 byte - if (value[24] < MaximalChar - && (hi = TableFromHexToBytes[value[24]]) != 0xFF - && value[25] < MaximalChar - && (lo = TableFromHexToBytes[value[25]]) != 0xFF) + if (value[24] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[24]]) != 0xFF + && value[25] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[25]]) != 0xFF) { resultPtr[12] = (byte) ((byte) (hi << 4) | lo); // 13 byte - if (value[26] < MaximalChar - && (hi = TableFromHexToBytes[value[26]]) != 0xFF - && value[27] < MaximalChar - && (lo = TableFromHexToBytes[value[27]]) != 0xFF) + if (value[26] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[26]]) != 0xFF + && value[27] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[27]]) != 0xFF) { resultPtr[13] = (byte) ((byte) (hi << 4) | lo); // 14 byte - if (value[28] < MaximalChar - && (hi = TableFromHexToBytes[value[28]]) != 0xFF - && value[29] < MaximalChar - && (lo = TableFromHexToBytes[value[29]]) != 0xFF) + if (value[28] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[28]]) != 0xFF + && value[29] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[29]]) != 0xFF) { resultPtr[14] = (byte) ((byte) (hi << 4) | lo); // 15 byte - if (value[30] < MaximalChar - && (hi = TableFromHexToBytes[value[30]]) != 0xFF - && value[31] < MaximalChar - && (lo = TableFromHexToBytes[value[31]]) != 0xFF) + if (value[30] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[30]]) != 0xFF + && value[31] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[31]]) != 0xFF) { resultPtr[15] = (byte) ((byte) (hi << 4) | lo); return true; @@ -2198,127 +2470,127 @@ private static bool TryParsePtrD(char* value, byte* resultPtr) byte hi; byte lo; // 0 byte - if (value[0] < MaximalChar - && (hi = TableFromHexToBytes[value[0]]) != 0xFF - && value[1] < MaximalChar - && (lo = TableFromHexToBytes[value[1]]) != 0xFF) + if (value[0] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[0]]) != 0xFF + && value[1] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[1]]) != 0xFF) { resultPtr[0] = (byte) ((byte) (hi << 4) | lo); // 1 byte - if (value[2] < MaximalChar - && (hi = TableFromHexToBytes[value[2]]) != 0xFF - && value[3] < MaximalChar - && (lo = TableFromHexToBytes[value[3]]) != 0xFF) + if (value[2] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[2]]) != 0xFF + && value[3] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[3]]) != 0xFF) { resultPtr[1] = (byte) ((byte) (hi << 4) | lo); // 2 byte - if (value[4] < MaximalChar - && (hi = TableFromHexToBytes[value[4]]) != 0xFF - && value[5] < MaximalChar - && (lo = TableFromHexToBytes[value[5]]) != 0xFF) + if (value[4] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[4]]) != 0xFF + && value[5] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[5]]) != 0xFF) { resultPtr[2] = (byte) ((byte) (hi << 4) | lo); // 3 byte - if (value[6] < MaximalChar - && (hi = TableFromHexToBytes[value[6]]) != 0xFF - && value[7] < MaximalChar - && (lo = TableFromHexToBytes[value[7]]) != 0xFF) + if (value[6] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[6]]) != 0xFF + && value[7] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[7]]) != 0xFF) { resultPtr[3] = (byte) ((byte) (hi << 4) | lo); // value[8] == '-' // 4 byte - if (value[9] < MaximalChar - && (hi = TableFromHexToBytes[value[9]]) != 0xFF - && value[10] < MaximalChar - && (lo = TableFromHexToBytes[value[10]]) != 0xFF) + if (value[9] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[9]]) != 0xFF + && value[10] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[10]]) != 0xFF) { resultPtr[4] = (byte) ((byte) (hi << 4) | lo); // 5 byte - if (value[11] < MaximalChar - && (hi = TableFromHexToBytes[value[11]]) != 0xFF - && value[12] < MaximalChar - && (lo = TableFromHexToBytes[value[12]]) != 0xFF) + if (value[11] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[11]]) != 0xFF + && value[12] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[12]]) != 0xFF) { resultPtr[5] = (byte) ((byte) (hi << 4) | lo); // value[13] == '-' // 6 byte - if (value[14] < MaximalChar - && (hi = TableFromHexToBytes[value[14]]) != 0xFF - && value[15] < MaximalChar - && (lo = TableFromHexToBytes[value[15]]) != 0xFF) + if (value[14] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[14]]) != 0xFF + && value[15] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[15]]) != 0xFF) { resultPtr[6] = (byte) ((byte) (hi << 4) | lo); // 7 byte - if (value[16] < MaximalChar - && (hi = TableFromHexToBytes[value[16]]) != 0xFF - && value[17] < MaximalChar - && (lo = TableFromHexToBytes[value[17]]) != 0xFF) + if (value[16] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[16]]) != 0xFF + && value[17] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[17]]) != 0xFF) { resultPtr[7] = (byte) ((byte) (hi << 4) | lo); // value[18] == '-' // 8 byte - if (value[19] < MaximalChar - && (hi = TableFromHexToBytes[value[19]]) != 0xFF - && value[20] < MaximalChar - && (lo = TableFromHexToBytes[value[20]]) != 0xFF) + if (value[19] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[19]]) != 0xFF + && value[20] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[20]]) != 0xFF) { resultPtr[8] = (byte) ((byte) (hi << 4) | lo); // 9 byte - if (value[21] < MaximalChar - && (hi = TableFromHexToBytes[value[21]]) != 0xFF - && value[22] < MaximalChar - && (lo = TableFromHexToBytes[value[22]]) != 0xFF) + if (value[21] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[21]]) != 0xFF + && value[22] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[22]]) != 0xFF) { resultPtr[9] = (byte) ((byte) (hi << 4) | lo); // value[23] == '-' // 10 byte - if (value[24] < MaximalChar - && (hi = TableFromHexToBytes[value[24]]) != 0xFF - && value[25] < MaximalChar - && (lo = TableFromHexToBytes[value[25]]) != 0xFF) + if (value[24] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[24]]) != 0xFF + && value[25] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[25]]) != 0xFF) { resultPtr[10] = (byte) ((byte) (hi << 4) | lo); // 11 byte - if (value[26] < MaximalChar - && (hi = TableFromHexToBytes[value[26]]) != 0xFF - && value[27] < MaximalChar - && (lo = TableFromHexToBytes[value[27]]) != 0xFF) + if (value[26] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[26]]) != 0xFF + && value[27] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[27]]) != 0xFF) { resultPtr[11] = (byte) ((byte) (hi << 4) | lo); // 12 byte - if (value[28] < MaximalChar - && (hi = TableFromHexToBytes[value[28]]) != 0xFF - && value[29] < MaximalChar - && (lo = TableFromHexToBytes[value[29]]) != 0xFF) + if (value[28] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[28]]) != 0xFF + && value[29] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[29]]) != 0xFF) { resultPtr[12] = (byte) ((byte) (hi << 4) | lo); // 13 byte - if (value[30] < MaximalChar - && (hi = TableFromHexToBytes[value[30]]) != 0xFF - && value[31] < MaximalChar - && (lo = TableFromHexToBytes[value[31]]) != 0xFF) + if (value[30] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[30]]) != 0xFF + && value[31] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[31]]) != 0xFF) { resultPtr[13] = (byte) ((byte) (hi << 4) | lo); // 14 byte - if (value[32] < MaximalChar - && (hi = TableFromHexToBytes[value[32]]) != 0xFF - && value[33] < MaximalChar - && (lo = TableFromHexToBytes[value[33]]) != 0xFF) + if (value[32] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[32]]) != 0xFF + && value[33] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[33]]) != 0xFF) { resultPtr[14] = (byte) ((byte) (hi << 4) | lo); // 15 byte - if (value[34] < MaximalChar - && (hi = TableFromHexToBytes[value[34]]) != 0xFF - && value[35] < MaximalChar - && (lo = TableFromHexToBytes[value[35]]) != 0xFF) + if (value[34] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[34]]) != 0xFF + && value[35] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[35]]) != 0xFF) { resultPtr[15] = (byte) ((byte) (hi << 4) | lo); return true; @@ -2353,31 +2625,31 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[1] == '0' // value[2] == 'x' // 0 byte - if (value[3] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[3]]) != 0xFF - && value[4] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[4]]) != 0xFF) + if (value[3] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[3]]) != 0xFF + && value[4] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[4]]) != 0xFF) { resultPtr[0] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 1 byte - if (value[5] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[5]]) != 0xFF - && value[6] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[6]]) != 0xFF) + if (value[5] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[5]]) != 0xFF + && value[6] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[6]]) != 0xFF) { resultPtr[1] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 2 byte - if (value[7] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[7]]) != 0xFF - && value[8] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[8]]) != 0xFF) + if (value[7] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[7]]) != 0xFF + && value[8] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[8]]) != 0xFF) { resultPtr[2] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 3 byte - if (value[9] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[9]]) != 0xFF - && value[10] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[10]]) != 0xFF) + if (value[9] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[9]]) != 0xFF + && value[10] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[10]]) != 0xFF) { resultPtr[3] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2386,17 +2658,17 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[13] == 'x' // 4 byte - if (value[14] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[14]]) != 0xFF - && value[15] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[15]]) != 0xFF) + if (value[14] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[14]]) != 0xFF + && value[15] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[15]]) != 0xFF) { resultPtr[4] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 5 byte - if (value[16] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[16]]) != 0xFF - && value[17] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[17]]) != 0xFF) + if (value[16] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[16]]) != 0xFF + && value[17] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[17]]) != 0xFF) { resultPtr[5] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2405,17 +2677,17 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[20] == 'x' // 6 byte - if (value[21] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[21]]) != 0xFF - && value[22] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[22]]) != 0xFF) + if (value[21] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[21]]) != 0xFF + && value[22] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[22]]) != 0xFF) { resultPtr[6] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 7 byte - if (value[23] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[23]]) != 0xFF - && value[24] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[24]]) != 0xFF) + if (value[23] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[23]]) != 0xFF + && value[24] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[24]]) != 0xFF) { resultPtr[7] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2425,10 +2697,10 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[28] == 'x' // 8 byte - if (value[29] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[29]]) != 0xFF - && value[30] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[30]]) != 0xFF) + if (value[29] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[29]]) != 0xFF + && value[30] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[30]]) != 0xFF) { resultPtr[8] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2437,10 +2709,10 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[33] == 'x' // 9 byte - if (value[34] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[34]]) != 0xFF - && value[35] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[35]]) != 0xFF) + if (value[34] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[34]]) != 0xFF + && value[35] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[35]]) != 0xFF) { resultPtr[9] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2449,10 +2721,10 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[38] == 'x' // 10 byte - if (value[39] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[39]]) != 0xFF - && value[40] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[40]]) != 0xFF) + if (value[39] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[39]]) != 0xFF + && value[40] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[40]]) != 0xFF) { resultPtr[10] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2461,10 +2733,10 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[43] == 'x' // 11 byte - if (value[44] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[44]]) != 0xFF - && value[45] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[45]]) != 0xFF) + if (value[44] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[44]]) != 0xFF + && value[45] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[45]]) != 0xFF) { resultPtr[11] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2473,10 +2745,10 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[48] == 'x' // 12 byte - if (value[49] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[49]]) != 0xFF - && value[50] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[50]]) != 0xFF) + if (value[49] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[49]]) != 0xFF + && value[50] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[50]]) != 0xFF) { resultPtr[12] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2485,10 +2757,10 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[53] == 'x' // 13 byte - if (value[54] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[54]]) != 0xFF - && value[55] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[55]]) != 0xFF) + if (value[54] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[54]]) != 0xFF + && value[55] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[55]]) != 0xFF) { resultPtr[13] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2497,10 +2769,10 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[58] == 'x' // 14 byte - if (value[59] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[59]]) != 0xFF - && value[60] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[60]]) != 0xFF) + if (value[59] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[59]]) != 0xFF + && value[60] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[60]]) != 0xFF) { resultPtr[14] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2509,10 +2781,10 @@ private static bool TryParsePtrX(char* value, byte* resultPtr) // value[63] == 'x' // 15 byte - if (value[64] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[64]]) != 0xFF - && value[65] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[65]]) != 0xFF) + if (value[64] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[64]]) != 0xFF + && value[65] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[65]]) != 0xFF) { resultPtr[15] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); return true; @@ -2543,115 +2815,115 @@ private static bool TryParsePtrNUtf8(byte* value, byte* resultPtr) byte hi; byte lo; // 0 byte - if (value[0] < MaximalChar - && (hi = TableFromHexToBytes[value[0]]) != 0xFF - && value[1] < MaximalChar - && (lo = TableFromHexToBytes[value[1]]) != 0xFF) + if (value[0] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[0]]) != 0xFF + && value[1] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[1]]) != 0xFF) { resultPtr[0] = (byte) ((byte) (hi << 4) | lo); // 1 byte - if (value[2] < MaximalChar - && (hi = TableFromHexToBytes[value[2]]) != 0xFF - && value[3] < MaximalChar - && (lo = TableFromHexToBytes[value[3]]) != 0xFF) + if (value[2] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[2]]) != 0xFF + && value[3] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[3]]) != 0xFF) { resultPtr[1] = (byte) ((byte) (hi << 4) | lo); // 2 byte - if (value[4] < MaximalChar - && (hi = TableFromHexToBytes[value[4]]) != 0xFF - && value[5] < MaximalChar - && (lo = TableFromHexToBytes[value[5]]) != 0xFF) + if (value[4] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[4]]) != 0xFF + && value[5] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[5]]) != 0xFF) { resultPtr[2] = (byte) ((byte) (hi << 4) | lo); // 3 byte - if (value[6] < MaximalChar - && (hi = TableFromHexToBytes[value[6]]) != 0xFF - && value[7] < MaximalChar - && (lo = TableFromHexToBytes[value[7]]) != 0xFF) + if (value[6] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[6]]) != 0xFF + && value[7] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[7]]) != 0xFF) { resultPtr[3] = (byte) ((byte) (hi << 4) | lo); // 4 byte - if (value[8] < MaximalChar - && (hi = TableFromHexToBytes[value[8]]) != 0xFF - && value[9] < MaximalChar - && (lo = TableFromHexToBytes[value[9]]) != 0xFF) + if (value[8] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[8]]) != 0xFF + && value[9] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[9]]) != 0xFF) { resultPtr[4] = (byte) ((byte) (hi << 4) | lo); // 5 byte - if (value[10] < MaximalChar - && (hi = TableFromHexToBytes[value[10]]) != 0xFF - && value[11] < MaximalChar - && (lo = TableFromHexToBytes[value[11]]) != 0xFF) + if (value[10] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[10]]) != 0xFF + && value[11] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[11]]) != 0xFF) { resultPtr[5] = (byte) ((byte) (hi << 4) | lo); // 6 byte - if (value[12] < MaximalChar - && (hi = TableFromHexToBytes[value[12]]) != 0xFF - && value[13] < MaximalChar - && (lo = TableFromHexToBytes[value[13]]) != 0xFF) + if (value[12] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[12]]) != 0xFF + && value[13] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[13]]) != 0xFF) { resultPtr[6] = (byte) ((byte) (hi << 4) | lo); // 7 byte - if (value[14] < MaximalChar - && (hi = TableFromHexToBytes[value[14]]) != 0xFF - && value[15] < MaximalChar - && (lo = TableFromHexToBytes[value[15]]) != 0xFF) + if (value[14] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[14]]) != 0xFF + && value[15] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[15]]) != 0xFF) { resultPtr[7] = (byte) ((byte) (hi << 4) | lo); // 8 byte - if (value[16] < MaximalChar - && (hi = TableFromHexToBytes[value[16]]) != 0xFF - && value[17] < MaximalChar - && (lo = TableFromHexToBytes[value[17]]) != 0xFF) + if (value[16] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[16]]) != 0xFF + && value[17] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[17]]) != 0xFF) { resultPtr[8] = (byte) ((byte) (hi << 4) | lo); // 9 byte - if (value[18] < MaximalChar - && (hi = TableFromHexToBytes[value[18]]) != 0xFF - && value[19] < MaximalChar - && (lo = TableFromHexToBytes[value[19]]) != 0xFF) + if (value[18] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[18]]) != 0xFF + && value[19] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[19]]) != 0xFF) { resultPtr[9] = (byte) ((byte) (hi << 4) | lo); // 10 byte - if (value[20] < MaximalChar - && (hi = TableFromHexToBytes[value[20]]) != 0xFF - && value[21] < MaximalChar - && (lo = TableFromHexToBytes[value[21]]) != 0xFF) + if (value[20] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[20]]) != 0xFF + && value[21] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[21]]) != 0xFF) { resultPtr[10] = (byte) ((byte) (hi << 4) | lo); // 11 byte - if (value[22] < MaximalChar - && (hi = TableFromHexToBytes[value[22]]) != 0xFF - && value[23] < MaximalChar - && (lo = TableFromHexToBytes[value[23]]) != 0xFF) + if (value[22] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[22]]) != 0xFF + && value[23] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[23]]) != 0xFF) { resultPtr[11] = (byte) ((byte) (hi << 4) | lo); // 12 byte - if (value[24] < MaximalChar - && (hi = TableFromHexToBytes[value[24]]) != 0xFF - && value[25] < MaximalChar - && (lo = TableFromHexToBytes[value[25]]) != 0xFF) + if (value[24] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[24]]) != 0xFF + && value[25] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[25]]) != 0xFF) { resultPtr[12] = (byte) ((byte) (hi << 4) | lo); // 13 byte - if (value[26] < MaximalChar - && (hi = TableFromHexToBytes[value[26]]) != 0xFF - && value[27] < MaximalChar - && (lo = TableFromHexToBytes[value[27]]) != 0xFF) + if (value[26] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[26]]) != 0xFF + && value[27] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[27]]) != 0xFF) { resultPtr[13] = (byte) ((byte) (hi << 4) | lo); // 14 byte - if (value[28] < MaximalChar - && (hi = TableFromHexToBytes[value[28]]) != 0xFF - && value[29] < MaximalChar - && (lo = TableFromHexToBytes[value[29]]) != 0xFF) + if (value[28] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[28]]) != 0xFF + && value[29] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[29]]) != 0xFF) { resultPtr[14] = (byte) ((byte) (hi << 4) | lo); // 15 byte - if (value[30] < MaximalChar - && (hi = TableFromHexToBytes[value[30]]) != 0xFF - && value[31] < MaximalChar - && (lo = TableFromHexToBytes[value[31]]) != 0xFF) + if (value[30] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[30]]) != 0xFF + && value[31] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[31]]) != 0xFF) { resultPtr[15] = (byte) ((byte) (hi << 4) | lo); return true; @@ -2682,127 +2954,127 @@ private static bool TryParsePtrDUtf8(byte* value, byte* resultPtr) byte hi; byte lo; // 0 byte - if (value[0] < MaximalChar - && (hi = TableFromHexToBytes[value[0]]) != 0xFF - && value[1] < MaximalChar - && (lo = TableFromHexToBytes[value[1]]) != 0xFF) + if (value[0] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[0]]) != 0xFF + && value[1] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[1]]) != 0xFF) { resultPtr[0] = (byte) ((byte) (hi << 4) | lo); // 1 byte - if (value[2] < MaximalChar - && (hi = TableFromHexToBytes[value[2]]) != 0xFF - && value[3] < MaximalChar - && (lo = TableFromHexToBytes[value[3]]) != 0xFF) + if (value[2] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[2]]) != 0xFF + && value[3] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[3]]) != 0xFF) { resultPtr[1] = (byte) ((byte) (hi << 4) | lo); // 2 byte - if (value[4] < MaximalChar - && (hi = TableFromHexToBytes[value[4]]) != 0xFF - && value[5] < MaximalChar - && (lo = TableFromHexToBytes[value[5]]) != 0xFF) + if (value[4] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[4]]) != 0xFF + && value[5] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[5]]) != 0xFF) { resultPtr[2] = (byte) ((byte) (hi << 4) | lo); // 3 byte - if (value[6] < MaximalChar - && (hi = TableFromHexToBytes[value[6]]) != 0xFF - && value[7] < MaximalChar - && (lo = TableFromHexToBytes[value[7]]) != 0xFF) + if (value[6] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[6]]) != 0xFF + && value[7] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[7]]) != 0xFF) { resultPtr[3] = (byte) ((byte) (hi << 4) | lo); // value[8] == '-' // 4 byte - if (value[9] < MaximalChar - && (hi = TableFromHexToBytes[value[9]]) != 0xFF - && value[10] < MaximalChar - && (lo = TableFromHexToBytes[value[10]]) != 0xFF) + if (value[9] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[9]]) != 0xFF + && value[10] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[10]]) != 0xFF) { resultPtr[4] = (byte) ((byte) (hi << 4) | lo); // 5 byte - if (value[11] < MaximalChar - && (hi = TableFromHexToBytes[value[11]]) != 0xFF - && value[12] < MaximalChar - && (lo = TableFromHexToBytes[value[12]]) != 0xFF) + if (value[11] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[11]]) != 0xFF + && value[12] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[12]]) != 0xFF) { resultPtr[5] = (byte) ((byte) (hi << 4) | lo); // value[13] == '-' // 6 byte - if (value[14] < MaximalChar - && (hi = TableFromHexToBytes[value[14]]) != 0xFF - && value[15] < MaximalChar - && (lo = TableFromHexToBytes[value[15]]) != 0xFF) + if (value[14] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[14]]) != 0xFF + && value[15] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[15]]) != 0xFF) { resultPtr[6] = (byte) ((byte) (hi << 4) | lo); // 7 byte - if (value[16] < MaximalChar - && (hi = TableFromHexToBytes[value[16]]) != 0xFF - && value[17] < MaximalChar - && (lo = TableFromHexToBytes[value[17]]) != 0xFF) + if (value[16] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[16]]) != 0xFF + && value[17] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[17]]) != 0xFF) { resultPtr[7] = (byte) ((byte) (hi << 4) | lo); // value[18] == '-' // 8 byte - if (value[19] < MaximalChar - && (hi = TableFromHexToBytes[value[19]]) != 0xFF - && value[20] < MaximalChar - && (lo = TableFromHexToBytes[value[20]]) != 0xFF) + if (value[19] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[19]]) != 0xFF + && value[20] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[20]]) != 0xFF) { resultPtr[8] = (byte) ((byte) (hi << 4) | lo); // 9 byte - if (value[21] < MaximalChar - && (hi = TableFromHexToBytes[value[21]]) != 0xFF - && value[22] < MaximalChar - && (lo = TableFromHexToBytes[value[22]]) != 0xFF) + if (value[21] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[21]]) != 0xFF + && value[22] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[22]]) != 0xFF) { resultPtr[9] = (byte) ((byte) (hi << 4) | lo); // value[23] == '-' // 10 byte - if (value[24] < MaximalChar - && (hi = TableFromHexToBytes[value[24]]) != 0xFF - && value[25] < MaximalChar - && (lo = TableFromHexToBytes[value[25]]) != 0xFF) + if (value[24] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[24]]) != 0xFF + && value[25] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[25]]) != 0xFF) { resultPtr[10] = (byte) ((byte) (hi << 4) | lo); // 11 byte - if (value[26] < MaximalChar - && (hi = TableFromHexToBytes[value[26]]) != 0xFF - && value[27] < MaximalChar - && (lo = TableFromHexToBytes[value[27]]) != 0xFF) + if (value[26] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[26]]) != 0xFF + && value[27] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[27]]) != 0xFF) { resultPtr[11] = (byte) ((byte) (hi << 4) | lo); // 12 byte - if (value[28] < MaximalChar - && (hi = TableFromHexToBytes[value[28]]) != 0xFF - && value[29] < MaximalChar - && (lo = TableFromHexToBytes[value[29]]) != 0xFF) + if (value[28] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[28]]) != 0xFF + && value[29] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[29]]) != 0xFF) { resultPtr[12] = (byte) ((byte) (hi << 4) | lo); // 13 byte - if (value[30] < MaximalChar - && (hi = TableFromHexToBytes[value[30]]) != 0xFF - && value[31] < MaximalChar - && (lo = TableFromHexToBytes[value[31]]) != 0xFF) + if (value[30] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[30]]) != 0xFF + && value[31] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[31]]) != 0xFF) { resultPtr[13] = (byte) ((byte) (hi << 4) | lo); // 14 byte - if (value[32] < MaximalChar - && (hi = TableFromHexToBytes[value[32]]) != 0xFF - && value[33] < MaximalChar - && (lo = TableFromHexToBytes[value[33]]) != 0xFF) + if (value[32] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[32]]) != 0xFF + && value[33] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[33]]) != 0xFF) { resultPtr[14] = (byte) ((byte) (hi << 4) | lo); // 15 byte - if (value[34] < MaximalChar - && (hi = TableFromHexToBytes[value[34]]) != 0xFF - && value[35] < MaximalChar - && (lo = TableFromHexToBytes[value[35]]) != 0xFF) + if (value[34] < MaximalCharUtf16 + && (hi = TableFromHexToBytesUtf16[value[34]]) != 0xFF + && value[35] < MaximalCharUtf16 + && (lo = TableFromHexToBytesUtf16[value[35]]) != 0xFF) { resultPtr[15] = (byte) ((byte) (hi << 4) | lo); return true; @@ -2837,31 +3109,31 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[1] == '0' // value[2] == 'x' // 0 byte - if (value[3] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[3]]) != 0xFF - && value[4] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[4]]) != 0xFF) + if (value[3] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[3]]) != 0xFF + && value[4] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[4]]) != 0xFF) { resultPtr[0] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 1 byte - if (value[5] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[5]]) != 0xFF - && value[6] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[6]]) != 0xFF) + if (value[5] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[5]]) != 0xFF + && value[6] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[6]]) != 0xFF) { resultPtr[1] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 2 byte - if (value[7] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[7]]) != 0xFF - && value[8] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[8]]) != 0xFF) + if (value[7] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[7]]) != 0xFF + && value[8] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[8]]) != 0xFF) { resultPtr[2] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 3 byte - if (value[9] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[9]]) != 0xFF - && value[10] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[10]]) != 0xFF) + if (value[9] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[9]]) != 0xFF + && value[10] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[10]]) != 0xFF) { resultPtr[3] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2870,17 +3142,17 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[13] == 'x' // 4 byte - if (value[14] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[14]]) != 0xFF - && value[15] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[15]]) != 0xFF) + if (value[14] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[14]]) != 0xFF + && value[15] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[15]]) != 0xFF) { resultPtr[4] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 5 byte - if (value[16] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[16]]) != 0xFF - && value[17] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[17]]) != 0xFF) + if (value[16] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[16]]) != 0xFF + && value[17] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[17]]) != 0xFF) { resultPtr[5] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2889,17 +3161,17 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[20] == 'x' // 6 byte - if (value[21] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[21]]) != 0xFF - && value[22] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[22]]) != 0xFF) + if (value[21] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[21]]) != 0xFF + && value[22] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[22]]) != 0xFF) { resultPtr[6] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); // 7 byte - if (value[23] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[23]]) != 0xFF - && value[24] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[24]]) != 0xFF) + if (value[23] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[23]]) != 0xFF + && value[24] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[24]]) != 0xFF) { resultPtr[7] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2909,10 +3181,10 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[28] == 'x' // 8 byte - if (value[29] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[29]]) != 0xFF - && value[30] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[30]]) != 0xFF) + if (value[29] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[29]]) != 0xFF + && value[30] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[30]]) != 0xFF) { resultPtr[8] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2921,10 +3193,10 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[33] == 'x' // 9 byte - if (value[34] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[34]]) != 0xFF - && value[35] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[35]]) != 0xFF) + if (value[34] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[34]]) != 0xFF + && value[35] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[35]]) != 0xFF) { resultPtr[9] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2933,10 +3205,10 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[38] == 'x' // 10 byte - if (value[39] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[39]]) != 0xFF - && value[40] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[40]]) != 0xFF) + if (value[39] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[39]]) != 0xFF + && value[40] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[40]]) != 0xFF) { resultPtr[10] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2945,10 +3217,10 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[43] == 'x' // 11 byte - if (value[44] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[44]]) != 0xFF - && value[45] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[45]]) != 0xFF) + if (value[44] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[44]]) != 0xFF + && value[45] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[45]]) != 0xFF) { resultPtr[11] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2957,10 +3229,10 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[48] == 'x' // 12 byte - if (value[49] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[49]]) != 0xFF - && value[50] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[50]]) != 0xFF) + if (value[49] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[49]]) != 0xFF + && value[50] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[50]]) != 0xFF) { resultPtr[12] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2969,10 +3241,10 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[53] == 'x' // 13 byte - if (value[54] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[54]]) != 0xFF - && value[55] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[55]]) != 0xFF) + if (value[54] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[54]]) != 0xFF + && value[55] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[55]]) != 0xFF) { resultPtr[13] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2981,10 +3253,10 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[58] == 'x' // 14 byte - if (value[59] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[59]]) != 0xFF - && value[60] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[60]]) != 0xFF) + if (value[59] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[59]]) != 0xFF + && value[60] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[60]]) != 0xFF) { resultPtr[14] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); @@ -2993,10 +3265,10 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // value[63] == 'x' // 15 byte - if (value[64] < MaximalChar - && (hexByteHi = TableFromHexToBytes[value[64]]) != 0xFF - && value[65] < MaximalChar - && (hexByteLow = TableFromHexToBytes[value[65]]) != 0xFF) + if (value[64] < MaximalCharUtf16 + && (hexByteHi = TableFromHexToBytesUtf16[value[64]]) != 0xFF + && value[65] < MaximalCharUtf16 + && (hexByteLow = TableFromHexToBytesUtf16[value[65]]) != 0xFF) { resultPtr[15] = (byte) ((byte) (hexByteHi << 4) | hexByteLow); return true; @@ -3023,7 +3295,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // // IComparisonOperators // -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER /// #else /// @@ -3118,7 +3390,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) return false; } -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER /// #else /// @@ -3216,7 +3488,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) return true; } -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER /// #else /// @@ -3314,7 +3586,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) return false; } -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER /// #else /// @@ -3415,7 +3687,7 @@ private static bool TryParsePtrXUtf8(byte* value, byte* resultPtr) // // IParsable // -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER /// #else /// @@ -3431,7 +3703,7 @@ public static Uuid Parse(string s, IFormatProvider? provider) return Parse(s); } -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER /// #else /// @@ -3450,7 +3722,7 @@ public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? prov // // ISpanParsable // -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER /// #else /// @@ -3465,7 +3737,7 @@ public static Uuid Parse(ReadOnlySpan s, IFormatProvider? provider) return Parse(s); } -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER /// #else /// diff --git a/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj b/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj index fa69252..f8ab8c4 100644 --- a/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj +++ b/tools/Dodo.Primitives.Tools.CompareVersions/Dodo.Primitives.Tools.CompareVersions.csproj @@ -2,15 +2,15 @@ Exe - net7.0 - 11.0 + net8.0 + 12.0 enable disable true - +