lingua-franca 0.10.1
Lingua Franca code generator
Loading...
Searching...
No Matches
org.lflang.util.StringUtil Class Reference

Utilities to manipulate strings. More...

Static Public Member Functions

static String addDoubleQuotes (String str)
static String camelToSnakeCase (String str)
 Convert a string in Camel case to snake case.
static boolean hasQuotes (String str)
 Return true if the given string is surrounded by single or double quotes,.
static< T > String joinObjects (List< T > things, String delimiter)
static String normalizeEol (String s)
 Normalize end-of-line sequences to the Linux style.
static String removeQuotes (String str)
 If the given string is surrounded by single or double quotes, returns what's inside the quotes.
static String trimCodeBlock (String code, int firstLineToConsider)
 Intelligently trim the white space in a code block.

Detailed Description

Utilities to manipulate strings.

Author
Clément Fournier

Member Function Documentation

◆ addDoubleQuotes()

String org.lflang.util.StringUtil.addDoubleQuotes ( String str)
static

◆ camelToSnakeCase()

String org.lflang.util.StringUtil.camelToSnakeCase ( String str)
static

Convert a string in Camel case to snake case.

E.g. MinimalReactor will be converted to minimal_reactor. The string is assumed to be a single camel case identifier (no whitespace).

◆ hasQuotes()

boolean org.lflang.util.StringUtil.hasQuotes ( String str)
static

Return true if the given string is surrounded by single or double quotes,.

◆ joinObjects()

static< T > String org.lflang.util.StringUtil.joinObjects ( List< T > things,
String delimiter )
static

◆ normalizeEol()

String org.lflang.util.StringUtil.normalizeEol ( String s)
static

Normalize end-of-line sequences to the Linux style.

◆ removeQuotes()

String org.lflang.util.StringUtil.removeQuotes ( String str)
static

If the given string is surrounded by single or double quotes, returns what's inside the quotes.

Otherwise returns the same string.

Returns null if the parameter is null.

◆ trimCodeBlock()

String org.lflang.util.StringUtil.trimCodeBlock ( String code,
int firstLineToConsider )
static

Intelligently trim the white space in a code block.

The leading whitespaces of the first non-empty code line is considered as a common prefix across all code lines. If the remaining code lines indeed start with this prefix, it removes the prefix from the code line.

For examples, this code

int test = 4;
if (test == 42) {
printf("Hello\n");
}

will be trimmed to this:

int test = 4;
if (test == 42) {
printf("Hello\n");
}
Parameters
codethe code block to be trimmed
firstLineToConsiderThe first line not to ignore.
Returns
trimmed code block

The documentation for this class was generated from the following file:
  • /Users/runner/work/lingua-franca/lingua-franca/core/src/main/java/org/lflang/util/StringUtil.java