Skip to content

Commit c389f89

Browse files
authored
Merge pull request #858 from Denton-L/quotes-docs
Document existence of single-quotes
2 parents 04db7b0 + 1634a79 commit c389f89

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

docs/control-structures.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ Inline assembly parses comments, literals and identifiers exactly as Solidity, s
337337
usual ``//`` and ``/* */`` comments. Inline assembly is initiated by ``assembly { ... }`` and inside
338338
these curly braces, the following can be used (see the later sections for more details)
339339

340-
- literals, i.e. ``0x123``, ``42`` or ``"abc"`` (strings up to 32 characters)
340+
- literals, e.g. ``0x123``, ``42`` or ``"abc"`` (strings up to 32 characters)
341341
- opcodes (in "instruction style"), e.g. ``mload sload dup1 sstore``, for a list see below
342342
- opcodes in functional style, e.g. ``add(1, mlod(0))``
343343
- labels, e.g. ``name:``

docs/frequently-asked-questions.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ What character set does Solidity use?
399399
=====================================
400400

401401
Solidity is character set agnostic concerning strings in the source code, although
402-
utf-8 is recommended. Identifiers (variables, functions, ...) can only use
402+
UTF-8 is recommended. Identifiers (variables, functions, ...) can only use
403403
ASCII.
404404

405405
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.
741741
The type ``bytes`` is similar, only that it can change its length.
742742

743743
Finally, ``string`` is basically identical to ``bytes`` only that it is assumed
744-
to hold the utf-8 encoding of a real string. Since ``string`` stores the
745-
data in utf-8 encoding it is quite expensive to compute the number of
744+
to hold the UTF-8 encoding of a real string. Since ``string`` stores the
745+
data in UTF-8 encoding it is quite expensive to compute the number of
746746
characters in the string (the encoding of some characters takes more
747747
than a single byte). Because of that, ``string s; s.length`` is not yet
748748
supported and not even index access ``s[2]``. But if you want to access
749749
the low-level byte encoding of the string, you can use
750750
``bytes(s).length`` and ``bytes(s)[2]`` which will result in the number
751-
of bytes in the utf-8 encoding of the string (not the number of
752-
characters) and the second byte (not character) of the utf-8 encoded
751+
of bytes in the UTF-8 encoding of the string (not the number of
752+
characters) and the second byte (not character) of the UTF-8 encoded
753753
string, respectively.
754754

755755

docs/style-guide.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Source File Encoding
118118
UTF-8 or ASCII encoding is preferred.
119119

120120
Imports
121-
==========
121+
=======
122122

123123
Import statements should always be placed at the top of the file.
124124

@@ -519,6 +519,18 @@ No::
519519
Other Recommendations
520520
=====================
521521

522+
* Strings should be quoted with double-quotes instead of single-quotes.
523+
524+
Yes::
525+
526+
str = "foo";
527+
str = "Hamlet says, 'To be or not to be...'";
528+
529+
No::
530+
531+
str = 'bar';
532+
str = '"Be yourself; everyone else is already taken." -Oscar Wilde';
533+
522534
* Surround operators with a single space on either side.
523535

524536
Yes::

docs/types.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ Dynamically-sized byte array
147147
``bytes``:
148148
Dynamically-sized byte array, see :ref:`arrays`. Not a value-type!
149149
``string``:
150-
Dynamically-sized UTF8-encoded string, see :ref:`arrays`. Not a value-type!
150+
Dynamically-sized UTF-8-encoded string, see :ref:`arrays`. Not a value-type!
151151

152152
As a rule of thumb, use ``bytes`` for arbitrary-length raw byte data and ``string``
153-
for arbitrary-length string (utf-8) data. If you can limit the length to a certain
153+
for arbitrary-length string (UTF-8) data. If you can limit the length to a certain
154154
number of bytes, always use one of ``bytes1`` to ``bytes32`` because they are much cheaper.
155155

156156
.. index:: ! ufixed, ! fixed, ! fixed point number
@@ -214,9 +214,9 @@ a non-rational number).
214214
String Literals
215215
---------------
216216

217-
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``.
217+
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``.
218218

219-
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.
219+
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.
220220

221221
.. index:: enum
222222

@@ -353,7 +353,7 @@ So ``bytes`` should always be preferred over ``byte[]`` because it is cheaper.
353353
.. note::
354354
If you want to access the byte-representation of a string ``s``, use
355355
``bytes(s).length`` / ``bytes(s)[7] = 'x';``. Keep in mind
356-
that you are accessing the low-level bytes of the utf-8 representation,
356+
that you are accessing the low-level bytes of the UTF-8 representation,
357357
and not the individual characters!
358358

359359
.. index:: ! array;allocating, new

0 commit comments

Comments
 (0)