[OPEN-ILS-DEV] messagecatalog -- linefeeds and other escaped characters

Scott McKellar mck9 at swbell.net
Sat Aug 18 09:37:56 EDT 2007


--- Mike Rylander <mrylander at gmail.com> wrote:

> On 8/17/07, Dan Scott <denials at gmail.com> wrote:

<snip>

> > This is mostly a heads-up. I am mostly hoping that there's an
> > existing XUL method I can call to handle the escaped characters. :)
> >
> 
> Agreed on the need, though I'll be surprised if that method isn't
> spelled 'replace'. ;)

I assume that you are proposing to use some utility function to
replaces all occurrences of "\n" with linefeeds, all occurrences of
"\t" with horizontal tabs, and so forth.

While this approach will get the right answer most of the time, and
maybe all of the time in practice, it will not always work in general.

Consider a string containing the characters "X\\n".  The pair of
backslashes should be rendered as a single backslash, and the 'n'
as a literal 'n', with no linefeed.  I don't think you can get that
result with simple string replacements.

For further perversities, consider "X\\\n", "X\\\\n", and so forth.

To do the job correctly, there's no way to avoid traversing the string
character by character, responding to backslashes as you find them
(unless of course such a function is already available).

Such a function is not hard to write, just a little tedious.  The 
main issue is input like "X\z", where "\z" has no special meaning.  
Do you render it as "X\z" or "Xz"?  Or issue an error message?

Scott McKellar
http://home.swbell.net/mck9/ct/



More information about the Open-ils-dev mailing list