Multiline strings formatter

A free utility (mlsfmt) which simplifies a usage of multiline string constants.


Say you need to pass following json as a string:

"items": [{
  "id": "11111111-2222-3333-4444-555555555555",
  "name": "Test name",
  "quantity": 999,
  "subItems": [{
      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "name": "subitem 1"
    }, {
      "id": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
      "name": "subitem 2"
    }]
}]

Usually you will enclose every line in apostrophes, join the lines together with an ampersand &, append line continuation symbol |, care about left curly braces, left angle brackets, the apostrophes.

The utility automates this job: just paste raw text into the top textbox, and get formatted string in the bottom textbox and in Clipboard.

Home page: https://github.com/mikeduglas/Multiline-strings-formatter

4 Likes

Looks very nice.
Thanks Mike :smile:

Great!!
don’t know if it is already supported, but if the original string already contains a single quote ( ) it should be converted to <39> I suppose

2 apostrophes are shorter than <39> :slight_smile:

1 Like

…and possibly more confusing to aging eyes.

Well, I never use <39> for myself, but see a reason to add such option.

1 Like

for me this "'" is not readable then "<39>"

That could make a neat IDE plugin, based on selected text.

2 Likes

I think the “Refresh” button is missing. After I Paste a text in the upper box and may want to edit it and there is no way to refresh the result (lower box)

New release is ready, with the option Apostrophes as <39>.

1 Like

This can also be done using the Ultimate Clarionizer part of the ClarionLive Ultimate Utilities on GitHub.

Clarionizer it is written in Clarion so easy for anyone here to change, e.g. add an option to encode quotes as <39>.

Here’s Mike’s example JSON:

The change I would make first is that TEXT control from Segoe 8 pt to Consolas 11 pt to be a fixed space font making the code easy to read. Here is the Clarionizer result pasted so easier to read:

'"items": [{{ <13,10>' & |
'  "id": "11111111-2222-3333-4444-555555555555", <13,10>' & |
'  "name": "Test name", <13,10>' & |
'  "quantity": 999, <13,10>' & |
'  "subItems": [{{ <13,10>' & |
'      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", <13,10>' & |
'      "name": "subitem 1" <13,10>' & |
'    }, {{ <13,10>' & |
'      "id": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", <13,10>' & |
'      "name": "subitem 2" <13,10>' & |
'    }] <13,10>' & |
'}]'

Another change (and in my “String Builder”) would be an option to encode 13,10 as a ‘<13,10>’ in the output so the above example would output like below. I think MlsFmt has this as “Keep New lines”. I also append the “Length=304” to the end.

'"items": [{{' &|
'<13,10>  "id": "11111111-2222-3333-4444-555555555555",' &|
'<13,10>  "name": "Test name",' &|
'<13,10>  "quantity": 999,' &|
'<13,10>  "subItems": [{{' &|
'<13,10>      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",' &|
'<13,10>      "name": "subitem 1"' &|
'<13,10>    }, {{' &|
'<13,10>      "id": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",' &|
'<13,10>      "name": "subitem 2"' &|
'<13,10>    }]' &|
'<13,10>}]'   ! Length = 304
1 Like

There are a lot of better text editors around :slight_smile:

1 Like

Just added “Refresh” button.