Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string escape/unescape operations #62

Merged
merged 1 commit into from
Aug 15, 2017
Merged

Add string escape/unescape operations #62

merged 1 commit into from
Aug 15, 2017

Conversation

dalemyers
Copy link

@dalemyers dalemyers commented Jan 23, 2017

These operations are useful for taking the contents of a string, and making it
suitable for use as a stand alone string. For example, in an IDE you might see
a string which is represented as: "Say \"Hello\"". The escaped double quotes
are shown to make it clear that they do not end the string, despite the fact
that they are not truly part of the string. In order to get the raw string, you
would need to copy this, then manually remove the backslashes. The new
String_.run_unescape operation does this automatically.

The String_.run_escape is the inverse. It allows you to take a string such as
Say "Hello", and paste it between two quotes without having to manually
escape it.

The "Parse escaped string" operation is similar, but only operates on new line
characters. This works on newlines, backslashes, single and double quotes.

These operations are useful for taking the contents of a string, and making it
suitable for use as a stand alone string. For example, in an IDE you might see
a string which is represented as: "Say \"Hello\"". The escaped double quotes
are shown to make it clear that they do not end the string, despite the fact
that they are not truly part of the string. In order to get the raw string, you
would need to copy this, then manually remove the backslashes. The new
String_.run_unescape operation does this automatically.

The String_.run_escape is the inverse. It allows you to take a string like the
one above, and paste it between two quotes without having to manually escape
it.
@n1474335
Copy link
Member

Hi @Vel0X,

This looks really good, thanks for contributing. There are a few things to consider and modify before we merge this.

  1. There is already an operation which overlaps somewhat with your 'Unescape string' operation. It's called 'Parse escaped string'. It does differ slightly from your operation though. Yours handles escaped quotes which it does not, but it handles escaped hex and a few other special characters which yours does not. Perhaps if your new operations were modified to support all these cases, we could get rid of 'Parse escaped string' altogether.
  2. It would probably make sense to move these operations into the StrUtils namespace instead of creating a new one (Strings_). Make sure you include your author tag in each of your functions in a shared namespace.
  3. Try to structure the examples in your comments in the same way as the rest of the code base. Example here.

I see you have signed the CLA so once these changes have been made, we'll be good to go.

@mattnotmitt
Copy link
Collaborator

mattnotmitt commented Aug 4, 2017

@Vel0X Are you still planning to work on this? I'd be happy to do a new PR to get this cleaned up if you can't.

@dalemyers
Copy link
Author

It's been on the back of my mind, but I've not had the chance. Feel free.

@n1474335 n1474335 merged commit fadd715 into gchq:master Aug 15, 2017
@dalemyers dalemyers deleted the string_escaping_unescaping branch August 16, 2017 08:13
BRAVO68WEB pushed a commit to BRAVO68WEB/CyberChef that referenced this pull request May 29, 2022
[FEATURE] Opening methods, and context menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants