Get text direction with MBS

I’ve got a declare from Thomas T. to get the text direction:

[code]Declare Function CFStringTokenizerCopyBestStringLanguage Lib “CoreFoundation” (aString As CFStringRef, range As CFRange) As CFStringRef
Declare Function CFLocaleGetLanguageCharacterDirection Lib “CoreFoundation” (isoLangCode As CFStringRef) As Integer

Const kCFLocaleLanguageDirectionUnknown = 0
Const kCFLocaleLanguageDirectionLeftToRight = 1
Const kCFLocaleLanguageDirectionRightToLeft = 2
Const kCFLocaleLanguageDirectionTopToBottom = 3
Const kCFLocaleLanguageDirectionBottomToTop = 4

Dim range As CFRange
range.location = 0
range.length = txt.Len

Dim isoLangCode As String = CFStringTokenizerCopyBestStringLanguage(txt, range)

Select Case CFLocaleGetLanguageCharacterDirection(isoLangCode)
Case kCFLocaleLanguageDirectionRightToLeft
return true
Case kCFLocaleLanguageDirectionTopToBottom
break ’ huh?!
Case kCFLocaleLanguageDirectionBottomToTop
break ’ huh?!

Unfortunately, this crashes hard with Xojo 2018r1, El Capitan, 64bit

[quote]1 0x00007fff93e5d5d1 CFStringTokenizerCopyBestStringLanguage + 49
2 Mail Archiver X.debug 0x000000010b403a2f FinderTextWrapper.!IsRightToLeftText%b%s + 751 (/FinderTextWrapper:125)[/quote]

So I’m looking to MBS for a replacement. How do I apply the example at ? I only have some string and not a TextArea. The string can only have one text direction.

NSLocaleMBS class has a method called characterDirectionForLanguage(isoLangCode as string) as Integer for you.

Thanks, I’ll have a look.