forked from stcu/SharedScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-UnicodeName.ps1
39 lines (33 loc) · 1.01 KB
/
Get-UnicodeName.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<#
.SYNOPSIS
Returns the name of a Unicode code point.
.INPUTS
System.Int32 of a Unicode code point value to name, or
System.String of Unicode characters to name.
.OUTPUT
System.String of the Unicode code point name.
.LINK
https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt
.EXAMPLE
Get-UnicodeName.ps1 32
SPACE
#>
#Requires -Version 3
[CmdletBinding()][OutputType([string])] Param(
# The numeric value of the Unicode character.
[Parameter(ParameterSetName='CodePoint',Position=0,Mandatory=$true,ValueFromPipeline=$true)][int] $CodePoint,
# The Unicode character.
[Parameter(ParameterSetName='Character',Position=0,Mandatory=$true,ValueFromPipeline=$true)][string] $Character
)
Begin {$name = ConvertFrom-StringData (Get-Content ([io.path]::ChangeExtension($PSCommandPath,'txt')) -Raw)}
Process
{
if($PSCmdlet.ParameterSetName -eq 'Character')
{
return $Character.GetEnumerator() |foreach {[int]$_} |Get-UnicodeName.ps1
}
else
{
return $name['{0:X4}' -f $CodePoint]
}
}