nisus.com
https://www.nisus.com/forum/

Title Case
https://www.nisus.com/forum/viewtopic.php?f=17&t=4522
Page 1 of 1

Author:  Bob Stern [ 2011-09-30 00:59:01 ]
Post subject:  Title Case

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!

Author:  martin [ 2011-09-30 13:00:50 ]
Post subject:  Re: Title Case

EDIT: this macro was removed because it had shortcomings. See below for a fixed version of the macro.

Author:  Bob Stern [ 2011-09-30 15:00:38 ]
Post subject:  Error msg

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 7638 times ]


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

Author:  martin [ 2011-09-30 15:15:23 ]
Post subject:  Re: Title Case

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.

Author:  Bob Stern [ 2011-10-01 05:03:12 ]
Post subject:  Unicode

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 7627 times ]

Author:  martin [ 2011-10-03 13:07:35 ]
Post subject:  Re: Title Case

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;"

Author:  Bob Stern [ 2011-10-03 15:10:30 ]
Post subject:  Edit > Convert > From Unicode Code Points

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.

Author:  phspaelti [ 2011-10-03 16:47:15 ]
Post subject:  Re: Title Case

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.

Author:  Bob Stern [ 2011-10-03 23:14:50 ]
Post subject:  Thanks, Philip!

The U+ prefix worked.

Nisus should add that to the user guide.

Author:  martin [ 2011-10-04 11:42:07 ]
Post subject:  Re: Title Case

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.

Author:  skyblue [ 2015-12-06 13:01:41 ]
Post subject:  Re: Title Case

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

Author:  martin [ 2015-12-09 13:32:45 ]
Post subject:  Re: Title Case

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 54 times

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/