forked from brianary/scripts
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Get-UnicodeName.ps1
64 lines (57 loc) · 1.63 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<#
.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.
.OUTPUTS
System.String of the Unicode code point name.
.FUNCTIONALITY
Unicode
.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,
# Update the character name database.
[Parameter(ParameterSetName='Update')][switch] $Update
)
Begin
{
$basename = Join-Path -Path $PSScriptRoot -ChildPath data -AdditionalChildPath UnicodeName
$cc = ConvertFrom-StringData (Get-Content "$basename.cc.txt" -Raw)
$name = ConvertFrom-StringData (Get-Content "$basename.txt" -Raw)
}
Process
{
switch($PSCmdlet.ParameterSetName)
{
Update
{
Get-UnicodeData.ps1 |
Select-Object Value,@{n='Name';e={
$hex = '{0:X4}' -f $_.Value
$cc.ContainsKey($hex) ? $cc[$hex] : $_.Name
}} |
Export-Csv "$basename.txt" -Delimiter '=' -UseQuotes AsNeeded
Write-Information 'Updated.'
return
}
Character
{
return $Character.GetEnumerator() |ForEach-Object {[int]$_} |Get-UnicodeName.ps1
}
default
{
$hex = '{0:X4}' -f $CodePoint
return $cc.ContainsKey($hex) ? $cc[$hex] : $name[$hex]
}
}
}