Unicode property block and script

This works fine:

let uniScalars = someString.unicodeScalars
for uniScalar in uniScalars
{
	let prop = uniScalar.properties
	var out = ""
	out += " \(prop.generalCategory);"
	out += " \(prop.name ?? "no name");"
}

But I also need the block and script property.

Is there a way do get this in Swift, or do I have to scan the Unicode Blocks.txt and Script.txt?

Gerriet.

1 Like

It's not built-in yet.

Script matching is implemented for regexes, so if you're looking for specific script(s), you could use a regex. Block matching is not yet implemented.

// Script property works.
func isArabic(_ s: String) -> Bool {
    s.wholeMatch(of: /\p{Arabic}/) != nil
}

// Error: Unicode block property is not currently supported
func isBasicLatin(_ s: String) -> Bool {
    s.wholeMatch(of: /\p{inBasicLatin}/) != nil
}

The plan is to eventually also make this data available on UnicodeScalar, just as other scalar properties are exposed.