[jira] Created: (LANG-498) Add StringEscapeUtils.escapeText() methods

View: New views
9 Messages — Rating Filter:   Alert me  

[jira] Created: (LANG-498) Add StringEscapeUtils.escapeText() methods

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Add StringEscapeUtils.escapeText() methods
------------------------------------------

                 Key: LANG-498
                 URL: https://issues.apache.org/jira/browse/LANG-498
             Project: Commons Lang
          Issue Type: New Feature
    Affects Versions: 3.x, 2.x
            Reporter: Henning Schmiedehausen
         Attachments: LANG-498.patch

I needed to escape text to be print out to a file; mainly so that all non-ASCII characters (< 32 and >=127) are printed out as escapes (if available) or unicode escapes. This is a one-way conversion, there is no way to find out whether a String contained "\\n" or a newline before conversion, so I just set up escapeText() methods, no unescapeText().

Please apply to the next release of commons-lang. :-)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-498) Add StringEscapeUtils.escapeText() methods

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ https://issues.apache.org/jira/browse/LANG-498?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henning Schmiedehausen updated LANG-498:
----------------------------------------

    Attachment: LANG-498.patch

> Add StringEscapeUtils.escapeText() methods
> ------------------------------------------
>
>                 Key: LANG-498
>                 URL: https://issues.apache.org/jira/browse/LANG-498
>             Project: Commons Lang
>          Issue Type: New Feature
>    Affects Versions: 3.x, 2.x
>            Reporter: Henning Schmiedehausen
>         Attachments: LANG-498.patch
>
>
> I needed to escape text to be print out to a file; mainly so that all non-ASCII characters (< 32 and >=127) are printed out as escapes (if available) or unicode escapes. This is a one-way conversion, there is no way to find out whether a String contained "\\n" or a newline before conversion, so I just set up escapeText() methods, no unescapeText().
> Please apply to the next release of commons-lang. :-)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-498) Add StringEscapeUtils.escapeText() methods

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ https://issues.apache.org/jira/browse/LANG-498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12703459#action_12703459 ]

Sebb commented on LANG-498:
---------------------------

Seems useful to me, but maybe it would be better to name it as toAsciiPrintable() or similar?
And perhaps it belongs in a different class.

> Add StringEscapeUtils.escapeText() methods
> ------------------------------------------
>
>                 Key: LANG-498
>                 URL: https://issues.apache.org/jira/browse/LANG-498
>             Project: Commons Lang
>          Issue Type: New Feature
>    Affects Versions: 3.x, 2.x
>            Reporter: Henning Schmiedehausen
>         Attachments: LANG-498.patch
>
>
> I needed to escape text to be print out to a file; mainly so that all non-ASCII characters (< 32 and >=127) are printed out as escapes (if available) or unicode escapes. This is a one-way conversion, there is no way to find out whether a String contained "\\n" or a newline before conversion, so I just set up escapeText() methods, no unescapeText().
> Please apply to the next release of commons-lang. :-)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-498) Add StringEscapeUtils.escapeText() methods

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ https://issues.apache.org/jira/browse/LANG-498?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-498:
-------------------------------

    Affects Version/s:     (was: 2.x)
                           (was: 3.x)
        Fix Version/s: 3.0

Agreed on name. escapeToPrintableAscii or some such. Class probably okay.

> Add StringEscapeUtils.escapeText() methods
> ------------------------------------------
>
>                 Key: LANG-498
>                 URL: https://issues.apache.org/jira/browse/LANG-498
>             Project: Commons Lang
>          Issue Type: New Feature
>            Reporter: Henning Schmiedehausen
>             Fix For: 3.0
>
>         Attachments: LANG-498.patch
>
>
> I needed to escape text to be print out to a file; mainly so that all non-ASCII characters (< 32 and >=127) are printed out as escapes (if available) or unicode escapes. This is a one-way conversion, there is no way to find out whether a String contained "\\n" or a newline before conversion, so I just set up escapeText() methods, no unescapeText().
> Please apply to the next release of commons-lang. :-)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-498) Add StringEscapeUtils.escapeText() methods

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ https://issues.apache.org/jira/browse/LANG-498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12705352#action_12705352 ]

Henning Schmiedehausen commented on LANG-498:
---------------------------------------------

I dont't really care about the name; however the code shares significant synergies with the Java/JavaScript escape, so I would keep it in that class. It would also be the first class that I would look for it. ;-)

> Add StringEscapeUtils.escapeText() methods
> ------------------------------------------
>
>                 Key: LANG-498
>                 URL: https://issues.apache.org/jira/browse/LANG-498
>             Project: Commons Lang
>          Issue Type: New Feature
>            Reporter: Henning Schmiedehausen
>             Fix For: 3.0
>
>         Attachments: LANG-498.patch
>
>
> I needed to escape text to be print out to a file; mainly so that all non-ASCII characters (< 32 and >=127) are printed out as escapes (if available) or unicode escapes. This is a one-way conversion, there is no way to find out whether a String contained "\\n" or a newline before conversion, so I just set up escapeText() methods, no unescapeText().
> Please apply to the next release of commons-lang. :-)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-498) Add StringEscapeUtils.escapeText() methods

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ https://issues.apache.org/jira/browse/LANG-498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12710288#action_12710288 ]

