トップ «前の日記(2022年08月14日) 最新 次の日記(2023年07月15日)» 編集

Masa's blog

検索キーワード:

2023年06月18日 mplayerでdvd-videoをメニュー再生およびマウス操作する方法 [長年日記]

mplayer -mouse-movements  dvdnav:// -dvd-device /dev/dvd1

_ powershellでPUA、サロゲートペア、IVSを含んだ文字列を操作するサンプル

StringSample.ps1

function getLength($string){
	$count = 0
	for ($i = 0; $i -lt $s.length; $i++){
		if ([int][char]$s[$i] -ge 0xd800 -and [int][char]$s[$i] -le 0xdbff){
			if ([int][char]$s[$i] -eq 0xdb40){
#				IVS H
			}else{
#				SURR H
				$count++
			}
		}elseif ([int][char]$s[$i] -ge 0xdc00 -and [int][char]$s[$i] -le 0xdfff){
			if ([int][char]$s[$i] -ge 0xdd00 -and [int][char]$s[$i] -le 0xddef){
#				IVS L
			}else{
#				SURR L
			}
		}else{
#			BMP
			$count++
		}
	}
	return $count
}

function getCharByIndex($string, $index){
	$out = ""
	$windex = -1
	for ($i = 0; $i -lt $s.length; $i++){
		if ([int][char]$s[$i] -ge 0xd800 -and [int][char]$s[$i] -le 0xdbff){
			if ([int][char]$s[$i] -eq 0xdb40){
#				IVS H
			}else{
#				SURR H
				$windex++
			}
		}elseif ([int][char]$s[$i] -ge 0xdc00 -and [int][char]$s[$i] -le 0xdfff){
			if ([int][char]$s[$i] -ge 0xdd00 -and [int][char]$s[$i] -le 0xddef){
#				IVS L
			}else{
#				SURR L
			}
		}else{
#			BMP
			$windex++
		}
		if ($windex -eq $index){
			$out = $s[$i]
			if ([int][char]$s[$i] -ge 0xd800 -and [int][char]$s[$i] -le 0xdbff){
				if ([int][char]$s[$i] -eq 0xdb40){
#					IVS H
				}else{
#					SURR H
					$i++
					$out += $s[$i]	# add SURR L
				}
			}
			if ([int][char]$s[$i + 1] -eq 0xdb40){
#				IVS H
				$i++
				$out += $s[$i]	# add IVS H
				$i++
				$out += $s[$i]	# add IVS L
			}
		}
	}
	return $out
}

function getSubString($string, $index, $length){
	$out = ""
	for ($i = $index; $i -lt ($index + $length); $i++){
		$out += (getCharByIndex $string $i)
	}
	return $out
}

$s = "a漢𠮷辻󠄀b"
echo ("文字列:" + $s)
echo ("文字数:" + (getLength $s))
echo ("0文字目:" + (getCharByIndex $s 0))
echo ("1文字目(BMP):" + (getCharByIndex $s 1))
echo ("2文字目(PUA):" + (getCharByIndex $s 2))
echo ("3文字目(surrogate):" + (getCharByIndex $s 3))
echo ("4文字目(BMP+IVS):" + (getCharByIndex $s 4))
echo ("2文字目から3文字分:" + (getSubString $s 2 3))

実行結果

PS C:\Users\USER\Desktop\PowerShell> .\SampleString.ps1
文字列:a漢𠮷辻󠄀b
文字数:6
0文字目:a
1文字目(BMP):漢
2文字目(PUA):
3文字目(surrogate):𠮷
4文字目(BMP+IVS):辻󠄀
2文字目から3文字分:𠮷辻󠄀
PS C:\Users\USER\Desktop\PowerShell>