aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-09-19 20:58:09 +0800
committerchriseth <chris@ethereum.org>2018-09-19 21:54:30 +0800
commit32362f1b386cf2667152accff868dcd722fb0cdb (patch)
tree3bf97c777ba2341cc40bb208256a510b63ebaf71
parent785cbf40056e8d4c3c7629d37ec69b403e768aa9 (diff)
downloaddexon-solidity-32362f1b386cf2667152accff868dcd722fb0cdb.tar
dexon-solidity-32362f1b386cf2667152accff868dcd722fb0cdb.tar.gz
dexon-solidity-32362f1b386cf2667152accff868dcd722fb0cdb.tar.bz2
dexon-solidity-32362f1b386cf2667152accff868dcd722fb0cdb.tar.lz
dexon-solidity-32362f1b386cf2667152accff868dcd722fb0cdb.tar.xz
dexon-solidity-32362f1b386cf2667152accff868dcd722fb0cdb.tar.zst
dexon-solidity-32362f1b386cf2667152accff868dcd722fb0cdb.zip
Last part of value types.
-rw-r--r--docs/types.rst48
1 files changed, 42 insertions, 6 deletions
diff --git a/docs/types.rst b/docs/types.rst
index de384e2f..a86bcab7 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -398,9 +398,37 @@ a non-rational number).
String Literals
---------------
-String literals are written with either double or single-quotes (``"foo"`` or ``'bar'``). They do not imply trailing zeroes as in C; ``"foo"`` represents three bytes not four. As with integer literals, their type can vary, but they are implicitly convertible to ``bytes1``, ..., ``bytes32``, if they fit, to ``bytes`` and to ``string``.
+String literals are written with either double or single-quotes (``"foo"`` or ``'bar'``). They do not imply trailing zeroes as in C; ``"foo"`` represents three bytes, not four. As with integer literals, their type can vary, but they are implicitly convertible to ``bytes1``, ..., ``bytes32``, if they fit, to ``bytes`` and to ``string``.
+
+String literals support the following escape characters:
+
+ - ``\<newline>`` (escapes an actual newline)
+ - ``\\`` (backslash)
+ - ``\'`` (single quote)
+ - ``\"`` (double quote)
+ - ``\b`` (backspace)
+ - ``\f`` (form feed)
+ - ``\n`` (newline)
+ - ``\r`` (carriage return)
+ - ``\t`` (tab)
+ - ``\v`` (vertical tab)
+ - ``\xNN`` (hex escape, see below)
+ - ``\uNNNN`` (unicode escape, see below)
+
+``\xNN`` takes a hex value and inserts the appropriate byte, while ``\uNNNN`` takes a Unicode codepoint and inserts an UTF-8 sequence.
+
+The string in the following example has a length of ten bytes.
+It starts with a newline byte, followed by a double quote, a single
+quote a backslash character and then (without separator) the
+character sequence ``abcdef``.
-String literals support escape characters, such as ``\n``, ``\xNN`` and ``\uNNNN``. ``\xNN`` takes a hex value and inserts the appropriate byte, while ``\uNNNN`` takes a Unicode codepoint and inserts an UTF-8 sequence.
+::
+
+ "\n\"\'\\abc\
+ def"
+
+Any unicode line terminator which is not a newline (i.e. LF, VF, FF, CR, NEL, LS, PS) is considered to
+terminate the string literal. Newline only terminates the string literal if it is not preceded by a ``\``.
.. index:: literal, bytes
@@ -419,8 +447,9 @@ Enums
-----
Enums are one way to create a user-defined type in Solidity. They are explicitly convertible
-to and from all integer types but implicit conversion is not allowed. The explicit conversions
-check the value ranges at runtime and a failure causes an exception. Enums needs at least one member.
+to and from all integer types but implicit conversion is not allowed. The explicit conversion
+from integer checks at runtime that the value lies inside the range of the enum and causes a failing assert otherwise.
+Enums needs at least one member.
The data representation is the same as for enums in C: The options are represented by
subsequent unsigned integer values starting from ``0``.
@@ -488,6 +517,11 @@ omitted. Note that this only applies to function types. Visibility has
to be specified explicitly for functions defined in contracts, they
do not have a default.
+Conversions:
+
+A value of external function type can be explicitly converted to ``address``
+resulting in the address of the contract of the function.
+
A function type ``A`` is implicitly convertible to a function type ``B`` if and only if
their parameter types are identical, their return types are identical,
their internal/external property is identical and the state mutability of ``A``
@@ -497,7 +531,7 @@ is not more restrictive than the state mutability of ``B``. In particular:
- ``view`` functions can be converted to ``non-payable`` functions
- ``payable`` functions can be converted to ``non-payable`` functions
-No other conversions are possible.
+No other conversions between function types are possible.
The rule about ``payable`` and ``non-payable`` might be a little
confusing, but in essence, if a function is ``payable``, this means that it
@@ -517,7 +551,9 @@ Note that public functions of the current contract can be used both as an
internal and as an external function. To use ``f`` as an internal function,
just use ``f``, if you want to use its external form, use ``this.f``.
-Additionally, public (or external) functions also have a special member called ``selector``,
+Members:
+
+Public (or external) functions also have a special member called ``selector``,
which returns the :ref:`ABI function selector <abi_function_selector>`::
pragma solidity ^0.4.16;