Henri Yandell commented on LANG-498:
------------------------------------

Hopefully LANG-505 will remove the need to do this. Instead you would have an easy API to pick and choose the escaping elements you want.

> Add StringEscapeUtils.escapeText() methods
> ------------------------------------------
>
>                 Key: LANG-498
>                 URL: https://issues.apache.org/jira/browse/LANG-498
>             Project: Commons Lang
>          Issue Type: New Feature
>            Reporter: Henning Schmiedehausen
>             Fix For: 3.0
>
>         Attachments: LANG-498.patch
>
>
> I needed to escape text to be print out to a file; mainly so that all non-ASCII characters (< 32 and >=127) are printed out as escapes (if available) or unicode escapes. This is a one-way conversion, there is no way to find out whether a String contained "\\n" or a newline before conversion, so I just set up escapeText() methods, no unescapeText().
> Please apply to the next release of commons-lang. :-)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-498) Add StringEscapeUtils.escapeText() methods

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ https://issues.apache.org/jira/browse/LANG-498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12723438#action_12723438 ]

Henri Yandell commented on LANG-498:
------------------------------------

This would now be implemented as:

        new AggregateTranslator(
            new EscapeLowAsciiAsUnicode(),
            new EscapeNonAsciiAsUnicode()
        );

Not escaping \ would still leave it one-way. Possibly that would become:

  static import org.apache.commons.lang.text.translate.EscapeUtils.*;

  TRANSLATE.with(ASCII_LOW, ASCII_GREATER_THAN)

Though that all has the assumption that \b is the escape for backspace and not the unicode value for the number etc.

Alternatively, it would not be a huge change for this to be doable:

  UnicodeEscaper.below(32).with(UnicodeEscaper.above(0x7f));

if \b should go to unicode etc.

> Add StringEscapeUtils.escapeText() methods
> ------------------------------------------
>
>                 Key: LANG-498
>                 URL: https://issues.apache.org/jira/browse/LANG-498
>             Project: Commons Lang
>          Issue Type: New Feature
>            Reporter: Henning Schmiedehausen
>             Fix For: 3.0
>
>         Attachments: LANG-498.patch
>
>
> I needed to escape text to be print out to a file; mainly so that all non-ASCII characters (< 32 and >=127) are printed out as escapes (if available) or unicode escapes. This is a one-way conversion, there is no way to find out whether a String contained "\\n" or a newline before conversion, so I just set up escapeText() methods, no unescapeText().
> Please apply to the next release of commons-lang. :-)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-498) Add StringEscapeUtils.escapeText() methods

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ https://issues.apache.org/jira/browse/LANG-498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12723458#action_12723458 ]

Henri Yandell commented on LANG-498:
------------------------------------

Or even:

{code:java}
        new AggregateTranslator(
            EscapeUtils.ESCAPE_JAVA,
            UnicodeEscaper.outsideOf(32, 0x7f)
        );
{code}

Though it's being a little buggy at me right now so not committed.

> Add StringEscapeUtils.escapeText() methods
> ------------------------------------------
>
>                 Key: LANG-498
>                 URL: https://issues.apache.org/jira/browse/LANG-498
>             Project: Commons Lang
>          Issue Type: New Feature
>            Reporter: Henning Schmiedehausen
>             Fix For: 3.0
>
>         Attachments: LANG-498.patch
>
>
> I needed to escape text to be print out to a file; mainly so that all non-ASCII characters (< 32 and >=127) are printed out as escapes (if available) or unicode escapes. This is a one-way conversion, there is no way to find out whether a String contained "\\n" or a newline before conversion, so I just set up escapeText() methods, no unescapeText().
> Please apply to the next release of commons-lang. :-)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (LANG-498) Add StringEscapeUtils.escapeText() methods

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ https://issues.apache.org/jira/browse/LANG-498?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-498.
------------------------------

    Resolution: Fixed

UnicodeEscaper.outsideOf(32, 0x7f) now works and would handle this case. Or if you want >= 7f, use 0x7e.

There is also a EscapeUtils.ESCAPE_JAVA_CTRL_CHARS and matching unescape. So your request is (currently anyway in trunk):

{code:java}
new AggregateTranslator(
            EscapeUtils.ESCAPE_JAVA_CTRL_CHARS,
            UnicodeEscaper.outsideOf(32, 0x7f)
        );
{code}

or:

{code:java}
EscapeUtils.ESCAPE_JAVA_CTRL_CHARS.with( UnicodeEscaper.outsideOf(32, 0x7f) )
{code}

I'm resolving this issue as I think this sufficiently simplifies your desire to share the escapeJava code.

> Add StringEscapeUtils.escapeText() methods
> ------------------------------------------
>
>                 Key: LANG-498
>                 URL: https://issues.apache.org/jira/browse/LANG-498
>             Project: Commons Lang
>          Issue Type: New Feature
>            Reporter: Henning Schmiedehausen
>             Fix For: 3.0
>
>         Attachments: LANG-498.patch
>
>
> I needed to escape text to be print out to a file; mainly so that all non-ASCII characters (< 32 and >=127) are printed out as escapes (if available) or unicode escapes. This is a one-way conversion, there is no way to find out whether a String contained "\\n" or a newline before conversion, so I just set up escapeText() methods, no unescapeText().
> Please apply to the next release of commons-lang. :-)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.