forked from brianary/scripts
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Get-UnicodeData.ps1
72 lines (63 loc) · 1.85 KB
/
Get-UnicodeData.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
65
66
67
68
69
70
71
72
<#
.SYNOPSIS
Returns the current (cached) Unicode character data.
.OUTPUTS
System.Management.Automation.PSCustomObject for each character entry with these properties:
* BidirectionalCategory
* Catgory
* CombiningClass
* Comment
* DecimalDigitValue
* DecompositionMapping
* DigitValue
* Lower
* Mirrored
* Name
* NumericValue
* OldName
* Title
* Upper
* Value
.FUNCTIONALITY
Unicode
.LINK
https://www.unicode.org/L2/L1999/UnicodeData.html
.EXAMPLE
Get-UnicodeData.ps1 |Export-Csv data/UnicodeData.csv
Saves the current Unicode data as a CSV file.
#>
#Requires -Version 7
[CmdletBinding()][OutputType([pscustomobject])] Param(
# The location of the latest Unicode data.
[uri] $Url = 'https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt',
[string] $DataFile = (Join-Path $env:TEMP ($Url.Segments[-1]))
)
function Save-Data
{
if(!(Test-Path $DataFile -Type Leaf))
{
$http = Invoke-WebRequest $Url -OutFile $DataFile -PassThru
Write-Information "Downloaded $Url to $(Join-Path $PWD $DataFile)"
[datetime] $lastmod = "$($http.Headers['Last-Modified'])"
(Get-Item $DataFile).LastWriteTime = $lastmod
}
else
{
$http = Invoke-WebRequest $Url -Method Head
[datetime] $lastmod = "$($http.Headers['Last-Modified'])"
if((Get-Item $DataFile).LastWriteTime -lt $lastmod)
{
Invoke-WebRequest $Url -OutFile $DataFile
Write-Information "Updated $Url to $(Join-Path $PWD $DataFile)"
(Get-Item $DataFile).LastWriteTime = $lastmod
}
}
}
function Read-Data
{
Import-Csv $DataFile -Delimiter ';' -Header Value,Name,Catgory,CombiningClass,BidirectionalCategory,
DecompositionMapping,DecimalDigitValue,DigitValue,NumericValue,Mirrored,OldName,Comment,
Upper,Lower,Title
}
Save-Data
Read-Data