Skip to content

String operators

Text operations.

Every program can use these operators. No import is necessary.

Operator Arguments Gives
!= left: string, right: string boolean
!null? arg: <optional>string boolean
+ left: string, right: double string
+ left: string, right: enum string
+ left: string, right: int string
+ left: string, right: string string
== left: string, right: string boolean
&#124;&#124; left: string, right: string string
async_read_file path: string, filename: string &lt;optional&gt;string
at text: string, position: int string
buffer_from_string str: string buffer
buffer_read_file path: string, filename: string buffer
ccode text: string char
char_length text: string int
charAt text: string, position: int int
charcode text: string char
contains str: string, sub: string boolean
dir_exists path: string boolean
endsWith str: string, suffix: string boolean
env_var name: string &lt;optional&gt;string
file_exists path: string, filename: string boolean
file_mtime path: string, filename: string int
find_process path: string RangerProcessBase
first str: string string
get_option name: string string
get_required_option n: string string
has str: string boolean
has_option name: string boolean
indexOf str: string, key: string int
indexOfFrom str: string, key: string, startPos: int int
iso_add_days iso: string, days: int string
iso_between d: string, start: string, end: string boolean
iso_compare a: string, b: string int
lastIndexOf str: string, key: string int
length text: string int
md5 input: string string
normalize arg: string string
null? arg: <optional>string boolean
path_dirname arg: string string
read_file path: string, filename: string &lt;optional&gt;string
read_file_sync path: string, filename: string &lt;optional&gt;string
regex_test pattern: string, haystack: string boolean
replace str: string, oldStr: string, newStr: string string
run_process_result program: string, args: [string], cwd: string, capture: boolean, env: [string] [string]
sha256 input: string string
startsWith str: string, prefix: string boolean
str2double value: string &lt;optional&gt;double
str2int value: string &lt;optional&gt;int
strlen text: string int
strsplit strToSplit: string, delimiter: string [string]
substring text: string, position: int string
substring text: string, start: int, end: int string
to_charbuffer text: string charbuffer
to_chars text: string [int]
to_double value: string &lt;optional&gt;double
to_int txt: string &lt;optional&gt;int
to_int value: string int
to_lowercase s: string string
to_uppercase s: string string
trim value: string string
trim_right value: string string
unwrap arg: <optional>string string
utf8_substring text: string, start: int, end: int string

Target support marks

  • Own template
  • Default template
  • No template

The operator works for a target with an own template and for a target with the default template. The default template is the * entry of the definition: it writes the same code for every target that has no template of its own. A target with no template writes no code, and a program that uses the operator does not compile for that target.

!=

