After fighting with it for literal days I ended up setting it to just take an AttributedString and return a “UnionValue" thing that is like documented in one web page and a WWDC link, both with incorrect explanation of how it should be used.
It still doesn't work like I think it should but it works mostly OK and at this point I give up working on a feature 1% of users will ever touch.
@paul The Shortcuts/App Intents API is so fucking inscrutable. And the documentation is too disjoint to fix that problem.
And/or I’m a dunce.
@paul « a version with maybe 1/4 of the features (i.e. needless complexity) »
That'd be Dart (what is used for Flutter).
@paul Here's the example I used:
NSString *yourString = [whitespaceString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
NSString *yourString = [whitespaceString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
I originally did this talk for a Perl conference. As you can imagine, the equivalent code is a LOT shorter in Perl. 😀
@paul Are `whitespaceCharacterSet` and `whitespaceAndNewlineCharacterSet` two different constants in the API? I'm sure I just copied that from the API docs but I don't remember. In any event, in Perl you'd either use `chomp` or a very simple regex if you wanted finer control. That second command would be something like
$yourString =~ s/\s+$//;
in Perl.
@pdcawley @paul I thought the second example was supposed to trim the newline, so that's why I went with that example. My intention wasn't to give every possibility but just demonstrate what the equivalent Perl code might look like. It's easy enough to use a character class in your regex to remove anything you want.
That said, I'm having a hard time thinking of a case where I wanted to trim trailing whitespace and *not* also trim the newlines. Maybe it comes up more often in GUI programming than CLI tools?