Reply to topic  [ 12 posts ] 
Title Case 
Author Message

Joined: 2006-03-12 12:32:47
Posts: 138
Searching the web for an algorithm to convert text to Title Case, I discovered a Perl script written by John Gruber and Aristotle Pagaltzis:
https://github.com/ap/titlecase/blob/master/titlecase

I would like to embed this Perl script into a NWP macro so I can apply it to the current selection in a document. However, I don't know enough about Perl to figure out where the input variable is in this script. (I can see that the output variable is named $_.)

Martin, would it be too much trouble for you to provide the NWP macro steps that should surround this Perl script?

Thanks a million!


2011-09-30 00:59:01
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
EDIT: this macro was removed because it had shortcomings. See below for a fixed version of the macro.


2011-09-30 13:00:50
Profile WWW

Joined: 2006-03-12 12:32:47
Posts: 138
Thanks, Martin!

However, when I run the macro, NWP produces the following error msg:
Attachment:
Screen shot 2011-09-30 at 3.52.54 PM.png
Screen shot 2011-09-30 at 3.52.54 PM.png [ 35.26 KiB | Viewed 7684 times ]


When I click Open Macro in the error msg, the following line of the macro is highlighted:
\b (_*) (?:


2011-09-30 15:00:38
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Ah yes. That character \xC2 is a non-breaking space, introduced by the forum when you copy-paste code from the web. Perl doesn't like it. You can fix it by replacing all non-breaking spaces in the macro with regular spaces. Or download the macro I'll attach here.
...
EDIT: this macro was removed because it had shortcomings. See below for a fixed version of the macro.


2011-09-30 15:15:23
Profile WWW

Joined: 2006-03-12 12:32:47
Posts: 138
Perfect! Thanks!

Another question: How could I have figured out that \xC2 means non-breaking space?

I typed c2 or C2 or \xC2 in a NWP document, selected it, and attempted to use the menu command Edit > Convert > From Unicode Code Points, but the command was grayed out. I cannot figure out how to make this command active.

I also tried using the OS X Character Viewer to view the Unicode Code Table. I must be interpreting this incorrectly, because Unicode 00C2 appears to be "capital A with circumflex".
Attachment:
Screen shot 2011-10-01 at 5.56.57 AM.jpg
Screen shot 2011-10-01 at 5.56.57 AM.jpg [ 83.63 KiB | Viewed 7673 times ]


2011-10-01 05:03:12
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Actually, you're correct Bob, U+00C2 is a capital A with circumflex. I didn't actually look up the character/code, I just knew Perl doesn't like non-breaking spaces and assumed the \xC2 mentioned in Perl's error message was the code for a non-breaking space.

Perl's error message should probably be clarified. When it says "unrecognized character", it really means unrecognized byte in the UTF-8 steam/data. A non-breaking space must be encoded in UTF-8 using a two byte sequence: 0xC2 0xA0. Perl's error only reports that leading byte, even though it's only the first half of the proper Unicode character. It may be that Perl doesn't really deal with full Unicode characters outside of string literals/data, even when declaring "use utf8;"


2011-10-03 13:07:35
Profile WWW

Joined: 2006-03-12 12:32:47
Posts: 138
Thanks for the clarification, Martin.

FYI, I just used the Feedback reporter to report as a bug that fact that "Edit > Convert > From Unicode Code Points" is always greyed out.


2011-10-03 15:10:30
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Bob. a string has to have the form U+xxxx for the "Edit > Convert > From Unicode Code Points" to work.

Of course I agree that they could make it more user-friendly.

_________________
philip


2011-10-03 16:47:15
Profile

Joined: 2006-03-12 12:32:47
Posts: 138
The U+ prefix worked.

Nisus should add that to the user guide.


2011-10-03 23:14:50
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Thanks for the feedback report Bob, glad you have it working. I agree that it should be more lenient in what forms it accepts; being as liberal as possible would be best.


2011-10-04 11:42:07
Profile WWW

Joined: 2015-03-18 07:28:09
Posts: 5
Hi,

I was excited to find this macro. I found a bug, which I thought I would report. (I'm not much of a scripter, so I can't fix the issue myself.)

The macro failed with a carriage return between lines.
Example- input text:
Code:
journal of nervous and mental disease
psychotherapy and psychosomatics
journal of humanistic psychology
journal of transpersonal psychology


bipolar disorders

journal of affective disorders


Yields this result:
Code:
Journal of Nervous and Mental Disease
Psychotherapy and Psychosomatics
Journal of Humanistic Psychology
Journal of Transpersonal Psychology


i.e. just lopped off everything after the carriage return. Does the same thing when I change it to only 1 carriage return for the first blank space instead of 2.

When I turn on "View > Show Invisibles," it displays the blank lines with a paragraph symbol.

For now I can work around it just fine, but just thought I would mention it in case further development happens with this macro.

thanks
sb


2015-12-06 13:01:41
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
skyblue wrote:
The macro failed with a carriage return between lines.
...
i.e. just lopped off everything after the carriage return.

Thanks for letting us know skyblue. Here's an amended macro that doesn't suffer from this problem.


Attachments:
TitleCase.nwm [21.16 KiB]
Downloaded 55 times
2015-12-09 13:32:45
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software