PoshCode Archive  Artifact Content

Artifact 505d8661342657a788f5f71ba39d336e07511f8b7ecd1db776e04b2f77a3e8b3:

  • File quoted-printable.ps1 — part of check-in [0f9b419d91] at 2018-06-10 14:10:20 on branch trunk — quoted printable decoder (assumes you want to output strings as opposed to a byte buffer). (user: Public Domain size: 1029)

# encoding: ascii
# api: powershell
# title: quoted printable
# description: quoted printable decoder (assumes you want to output strings as opposed to a byte buffer).
# version: 0.1
# type: function
# author: Public Domain
# license: CC0
# function: ConvertFrom-QuotedPrintable
# x-poshcode-id: 6204
# x-archived: 2016-03-18T22:00:36
# x-published: 2016-02-07T19:59:00
#
#
function ConvertFrom-QuotedPrintable {
	[OutputType([string])]
	[CmdletBinding()]
	param(
		[Parameter(ValueFromPipeline)]
		[string]$InputObject
,
		[Parameter(Mandatory)]
		[System.Text.Encoding]$Encoding = [System.Text.Encoding]::UTF8
	)
	begin {
		$buf = ''
	}
	process {
		$buf += [regex]::Replace(
			[regex]::Replace($InputObject, "=[ `t]*(?:`r`n|`n|\z)", ''),
			'=[0-9a-fA-F]{2}',
			[System.Text.RegularExpressions.MatchEvaluator]{[string][char][int]::Parse($args[0].Value.Substring(1), [System.Globalization.NumberStyles]::AllowHexSpecifier)}
		)
	}
	end {
		$Encoding.GetString([byte[]][char[]]$buf)
	}
}