Skip to content

Instantly share code, notes, and snippets.

@ninmonkey
Created January 19, 2024 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninmonkey/d0a0cc9803b4b1f315e31ae4457d900c to your computer and use it in GitHub Desktop.
Save ninmonkey/d0a0cc9803b4b1f315e31ae4457d900c to your computer and use it in GitHub Desktop.
Text.Rune - Calculated Columns using EzOut
Write-FormatView -TypeName ([Text.Rune]) -Property @(
'Render', 'Hex', 'Dec', 'Utf16', 'Utf8', 'Numeric' , 'Cat' , 'Ctrl' , 'Enc8', 'Enc16', 'Enc16Be', 'Upper', 'Lower'
) -AliasProperty @{
'Cat' = 'GetUnicodeCategory'
'Dec' = 'Value'
'Utf16' = 'Utf16SequenceLength'
'Utf8' = 'Utf8SequenceLength'
'Text' = 'Render'
'Lower' = 'ToLowerInvariant'
'Upper' = 'ToUpperInvariant'
'Symbol' = 'IsSymbol'
} -AlignProperty @{
'Enc8' = 'right'
'Enc16' = 'right'
'Enc16Be' = 'right'
'Rune' = 'right'
'Hex' = 'right'
} -VirtualProperty @{
Enc8 = {
[Text.Encoding]::GetEncoding('utf-8').GetBytes( $_ )
| Join-string -f '{0:x2}' -sep ' ' }
Enc16 = {
[Text.Encoding]::GetEncoding('utf-16le').GetBytes( $_ )
| Join-string -f '{0:x2}' -sep ' ' }
Enc16Be = {
[Text.Encoding]::GetEncoding('utf-16be').GetBytes( $_ )
| Join-string -f '{0:x2}' -sep ' ' }
Cat = { # Category
[Text.Rune]::GetUnicodeCategory( $_.Value )
}
Hex = {
Join-String -f '{0:x}' -sep ' ' -In $_.Value
}
Render = { $_ | Format-ControlChar }
Numeric = { [Text.Rune]::GetNumericValue( $_ ) } # was: 'GetNumericValue'
GetUnicodeCategory = { [Text.Rune]::GetUnicodeCategory( $_ ) }
Ctrl = { [Text.Rune]::IsControl( $_ ) } <# was: 'IsControl' #>
IsDigit = { [Text.Rune]::IsDigit( $_ ) }
IsLetter = { [Text.Rune]::IsLetter( $_ ) }
IsLetterOrDigit = { [Text.Rune]::IsLetterOrDigit( $_ ) }
IsLower = { [Text.Rune]::IsLower( $_ ) }
IsNumber = { [Text.Rune]::IsNumber( $_ ) }
IsPunctuation = { [Text.Rune]::IsPunctuation( $_ ) }
IsSeparator = { [Text.Rune]::IsSeparator( $_ ) }
IsSymbol = { [Text.Rune]::IsSymbol( $_ ) }
IsUpper = { [Text.Rune]::IsUpper( $_ ) }
IsWhiteSpace = { [Text.Rune]::IsWhiteSpace( $_ ) }
'Lower' = # ToLowerInvariant =
{ [Text.Rune]::ToLowerInvariant( $_ ) }
'Upper' = # ToUpperInvariant
{ [Text.Rune]::ToUpperInvariant( $_ ) }
} -AutoSize
| Out-FormatData | Push-FormatData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment