Bug in the Improved Sentence Case Macro? [RESOLVED]


#1

I'm using the Improved Sentence Case Macro from the Best Macro List, but I'm having a small problem: contractions. For example:

let's see, I don't know if I'll try this again.

gets converted to:

Let'S see, I don'T know if I'Ll try this again.

I'm not smart enough with Perl Compatible Regular Expressions to be able to figure out how to fix this. Any help?


#2

Well, this is what I get:

let's see, I don't know if I'll try this again.

Let's See, I Don't Know if I'll Try This Again

So maybe try it again?


#3

Your example looks like the Title Case Macro, not the Sentence Case Macro. Let's see if I can upload the Sentence Case Macro that I'm having issues with. I believe it's identical to yours with the exception of the triggers (I removed the Hot Key trigger and use it as part of a palette.)
Sentence Case.kmmacros (3.7 KB)


#4

Ah, got it. Sentence not Title. Yes, that's a problem. Here's the solution (add the fourth line: s/'([stmdlrv])/'\l$1/gi;):

#! /usr/bin/env perl

use strict;
use warnings;

my @acronyms = qw( FBI CIA NASA );
my $acronym_list = join '|', @acronyms;

$_ = $ENV{KMVAR_LinkText};

s/(?<=\b[A-Z])[.]//gi;
$_ = lc $_ if not /[[:lower:]]/;
s/(^\w|[!\?\.'"’”]\s+\w|['"“‘]\w)/\U$1\E/g;
s/'([stmdlrv])/'\l$1/gi;
s/([A-Z]\.\s)([A-Z])/$1\L$2\E/g;
s/(,['"’”] )([A-Z])/$1\L$2\E/g;
s/\b($acronym_list)\b/\U$1/gi;

print $_;

I'll update the macro on the site...


#5

Let me try it out:

let's see, I don't know if I'll try this again.

gets converted to:

Let's see, I don't know if I'll try this again.

Excellent! Thank you very much!


#6

Sorry for my initial confusion. Just speculating but I have a hunch the code couldn't distinguish between a closing single quote and apostrophe. This fix takes care of that.