Generate String Literal #19

Open
opened 2018-09-19 18:54:33 +00:00 by eelke · 2 comments
eelke commented 2018-09-19 18:54:33 +00:00 (Migrated from gitlab.com)

The basic algorithm would be to place begin and end markers around the string and escape special characters. However we want it to be e general solution so we need to be able to configure this
and when you think about it then especially the escaping part is not that easy.

Escapes

Let's start with considering classic C++ strings the escape rules are fairly simple but there are actual three different escapes.

  • escape special meaning as the escape character '' and the quote have special meaning they need escaping to "remove" the special meaning. In this case the escape is thus followed by a normal character.
  • escape that changes the meaning of the character like \t which represents a tab character.
  • numerical escapes in this case the escape is followed by a letter and a number where the number specifies the char/codepoint.

So when converting to escape there are three types of conversions to perform.

Do other languages need something else?

Quote's

Commonly use single or double quotes with single line literals. Some languages allow for multiline string literals with more complex begin and end markers.

  • cpp has raw strings R"delimiter(raw characters)delimiter"
  • php has heredoc and nowdoc
The basic algorithm would be to place begin and end markers around the string and escape special characters. However we want it to be e general solution so we need to be able to configure this and when you think about it then especially the escaping part is not that easy. ## Escapes Let's start with considering classic C++ strings the escape rules are fairly simple but there are actual three different escapes. - escape special meaning as the escape character '\' and the quote have special meaning they need escaping to "remove" the special meaning. In this case the escape is thus followed by a normal character. - escape that changes the meaning of the character like \t which represents a tab character. - numerical escapes in this case the escape is followed by a letter and a number where the number specifies the char/codepoint. So when converting to escape there are three types of conversions to perform. Do other languages need something else? ## Quote's Commonly use single or double quotes with single line literals. Some languages allow for multiline string literals with more complex begin and end markers. - cpp has raw strings R"delimiter(raw characters)delimiter" - php has heredoc and nowdoc
eelke commented 2018-11-11 09:45:58 +00:00 (Migrated from gitlab.com)

Needed by #18

Needed by #18
eelke commented 2019-08-19 13:53:15 +00:00 (Migrated from gitlab.com)

ConvertToMultiLineCString does most (all?) of this for atleast c/cpp possible good bases for more advanced implementation.

ConvertToMultiLineCString does most (all?) of this for atleast c/cpp possible good bases for more advanced implementation.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: eelke/pgLab#19
No description provided.