(!= left right) → boolean
!=(left: string, right: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: own template
  • Python: default template
  • Java: own template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: own template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 11461

!null?

(!null? arg) → boolean
!null?(arg: <optional>string)

Target support

  • JavaScript: no template
  • TypeScript: no template
  • Go: no template
  • Rust: no template
  • Python: no template
  • Java: no template
  • Kotlin: no template
  • Dart: no template
  • Swift: no template
  • C#: no template
  • C++: own template
  • PHP: no template
  • Scala: no template

Definition: compiler/Lang.rgr, line 5615

+

(+ left right) → string
+(left: string, right: double)

A double reaches a string in its shortest form that reads back as the same value -- 1.5 is "1.5", not "1.500000". Go used 'f' with six digits and C++ used std::to_string, which also fixes six digits, so the same program printed a different number on those two targets than on every other one. See r_double_to_string below.

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: default template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: default template
  • C++: own template
  • PHP: own template
  • Scala: default template

Definition: compiler/Lang.rgr, line 4546

+

(+ left right) → string
+(left: string, right: enum)

string + operations

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 4507

+

(+ left right) → string
+(left: string, right: int)

Go; strconv.Itoa

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: default template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: default template
  • C++: own template
  • PHP: own template
  • Scala: default template

Definition: compiler/Lang.rgr, line 4580

+

(+ left right) → string
+(left: string, right: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: own template
  • Scala: default template

Definition: compiler/Lang.rgr, line 4531

==

(== left right) → boolean
==(left: string, right: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: own template
  • Python: default template
  • Java: own template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: own template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 11369

||

(|| left right) → string
||(left: string, right: string)

selects the first string if length > 0, else the second...

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 4873

async_read_file

(async_read_file path filename) → <optional>string
async_read_file(path: string, filename: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: no template
  • Rust: no template
  • Python: no template
  • Java: no template
  • Kotlin: no template
  • Dart: no template
  • Swift: no template
  • C#: no template
  • C++: no template
  • PHP: no template
  • Scala: no template

Definition: compiler/Lang.rgr, line 3821

at

(at text position) → string
at(text: string, position: int)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: default template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 7436

buffer_from_string

(buffer_from_string str) → buffer
buffer_from_string(str: string)

Convert string to buffer (UTF-8 encoded)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: no template

Definition: compiler/Lang.rgr, line 6873

buffer_read_file

(buffer_read_file path filename) → buffer
buffer_read_file(path: string, filename: string)

Read a binary file into a buffer

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: no template

Definition: compiler/Lang.rgr, line 7009

ccode

(ccode text) → char
ccode(text: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 8334

char_length

(char_length text) → int
char_length(text: string)

How many CHARACTERS are in this string -- the same number on every target, whatever unit that target happens to index in. `strlen` counts the target's own unit: UTF-16 code units on JavaScript, Java, Kotlin, C#, Scala, Dart and Swift 6, UTF-8 bytes on Rust, Go, C++ and PHP, code points on Python. That is the right number for a scan -- `while (i < (strlen s))` with `charAt s i` reads the same string either way -- and the wrong one for anything a person sees: a column, a width, a padding count, a truncation point. Those differ per target the moment the text stops being ASCII, and they differ silently. `char_length` is the count that does not: Unicode code points, the length of `(to_chars s)` without building the array. def w:int (char_length line) ; a column def n:int (strlen line) ; a scan bound For ASCII the two are equal, so the cost of choosing the honest one is nothing on the input that dominates. docs/plans/PLAN_STRING_INDEXING.md 3.3.

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 6640

charAt

(charAt text position) → int
charAt(text: string, position: int)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 7601

charcode

(charcode text) → char
charcode(text: string)

(charcode "A")

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 8217

contains

(contains str sub) → boolean
contains(str: string, sub: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 9754

dir_exists

(dir_exists path) → boolean
dir_exists(path: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 3303

endsWith

(endsWith str suffix) → boolean
endsWith(str: string, suffix: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 9725

env_var

(env_var name) → <optional>string
env_var(name: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: no template

Definition: compiler/Lang.rgr, line 1480

file_exists

(file_exists path filename) → boolean
file_exists(path: string, filename: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 3231

file_mtime

(file_mtime path filename) → int
file_mtime(path: string, filename: string)

Returns the file modification time (ms on es6/cpp; seconds on go)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 3410

find_process

(find_process path) → RangerProcessBase
find_process(path: string)

Process lifecycle operators (distinct from HttpServer start/stop)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: own template
  • Dart: default template
  • Swift: own template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 11800

first

(first str) → string
first(str: string)

first character of the string

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 10158

get_option

(get_option name) → string
get_option(name: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 945

get_required_option

(get_required_option n) → string
get_required_option(n: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 951

has

(has str) → boolean
has(str: string)

If string value is greater than > 0

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 932

has_option

(has_option name) → boolean
has_option(name: string)

compiler options...

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 939

indexOf

(indexOf str key) → int
indexOf(str: string, key: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Position of a substring

docs/examples/core/string/index-of.rgr
class Main {
sfn main:void () {
def text "Ranger compiler"
def position (indexOf text "compiler")
print ("position " + position)
}
}
main function, JavaScript
const text = "Ranger compiler";
const position = text.indexOf("compiler");
console.log("position " + position);
The complete file
class Main {
constructor() {
}
}
/* static JavaSript main routine at the end of the JS file */
function __js_main() {
const text = "Ranger compiler";
const position = text.indexOf("compiler");
console.log("position " + position);
}
__js_main();

Definition: compiler/Lang.rgr, line 9337

indexOfFrom

(indexOfFrom str key startPos) → int
indexOfFrom(str: string, key: string, startPos: int)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 9459

iso_add_days

(iso_add_days iso days) → string
iso_add_days(iso: string, days: int)

ISO calendar dates (YYYY-MM-DD). See lib/IsoDate/ and ai/ISO_DATE.md.

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: own template
  • Kotlin: own template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 6170

iso_between

(iso_between d start end) → boolean
iso_between(d: string, start: string, end: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: own template
  • Kotlin: own template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 6190

iso_compare

(iso_compare a b) → int
iso_compare(a: string, b: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: own template
  • Kotlin: own template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 6180

lastIndexOf

(lastIndexOf str key) → int
lastIndexOf(str: string, key: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 9582

length

(length text) → int
length(text: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: default template
  • Dart: default template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 10079

md5

(md5 input) → string
md5(input: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: no template
  • Rust: no template
  • Python: no template
  • Java: no template
  • Kotlin: no template
  • Dart: no template
  • Swift: no template
  • C#: no template
  • C++: no template
  • PHP: no template
  • Scala: no template

Definition: compiler/Lang.rgr, line 1280

normalize

(normalize arg) → string
normalize(arg: string)

I/O

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: default template
  • Kotlin: own template
  • Dart: own template
  • Swift: default template
  • C#: own template
  • C++: own template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 2250

null?

(null? arg) → boolean
null?(arg: <optional>string)

Gives true when the optional text is empty.

Target support

  • JavaScript: no template
  • TypeScript: no template
  • Go: no template
  • Rust: no template
  • Python: no template
  • Java: no template
  • Kotlin: no template
  • Dart: no template
  • Swift: no template
  • C#: no template
  • C++: own template
  • PHP: no template
  • Scala: no template

Optional values

docs/examples/core/generic/optionals.rgr
class Main {
sfn main:void () {
def name@(optional):string
def shown (?? name "unknown")
print ("default " + shown)
if (null? name) {
print "the name is empty"
}
name = "Ada"
def value (!! name)
print ("value " + value)
}
}
main function, JavaScript
let name;
const shown = (name ?? "unknown");
console.log("default " + shown);
if ( typeof(name) === "undefined" ) {
console.log("the name is empty");
}
name = "Ada";
const value = name;
console.log("value " + value);
The complete file
class Main {
constructor() {
}
}
/* static JavaSript main routine at the end of the JS file */
function __js_main() {
let name;
const shown = (name ?? "unknown");
console.log("default " + shown);
if ( typeof(name) === "undefined" ) {
console.log("the name is empty");
}
name = "Ada";
const value = name;
console.log("value " + value);
}
__js_main();

Definition: compiler/Lang.rgr, line 5560

path_dirname

(path_dirname arg) → string
path_dirname(arg: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: default template
  • Kotlin: own template
  • Dart: own template
  • Swift: default template
  • C#: own template
  • C++: own template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 2563

read_file

(read_file path filename) → <optional>string
read_file(path: string, filename: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 3828

read_file_sync

(read_file_sync path filename) → <optional>string
read_file_sync(path: string, filename: string)

read_file, but not async on JavaScript. read_file awaits fs.readFile, so on JavaScript every function that reads a file, and every function that can reach one, is emitted async: in the compiler that was the whole import, analysis and writer chain, and each call then paid for a promise and a heap frame -- three seconds of a twelve second compile, all of it garbage. This one reads with readFileSync and answers absent on failure, as read_file does. The other targets read synchronously either way and share read_file's polyfills, which the writer emits once per text. Use it where blocking the event loop is fine: a command line tool, not a server.

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 4017

regex_test

(regex_test pattern haystack) → boolean
regex_test(pattern: string, haystack: string)

Case-insensitive regex substring search. Pattern is a string (no /literal/). See lib/Regex/ and ai/REGEX.md.

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: no template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: no template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 6201

replace

(replace str oldStr newStr) → string
replace(str: string, oldStr: string, newStr: string)

`replace` changes every occurrence. Half of the templates used to change only the first one -- JavaScript, Go, C++ and Python -- and the other half changed them all, so the same program gave two answers. The compiler itself wants every occurrence: the trigraph escaping of RangerCppClassWriter.rgr calls `(replace s "??=" ...)` on a whole generated file.

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 9780

run_process_result

(run_process_result program args cwd capture env) → [string]
run_process_result(program: string, args: [string], cwd: string, capture: boolean, env: [string])

run a command line program and answer ([exit code, stdout, stderr]); capture=false streams its output to this program instead

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: no template

Definition: compiler/Lang.rgr, line 1642

sha256

(sha256 input) → string
sha256(input: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: no template

Definition: compiler/Lang.rgr, line 957

startsWith

(startsWith str prefix) → boolean
startsWith(str: string, prefix: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 9704

str2double

(str2double value) → <optional>double
str2double(value: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 8816

str2int

(str2int value) → <optional>int
str2int(value: string)

note: this has now different value, it is optional int... the optionality of the return value should be preserved can not do just def x:int (10 + (str2int "hello")) --> optional return value here...

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 8627

strlen

(strlen text) → int
strlen(text: string)

Gives the number of characters in the text.

The count is a count of code points, not a count of bytes.

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: default template
  • Dart: default template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Text length and part

docs/examples/core/string/text.rgr
class Main {
sfn main:void () {
def text "Ranger compiler"
print ("length " + (strlen text))
print ("part " + (substring text 0 6))
}
}
main function, JavaScript
const text = "Ranger compiler";
console.log("length " + text.length);
console.log("part " + text.substring(0, 6 ));
The complete file
class Main {
constructor() {
}
}
/* static JavaSript main routine at the end of the JS file */
function __js_main() {
const text = "Ranger compiler";
console.log("length " + text.length);
console.log("part " + text.substring(0, 6 ));
}
__js_main();

Definition: compiler/Lang.rgr, line 6060

strsplit

(strsplit strToSplit delimiter) → [string]
strsplit(strToSplit: string, delimiter: string)

wr.out (").to[collection.mutable.ArrayBuffer]" false kotlin could use also something like: .split(Regex("(?<=[!?])|(?=[!?])")) swift : .components(separatedBy:

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: default template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 5991

substring

(substring text position) → string
substring(text: string, position: int)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 7422

substring

(substring text start end) → string
substring(text: string, start: int, end: int)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: default template

Text length and part

docs/examples/core/string/text.rgr
class Main {
sfn main:void () {
def text "Ranger compiler"
print ("length " + (strlen text))
print ("part " + (substring text 0 6))
}
}
main function, JavaScript
const text = "Ranger compiler";
console.log("length " + text.length);
console.log("part " + text.substring(0, 6 ));
The complete file
class Main {
constructor() {
}
}
/* static JavaSript main routine at the end of the JS file */
function __js_main() {
const text = "Ranger compiler";
console.log("length " + text.length);
console.log("part " + text.substring(0, 6 ));
}
__js_main();

Definition: compiler/Lang.rgr, line 7865

to_charbuffer

(to_charbuffer text) → charbuffer
to_charbuffer(text: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 6724

to_chars

(to_chars text) → [int]
to_chars(text: string)

A `charbuffer` is a buffer of BYTES -- see the block above the charbuffer overloads for what that does and does not mean. This operator is one of the two places the line between text and bytes is crossed, so it is the place that names the encoding: the bytes are the UTF-8 of the text, on every target. docs/plans/PLAN_STRING_INDEXING.md 2.3. The portable indexable view of text: Unicode CODE POINTS, the same sequence on every target, built once in O(n) and read in O(1). `charAt` on a `string` is the target's own unit -- a UTF-16 code unit, a code point or a UTF-8 byte, depending on where it runs -- and that is what makes it O(1) there. It is right for a scanner over ASCII structure and wrong for anything a human wrote. `to_chars` is the conversion that makes an index mean one thing everywhere, and because the program names it, the allocation is asked for rather than hidden. def cs:[int] (to_chars s) def n:int (array_length cs) def c:int (itemAt cs 0) Above the Basic Multilingual Plane this is the only view that agrees with itself: an emoji is ONE element here and two UTF-16 units or four UTF-8 bytes in the other views. docs/plans/PLAN_STRING_INDEXING.md 2.2.

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 6496

to_double

(to_double value) → <optional>double
to_double(value: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 8951

to_int

(to_int txt) → <optional>int
to_int(txt: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: default template
  • Rust: default template
  • Python: default template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: default template
  • C#: default template
  • C++: default template
  • PHP: default template
  • Scala: default template

Definition: compiler/Lang.rgr, line 7391

to_int

(to_int value) → int
to_int(value: string)

Target support

  • JavaScript: no template
  • TypeScript: no template
  • Go: no template
  • Rust: no template
  • Python: no template
  • Java: no template
  • Kotlin: no template
  • Dart: no template
  • Swift: no template
  • C#: no template
  • C++: no template
  • PHP: own template
  • Scala: no template

Definition: compiler/Lang.rgr, line 11361

to_lowercase

(to_lowercase s) → string
to_lowercase(s: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 11272

to_uppercase

(to_uppercase s) → string
to_uppercase(s: string)

Target support

  • JavaScript: own template
  • TypeScript: own template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 11303

trim

(trim value) → string
trim(value: string)

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: default template
  • Kotlin: default template
  • Dart: default template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 5936

trim_right

(trim_right value) → string
trim_right(value: string)

trim_right - removes whitespace from the right side of string

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 5962

unwrap

(unwrap arg) → string
unwrap(arg: <optional>string)

see the null? overload: an optional string carries its own presence bit on C++, so reading the value out of one is not a no-op.

Target support

  • JavaScript: no template
  • TypeScript: no template
  • Go: no template
  • Rust: no template
  • Python: no template
  • Java: no template
  • Kotlin: no template
  • Dart: no template
  • Swift: no template
  • C#: no template
  • C++: own template
  • PHP: no template
  • Scala: no template

Definition: compiler/Lang.rgr, line 4323

utf8_substring

(utf8_substring text start end) → string
utf8_substring(text: string, start: int, end: int)

The code point slice. `substring` counts whatever unit its target's strlen and charAt count, so that scanning and slicing agree; this one always counts characters, for text being measured rather than scanned -- truncating a label to twenty characters, say, without cutting a multi byte character in half. Targets whose strings are UTF-16 (Java, Kotlin, Scala, C#, and the JavaScript family) count code points here, except that a character outside the basic plane still occupies two units in the `*` fallback -- Array.from is the code point split, so the fallback below uses it.

Target support

  • JavaScript: default template
  • TypeScript: default template
  • Go: own template
  • Rust: own template
  • Python: own template
  • Java: own template
  • Kotlin: own template
  • Dart: own template
  • Swift: own template
  • C#: own template
  • C++: own template
  • PHP: own template
  • Scala: own template

Definition: compiler/Lang.rgr, line 8049

Ranger 3.5.1 · commit f323fd4 · development build