SRP Editor and Utilities Empower Strings
The SRP Editor adds quality of life improvements. Most notably, it adds full syntax highlighting support for SRP PreCompiler’s newest feature: Super Strings. As usual, you only need SRP Utilities to gain the feature in all your code, but SRP Editor makes it native.
“It’s a Bird! It’s a Plane! It’s…”
Super strings! BASIC+ programmers spend a lot of time building strings. Concatenations are far more prevalent in our code than even arithmetic, especially with our reliance upon delimiters. We’re not alone. Many languages have come up with clever ways to deal with common string scenarios, so we updated the SRP_PreCompiler to bring those clever solutions to BASIC+.
Move Over Quotation Marks
Super strings use accent marks, which means you can use single and double quotations in your string without concatenation. The following string not only avoids concatenation on your end as the developer, it actually avoids concatenation at runtime. Congratulations, you just effortlessly saved a few CPU cycles!
Var = `"I'd be delighted," she said cheerfully.`
Interpolating Variables
Interpolating variables is a more compact form of concatenation: it’s like weaving your variables into the string. Let’s interpolate a variable called “Name” and a system variable into our string without concatenation.
Var = `Hello, $Name. Your login is @USERNAME.`
In super strings, the $ and @ characters are reserved. The dollar sign means you are weaving in a variable. The at-symbol means you are weaving in a system variable. If you need these characters as-is in your super string, just double them up.
Var = `Hello, $Name. You owe $$5.00`
Expressions are supported by surrounding them in curly braces immediately after the dollar sign.
Var = `${If Gender = 'M' then "His" else "Her"} name is ${Trim(FirstName)}`
Important: Using angle brackets on a variable is considered an expression, so make sure to use the curly braces or you might be in for a surprise.
Incorrect = `The book "$BookInfo<1>" was written by $BookInfo<2>.`
Correct = `The book "${BookInfo<1>}" was written by ${BookInfo<2>}.`
Delimiters
Supers strings are optimized to produce the fewest concatenations possible. This is particularly true when it comes to delimiters.
// 8 concatenations
OldWay = "Monday":@FM:"Tuesday":@FM:"Wednesday":@FM:"Thursday":@FM:"Friday"
// No concatenations
NewWay = `Monday@FMTuesday@FMWednesday@FMThursday@FMFriday`
In the SRP Editor, interpolated variables are syntax highlighted inside the strings to make readability much easier.
Raw Strings
But we’re not done! Super strings also allow you to work with raw, multiline strings:
Var = ```
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$$5.95</price>
<description>Two Belgian Waffles with real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$$7.95</price>
<description>Light Belgian waffles covered with strawberries
and whipped cream</description>
<calories>900</calories>
</food>
</breakfast_menu>
```
There are a couple rules to follow for SRP_PreCompiler to properly understand your raw string:
- Opener and closer must be at least 3 accent marks, and they must match. If you open with five accents, you must close with 5 accents. Why would you use more than 3? If you needed multiple accent marks in a row inside your raw string, then make sure your opener and closer use more. If, for example, I open and close with 10 accent marks, then I can have 9 or less accent marks in a row inside the string.
- Opener and closer must be on their own lines. The string begins on the line after your opener and ends on the line just before your closer.
- Blank lines and line breaks are included in the string.
- Any whitespace that appears in front of your closer is ignored on all other lines. In the above example, there are four spaces in front of the closing accent marks, so four spaces will be ignored at the beginning of each line.
- You can comment out lines, but you must use the asterisk and it must be the first character of the line. (Using Ctrl+/ in the SRP Editor does this for you).
Raw strings can be useful for configuration or large default datasets that you don’t want stored in a record for someone to mess with. The SRP_PreCompiler will account for string size limits and perform concatenation as needed. In the debugger, the whole string will behave like a single operation. It is worth noting that object code in OpenInsight does have a size limit for literal data. In most circumstances, you don’t have to worry about it, but if you include pages and pages of raw strings in a stored procedure that is already very large, you could run into issues.
Raw strings also support interpolation, great for setting up some JSON:
Var = ```
{
"first-name" : "${Employee<1>}",
"last-name" : "${Employee<2>}",
"dob" : "${SRP_Date("Format", Employee<3>, "YYYY-MM-DD")}"
}
```
Lastly, you might want to see your string nicely formatted in your code, but you don’t want all that whitespace at runtime. In that case, you can use the -compress argument:
Var = ``` -compress
{
"CloseButtons" : true,
"Tabs" : [
{
"TabCaption" : "${Title<1>}",
"TabImage" : "${Icon<1>}"
},
{
"TabCaption" : "${Title<2>}",
"TabImage" : "${Icon<2>}"
}
]
}
```
The -compress argument will trim each line and strip all line breaks at compile time, making it equivalent to the following:
Var = '{"CloseButtons" : true,"Tabs" : [{"TabCaption" : "':Title<1>:'","TabImage" : "':Icon<1>:'"},{"TabCaption" : "':Title<2>:'","TabImage" : "':Icon<2>:'"}]}'
Nice and compact for passing to our control for setup. Now you can have your cake and eat it too.
Other Changes
SRP Editor 3.4.6 has moved the cursor information from the status bar into the editor control itself. You’ll see it in the bottom right corner, next to the scrollbars, which are now custom drawn to match your code theme.
Today’s Releases
There are other tweaks and fixes in this release. See the Version History for complete details. You can download SRP Editor from our products page.
The SRP Editor installer includes the SRP Utilities. If you need just the SRP Utilities, you can download the stand-alone installer. See the Version History for SRP Utilities for details on all the latest changes.
We’ve also released version 4.2.6 of the SRP ActiveX Controls, which you can download here and view the changes here.
Leave a Reply