Merge pull request #858 from Denton-L/quotes-docs

Document existence of single-quotes
This commit is contained in:
chriseth 2016-08-12 15:20:02 +02:00 committed by GitHub
commit c389f894b5
4 changed files with 24 additions and 12 deletions

View File

@ -337,7 +337,7 @@ Inline assembly parses comments, literals and identifiers exactly as Solidity, s
usual ``//`` and ``/* */`` comments. Inline assembly is initiated by ``assembly { ... }`` and inside usual ``//`` and ``/* */`` comments. Inline assembly is initiated by ``assembly { ... }`` and inside
these curly braces, the following can be used (see the later sections for more details) these curly braces, the following can be used (see the later sections for more details)
- literals, i.e. ``0x123``, ``42`` or ``"abc"`` (strings up to 32 characters) - literals, e.g. ``0x123``, ``42`` or ``"abc"`` (strings up to 32 characters)
- opcodes (in "instruction style"), e.g. ``mload sload dup1 sstore``, for a list see below - opcodes (in "instruction style"), e.g. ``mload sload dup1 sstore``, for a list see below
- opcodes in functional style, e.g. ``add(1, mlod(0))`` - opcodes in functional style, e.g. ``add(1, mlod(0))``
- labels, e.g. ``name:`` - labels, e.g. ``name:``

View File

@ -399,7 +399,7 @@ What character set does Solidity use?
===================================== =====================================
Solidity is character set agnostic concerning strings in the source code, although Solidity is character set agnostic concerning strings in the source code, although
utf-8 is recommended. Identifiers (variables, functions, ...) can only use UTF-8 is recommended. Identifiers (variables, functions, ...) can only use
ASCII. ASCII.
What are some examples of basic string manipulation (``substring``, ``indexOf``, ``charAt``, etc)? What are some examples of basic string manipulation (``substring``, ``indexOf``, ``charAt``, etc)?
@ -741,15 +741,15 @@ see a 32-byte hex value, this is just ``"stringliteral"`` in hex.
The type ``bytes`` is similar, only that it can change its length. The type ``bytes`` is similar, only that it can change its length.
Finally, ``string`` is basically identical to ``bytes`` only that it is assumed Finally, ``string`` is basically identical to ``bytes`` only that it is assumed
to hold the utf-8 encoding of a real string. Since ``string`` stores the to hold the UTF-8 encoding of a real string. Since ``string`` stores the
data in utf-8 encoding it is quite expensive to compute the number of data in UTF-8 encoding it is quite expensive to compute the number of
characters in the string (the encoding of some characters takes more characters in the string (the encoding of some characters takes more
than a single byte). Because of that, ``string s; s.length`` is not yet than a single byte). Because of that, ``string s; s.length`` is not yet
supported and not even index access ``s[2]``. But if you want to access supported and not even index access ``s[2]``. But if you want to access
the low-level byte encoding of the string, you can use the low-level byte encoding of the string, you can use
``bytes(s).length`` and ``bytes(s)[2]`` which will result in the number ``bytes(s).length`` and ``bytes(s)[2]`` which will result in the number
of bytes in the utf-8 encoding of the string (not the number of of bytes in the UTF-8 encoding of the string (not the number of
characters) and the second byte (not character) of the utf-8 encoded characters) and the second byte (not character) of the UTF-8 encoded
string, respectively. string, respectively.

View File

@ -118,7 +118,7 @@ Source File Encoding
UTF-8 or ASCII encoding is preferred. UTF-8 or ASCII encoding is preferred.
Imports Imports
========== =======
Import statements should always be placed at the top of the file. Import statements should always be placed at the top of the file.
@ -519,6 +519,18 @@ No::
Other Recommendations Other Recommendations
===================== =====================
* Strings should be quoted with double-quotes instead of single-quotes.
Yes::
str = "foo";
str = "Hamlet says, 'To be or not to be...'";
No::
str = 'bar';
str = '"Be yourself; everyone else is already taken." -Oscar Wilde';
* Surround operators with a single space on either side. * Surround operators with a single space on either side.
Yes:: Yes::

View File

@ -147,10 +147,10 @@ Dynamically-sized byte array
``bytes``: ``bytes``:
Dynamically-sized byte array, see :ref:`arrays`. Not a value-type! Dynamically-sized byte array, see :ref:`arrays`. Not a value-type!
``string``: ``string``:
Dynamically-sized UTF8-encoded string, see :ref:`arrays`. Not a value-type! Dynamically-sized UTF-8-encoded string, see :ref:`arrays`. Not a value-type!
As a rule of thumb, use ``bytes`` for arbitrary-length raw byte data and ``string`` As a rule of thumb, use ``bytes`` for arbitrary-length raw byte data and ``string``
for arbitrary-length string (utf-8) data. If you can limit the length to a certain for arbitrary-length string (UTF-8) data. If you can limit the length to a certain
number of bytes, always use one of ``bytes1`` to ``bytes32`` because they are much cheaper. number of bytes, always use one of ``bytes1`` to ``bytes32`` because they are much cheaper.
.. index:: ! ufixed, ! fixed, ! fixed point number .. index:: ! ufixed, ! fixed, ! fixed point number
@ -214,9 +214,9 @@ a non-rational number).
String Literals String Literals
--------------- ---------------
String Literals are written with double quotes (``"abc"``). 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'``). 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 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 UTF8 sequence. 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.
.. index:: enum .. index:: enum
@ -353,7 +353,7 @@ So ``bytes`` should always be preferred over ``byte[]`` because it is cheaper.
.. note:: .. note::
If you want to access the byte-representation of a string ``s``, use If you want to access the byte-representation of a string ``s``, use
``bytes(s).length`` / ``bytes(s)[7] = 'x';``. Keep in mind ``bytes(s).length`` / ``bytes(s)[7] = 'x';``. Keep in mind
that you are accessing the low-level bytes of the utf-8 representation, that you are accessing the low-level bytes of the UTF-8 representation,
and not the individual characters! and not the individual characters!
.. index:: ! array;allocating, new .. index:: ! array;allocating, new