Editor supporting "Escaped Characters"

  • Thread starter Sebastian L (Berlin)
  • Start date
S

Sebastian L (Berlin)

Hello,

I am searching for an editor, that supports "escaped characters" (/n /
t // /") as in strings.
I want to write/edit a long text/string I use in my source code, but
am annoyed every time, I want to make a change in it.

What I need is an editor, where I can edit a "plain text" with
linebreaks and quotes; simply converting into "escaped"-format
afterwards and back.

Does anyone know a usable editor.
Searching the net several times, I couldnt find a usable one....

Greets
Sebastian
 
L

Lew

Sebastian said:
I am searching for an editor, that supports "escaped characters"
(/n /t // /") as in strings.

Those are not escaped characters. Maybe that is the source of your trouble.
I want to write/edit a long text/string I use in my source code, but
am annoyed every time, I want to make a change in it.

Externalize that string! Source code is no place for it.

When I put long strings in source, I break them up into multiple lines for
readability, e.g.,

public final static String LONGSTR =
"This is a long string. I like to keep listings narrow for readability.\n"
+"If you don't do that, you will have a hard time maintaining your code.\n"
+"I think maybe you didn't define your problem correctly.\n"
+"This way you don't have to futz around with silly mode switches.\n"
+"BTW, why do you insist on putting quotes around the word \"escaped\" "
+"every time you use it, much less \"plain text\"? "
+"They serve no useful purpose."
What I need is an editor, where I can edit a "plain text" with
linebreaks and quotes; simply converting into "escaped"-format
afterwards and back.

That's not really what you need. You need to format your long strings for
readability at a minimum, or ideally to externalize them.

NetBeans and Eclipse both highlight escaped characters in an optionally
different color, font and style from other text. Emacs does, too, IIRC.
Others probably do, too.
Does anyone know a usable editor. [sic]

Yes, I do. All the ones I just mentioned.
Searching the net several times, I couldnt find a usable one....

Use one of the ones I mentioned, then. They're all eminently usable.
 
A

Andreas Leitgeb

Lew said:
bugbear said:
Why not just have a text file in the jar [sic], using getResourceAsStream[?]
Why do you recommend that approach over ResourceBundles (or Property
instances)? Bundles (properties) wrap the messy details of manual file
control and give keyed access to the contained resources, much more powerful
and convenient than a roll-your-own approach.

Wouldn't such a properties-file again require all those escapings
in the text that the OP wanted to deal with in the first place?

But then, again, there might exist comfortable properties-file editors...
 
L

Lew

Sebastian said:
I want to write/edit a long text/string I use in my source code, but
am annoyed every time, I want to make a change in it.
Why not just have a text file in the jar [sic], using getResourceAsStream[?]
Why do you recommend that approach over ResourceBundles (or Property
instances)?  Bundles (properties) wrap the messy details of manual file
control and give keyed access to the contained resources, much more powerful
and convenient than a roll-your-own approach.

Andreas said:
Wouldn't such a properties-file again require all those escapings
in the text that the OP wanted to deal with in the first place?

Has to deal with.
But then, again, there might exist comfortable properties-file editors...

It isn't about avoiding the escapes, it's about managing the strings.
Having logic-relevant strings in your source is an antipattern. If
you have to change them in source, it's a rebuild; in properties files
or bundles, it's a redeploy only, or even just a hot-fix.

You're right that avoiding escapes is not served by this, but then
that was not claimed anyway.
 
B

BGB

Those are not escaped characters. Maybe that is the source of your trouble.
<http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.6>

yeah, it was suspect...

unless the OP wants the editor to use a different set of escapes as to
allow multi-escaping or something, but '/' would be a poor choice for
this (would clash with other uses of the character).

I want to write/edit a long text/string I use in my source code, but
am annoyed every time, I want to make a change in it.

Externalize that string! Source code is no place for it.

When I put long strings in source, I break them up into multiple lines
for readability, e.g.,

public final static String LONGSTR =
"This is a long string. I like to keep listings narrow for readability.\n"
+"If you don't do that, you will have a hard time maintaining your code.\n"
+"I think maybe you didn't define your problem correctly.\n"
+"This way you don't have to futz around with silly mode switches.\n"
+"BTW, why do you insist on putting quotes around the word \"escaped\" "
+"every time you use it, much less \"plain text\"? "
+"They serve no useful purpose."
What I need is an editor, where I can edit a "plain text" with
linebreaks and quotes; simply converting into "escaped"-format
afterwards and back.

That's not really what you need. You need to format your long strings
for readability at a minimum, or ideally to externalize them.

NetBeans and Eclipse both highlight escaped characters in an optionally
different color, font and style from other text. Emacs does, too, IIRC.
Others probably do, too.
Does anyone know a usable editor. [sic]

Yes, I do. All the ones I just mentioned.
Searching the net several times, I couldnt find a usable one....

Use one of the ones I mentioned, then. They're all eminently usable.

one thing I have done before (mostly for C, less recommended for Java as
one can put text files in JAR's), was to write out a lot of text into a
text file, and then invoke a tool at build time to convert the text file
into a big string constant.

this is because otherwise, non-trivial cases involving files can be a
logistical mess in C-land, since there is no good way otherwise to
bundle files with programs (and the Windows "Resources" system is not
very good, and lacks a direct Linux analogue). so, it often ends up
nicer just to convert data into code and link it in directly.

but, yes, this is less advised for Java, since better probably is to
stuff the file into the JAR.


in my case, this was used mostly in a codegen for some occasional
slightly largish chunks of ASM (most other ASM was in small fragments
and emitted by printf-like statements).

in my case, my assembler allowed using '; ' for lumping multiple opcodes
per-line mostly as using this in a string constant was a little less
ugly than using a newline escape.

"push ebp; mov ebp, esp; sub esp, 128"
vs:
"push ebp\nmov ebp, esp\nsub esp, 128"

it can also help readability some with plain ASM as well, mostly by
increasing the visual code density (IMO, sometimes lumping multiple
statements on a line is a good thing WRT readability).

but, this little feature breaks compatibility with NASM and similar,
which always assume ';' to mean a comment (in my case, it is a comment
or a separator depending on context and surrounding white-space).
 
R

Roedy Green

What I need is an editor, where I can edit a "plain text" with
linebreaks and quotes; simply converting into "escaped"-format
afterwards and back.

IntelliJ has a feature that if you paste text inside "...", it
converts newlines to \n.

Quoter will convert text to Java strings for you by quoting as
necessary. It will also do three different regex conventions, both for
data in Java string literals. You run it along side your editor, and
it processes the clipboard. It does all kinds of text transforms you
might find useful. You can also run it an as applet in your browser
without installing it. see http://mindprod.com/applet/quoter.html

SlickEdit lets you write your own macros.
 
R

Roedy Green

Hello,

I am searching for an editor, that supports "escaped characters" (/n /
t // /") as in strings.
I want to write/edit a long text/string I use in my source code, but
am annoyed every time, I want to make a change in it.

What I need is an editor, where I can edit a "plain text" with
linebreaks and quotes; simply converting into "escaped"-format
afterwards and back.

Does anyone know a usable editor.

I wrote an outline for a student project to write an editor where you
maintain the strings in several different languages and export them as
Java ResourceBundles.

See http://mindprod.com/project/internationaliser.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top