In Dunaj, a String type represents strings. This type directly maps to the host string type, without any wraping.

In Dunaj lite, the type name clashes with host class java.lang.String. Because of this, Dunaj provides type alias called String+, that can be used in place of String.

String is an immutable and homogeneous collection of characters. String type, constructor, predicates and other related functionalities are defined in dunaj.string namespace.

There is a dedicated abstract type protocol for string-like objects called ICharSequence. This protocol is implemented for strings, string sections, reversed strings and mutable strings. Moreover, a provide-char-sequence functions wraps arbitrary indexed collection into an instance of ICharSequence if needed.

Character sequences and strings are immutable but not persistent collections. Strings main purpose is to convey a textual information and not to be a container of characters. Because of this, String is not considered a sequential collection and is not even equal to other persistent collections with a same content.

Features

String objects are collections (can be reduced and folded), implement natural total ordering (can be compared), are counted and support random access to their items (via nth). Just like symbols and keywords, strings are INamed. Strings are also editable.

String provide fast reduction by implementing IBatchedRed on chars. String support both slicing (shared-nothing slice) and sectioning (shared subsection). Instances of string can be reversed.

As string are collections, a string-factory is provided that implements ICollectionFactory protocol. A convenience constructors str and ->str are provided

Dunaj’s str has a different semantics from Clojure’s one, which is in Dunaj renamed to →str.

Syntax

Dunaj follows Clojure’s syntax for string. Following table compares syntax for JSON, EDN and CLJ formats:

JSON EDN CLJ

syntax

wrapped in "

wrapped in "

wrapped in "

may span multiple lines

NO

YES

YES

characters which must be escaped

" \ and control characters (U+0000 to U+001F)

" \

" \

escape characters

\" \\ \/ \b \f \n \r \t

\" \\ \n \r \t

\" \\ \' \b \f \n \r \t

unicode escapes

\uNNNN

NO, not mentioned in specs

\uNNNN

octal escapes

NO

NO

\0 to \377