Skip to content

Commit 6faf899

Browse files
committed
more docs
1 parent eaedbb8 commit 6faf899

File tree

8 files changed

+42
-370
lines changed

8 files changed

+42
-370
lines changed

docs/strings/Strings.md

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,21 @@
11
# Strings
22

3-
4-
53
**Package:** strings
64

75
**Contract type:** Static library
86

97
**Source file:** [Strings.sol](../../src/strings/Strings.sol)
108

11-
129
**Example usage:** [StringsExamples.sol](../../examples/strings/StringsExamples.sol)
1310

14-
1511
**Tests source file:** [strings_tests.sol](../../test/strings/strings_tests.sol)
1612

17-
1813
**Perf (gas usage) source file:** [strings_perfs.sol](../../perf/strings/strings_perfs.sol)
1914

20-
2115
## description
2216

2317
This library can be used to validate that a solidity string is valid UTF-8.
2418

2519
Solidity strings uses the UTF-8 encoding, as defined in the unicode 10.0 standard: http://www.unicode.org/versions/Unicode10.0.0/, but the only checks that are currently carried out are compile-time checks of string literals. This library makes runtime checks possible.
2620

2721
The idea to add a UTF string validation library came from Arachnid's (Nick Johnson) string-utils: https://github.com/Arachnid/solidity-stringutils
28-
29-
## Functions
30-
31-
- [validate(string memory)](#validatestring-memory)
32-
- [parseRune(uint)](#parseruneuint)
33-
34-
***
35-
36-
### validate(string memory)
37-
38-
`function validate(string memory self) internal pure returns (bool)`
39-
40-
Check that a string is proper UTF-8. No gas benchmark as it is simply an aggregate of the cost of validating each rune (benchmarks for that can be found in the docs for [parseRune(uint)](#parseruneuint).
41-
42-
##### params
43-
44-
- `string memory self`: The string.
45-
46-
47-
##### returns
48-
49-
- `bool`: `true` if the string is valid UTF-8.
50-
51-
##### ensures
52-
53-
- See the library description.
54-
55-
***
56-
57-
### parseRune(uint)
58-
59-
`function parseRune(uint bytepos) internal pure returns (uint len)`
60-
61-
Check that a rune is valid UTF-8. The rune is provided as a pointer to a byte in memory.
62-
63-
##### params
64-
65-
- `uint bytepos`: The memory address where the rune is stored.
66-
67-
68-
##### returns
69-
70-
- `uint len`: The length of the rune in bytes.
71-
72-
##### ensures
73-
74-
- See the library description.
75-
##### gascosts
76-
77-
- Parsing a rune of length one: **291**
78-
- Parsing a rune of length two: **512**
79-
- Parsing a rune of length three: **746**
80-
- Parsing a rune of length four: **1000**
81-

docs/unsafe/Memory.md

Lines changed: 0 additions & 281 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
**Source file:** [Memory.sol](../../src/unsafe/Memory.sol)
88

9-
**Example usage:** [MemoryExamples.sol](../../examples/unsafe/MemoryExamples.sol)
10-
119
**Tests source file:** [memory.sol](../../test/unsafe/memory.sol)
1210

1311
**Perf (gas usage) source file:** [memory.sol](../../perf/unsafe/memory.sol)
@@ -18,282 +16,3 @@
1816
The `unsafe` package contains code that performs potentially unsafe operations, for example reading and writing directly from memory. The memory library is used to work with memory directly; there are methods for copying memory, equals-checks, and converting from and to Solidity types.
1917

2018
In these docs, the word stored at memory address `n` is denoted `Memory[n]`. It is implicitly of type `uint`, but the regular index access syntax is used to point to individual bytes, e.g. byte number `m` of the word stored at address `n` is `Memory[n][m]`. Additionally, the free memory pointer is referred to `FMP`.
21-
22-
## Functions
23-
24-
- [equals(uint, uint, uint)](#equalsuint-uint-uint)
25-
- [equals(uint, uint, bytes memory)](#equalsuint-uint-bytes-memory)
26-
- [allocate(uint)](#allocateuint)
27-
- [copy(uint, uint, uint)](#copyuint-uint-uint)
28-
- [ptr(bytes)](#ptrbytes)
29-
- [dataPtr(bytes)](#dataptrbytes)
30-
- [fromBytes(bytes)](#frombytesbytes)
31-
- [toBytes(uint, uint)](#tobytesuint-uint)
32-
- [toUint(uint)](#touintuint)
33-
- [toBytes32(uint)](#tobytes32uint)
34-
- [toByte(uint, uint8)](#tobyteuint-uint8)
35-
36-
***
37-
38-
### equals(uint, uint, uint)
39-
40-
`function equals(uint addr, uint addr2, uint len) internal pure returns (bool)`
41-
42-
Checks if the data stored in two segments of memory is the same.
43-
44-
##### params
45-
46-
- `uint addr`: The first memory address.
47-
- `uint addr2`: The second memory address.
48-
- `uint len`: The number of bytes to check.
49-
50-
51-
##### returns
52-
53-
- `bool`: `true` if the bytes are equal, otherwise false.
54-
55-
##### ensures
56-
57-
- `equals(addr1, addr2, len) => 'n' in [0, len), Memory[addr1 + n][0] == Memory[addr2 + n][0]`
58-
##### gascosts
59-
60-
- Equals check of 16 bytes: **149**
61-
- Equals check of one word: **149**
62-
- Equals check of ten words: **278**
63-
- Equals check of one hundred words: **1647**
64-
65-
***
66-
67-
### equals(uint, uint, bytes memory)
68-
69-
`function equals(uint addr, uint len, bytes memory bts) internal pure returns (bool)`
70-
71-
Checks if the data stored in a segment of memory is the same as (part of) the data stored by a `bytes memory`.
72-
73-
##### params
74-
75-
- `uint addr`: The memory address.
76-
- `uint len`: The number of bytes to check.
77-
- `bytes memory bts`: The bytes array.
78-
79-
##### requires
80-
81-
- len <= bts.length
82-
83-
##### returns
84-
85-
- `bool`: `true` if the bytes are equal, otherwise false.
86-
87-
##### ensures
88-
89-
- `equals(addr, len, bts) => 'n' in [0, len), Memory[addr + n][0] == uint8(bts[n])`
90-
##### gascosts
91-
92-
- Equals check of one word: **256**
93-
94-
***
95-
96-
### allocate(uint)
97-
98-
`function allocate(uint numBytes) internal pure returns (uint addr)`
99-
100-
Allocates a section of memory, and initializes the bytes to `0`.
101-
102-
##### params
103-
104-
- `uint numBytes`: The number of bytes that should be allocated.
105-
106-
107-
##### returns
108-
109-
- `uint addr`: The (starting) address of the newly allocated segment.
110-
111-
##### ensures
112-
113-
- `addr = allocate(len) => FMP += len && for 'n' in [0, len), Memory[addr + n] == 0`
114-
##### gascosts
115-
116-
- Allocation of one word: **245**
117-
- Allocation of ten words: **983**
118-
119-
***
120-
121-
### copy(uint, uint, uint)
122-
123-
`function copy(uint src, uint dest, uint len) internal pure`
124-
125-
Copy a segment of memory.
126-
127-
##### params
128-
129-
- `uint src`: The source address.
130-
- `uint dest`: The destination address.
131-
- `uint len`: The number of bytes to copy.
132-
133-
134-
135-
##### ensures
136-
137-
- `copy(src, dest, len) => for 'n' in [0, len), Memory[dest + n][0] == Memory[src + n][0]`
138-
##### gascosts
139-
140-
- Copying 16 bytes: **210**
141-
- Copying one word: **307**
142-
- Copying ten words: **1153**
143-
144-
***
145-
146-
### ptr(bytes)
147-
148-
`function ptr(bytes bts) internal pure returns (uint addr)`
149-
150-
Get a memory pointer to a `bytes` array.
151-
152-
##### params
153-
154-
- `bytes bts`: The `bytes` array.
155-
156-
157-
##### returns
158-
159-
- `uint addr`: The pointer to the `bytes` in memory.
160-
161-
##### gascosts
162-
163-
- Fixed: **55**
164-
165-
***
166-
167-
### dataPtr(bytes)
168-
169-
`function dataPtr(bytes bts) internal pure returns (uint addr)`
170-
171-
Get a memory pointer to the data section of a `bytes` array.
172-
173-
##### params
174-
175-
- `bytes bts`: The `bytes` array.
176-
177-
178-
##### returns
179-
180-
- `uint addr`: The pointer to the data section of the `bytes` in memory.
181-
182-
##### gascosts
183-
184-
- Fixed: **61**
185-
186-
***
187-
188-
### fromBytes(bytes)
189-
190-
`function fromBytes(bytes bts) internal pure returns (uint addruint len)`
191-
192-
Get the address of the data stored by a `bytes memory`, and its length.
193-
194-
##### params
195-
196-
- `bytes bts`: The `bytes`.
197-
198-
199-
##### returns
200-
201-
- `uint addr`: The pointer to the data section of the `bytes` in memory.
202-
- `uint len`: The length of the `bytes`.
203-
204-
##### gascosts
205-
206-
- Fixed: **77**
207-
208-
***
209-
210-
### toBytes(uint, uint)
211-
212-
`function toBytes(uint addr, uint len) internal pure returns (bytes memory bts)`
213-
214-
Create a `bytes memory` from a starting address and a length. NOTE this will copy the bytes.
215-
216-
##### params
217-
218-
- `uint addr`: The memory address.
219-
- `uint len`: The length.
220-
221-
222-
##### returns
223-
224-
- `bytes memory bts`: The new `bytes` array.
225-
226-
##### gascosts
227-
228-
- Create a one word long byte array: **532**
229-
230-
***
231-
232-
### toUint(uint)
233-
234-
`function toUint(uint addr) internal pure returns (uint n)`
235-
236-
Get a word of memory as a `uint`
237-
238-
##### params
239-
240-
- `uint addr`: The memory address.
241-
242-
243-
##### returns
244-
245-
- `uint n`: The word as a `uint`.
246-
247-
##### gascosts
248-
249-
- Fixed: **58**
250-
251-
***
252-
253-
### toBytes32(uint)
254-
255-
`function toBytes32(uint addr) internal pure returns (bytes32 bts)`
256-
257-
Get a word of memory as a `bytes32`
258-
259-
##### params
260-
261-
- `uint addr`: The memory address.
262-
263-
264-
##### returns
265-
266-
- `bytes32 bts`: The word as a `bytes32`.
267-
268-
##### gascosts
269-
270-
- Fixed: **58**
271-
272-
***
273-
274-
### toByte(uint, uint8)
275-
276-
`function toByte(uint addr, uint8 index) internal pure returns (byte b)`
277-
278-
Get a single byte from memory.
279-
280-
##### params
281-
282-
- `uint addr`: The memory address.
283-
- `uint8 index`: The index of the byte.
284-
285-
##### requires
286-
287-
- `0 <= index < 32`
288-
289-
##### returns
290-
291-
- `byte b`: The byte.
292-
293-
##### ensures
294-
295-
- `b = toByte(addr, index) => b == toBytes32(addr)[index]`
296-
##### gascosts
297-
298-
- Fixed: **125**
299-

0 commit comments

Comments
 (0)