-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ Contents: | |
|
||
hello | ||
integers | ||
strings | ||
pythagoras | ||
guiindex | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
Strings | ||
======= | ||
|
||
A string is basically a sequence of characters | ||
with a definite length. | ||
|
||
Type | ||
---- | ||
|
||
The easiest string type to use in Felix is the one based | ||
on C++: | ||
|
||
.. code-block:: felix | ||
type string = "::std::basic_string<char>" | ||
requires Cxx_headers::string | ||
; | ||
Literals | ||
-------- | ||
|
||
There are two simple forms of string literals: | ||
|
||
.. code-block:: felix | ||
var x = "I am a string"; | ||
var y = 'I am a string too'; | ||
using double quote delimiters and single quote delimiters. | ||
These literals cannot exceed a single line. However | ||
you can concatenate them by juxtaposition: | ||
|
||
.. code-block:: felix | ||
var verse = | ||
"I am the first line,\n" | ||
'and I am the second.' | ||
; | ||
Notice the special encoding `\n` which inserts and end of | ||
line character into the string rather than a `\` followed | ||
by an `n`. This is called an escape. | ||
|
||
You can prevent escapes being translated with raw | ||
strings like this: | ||
|
||
.. code-block:: felix | ||
r"This \n is retained as two chars" | ||
Only double quoted strings can be raw. | ||
|
||
Felix also has triple quoted strings, which span | ||
line boundaries, and include end of lines in the | ||
literal: | ||
|
||
.. code-block:: felix | ||
"""This is | ||
a very long | ||
string""" | ||
which contains two end of line characters in the string, whilst | ||
this one: | ||
|
||
.. code-block:: felix | ||
''' | ||
Here is another | ||
long string | ||
''' | ||
has three end of lines (one after the first triple quote). | ||
|
||
Operations | ||
---------- | ||
|
||
Strings can be concatenated with the infix `+` operator or | ||
just written next to each other, juxtaposition has a higher | ||
precedence than infix `+`. | ||
|
||
.. code-block:: felix | ||
var x = "middle"; | ||
var y = "Start" x + "end"; | ||
In this case, the first concatenation of x is done first, | ||
then the second one which appends "end". The result | ||
is independent of the ordering because concatenation | ||
is associative, the run time performance, however, is not, | ||
because concatenation requires coping. | ||
|
||
|
||
|
||
|