Skip to content

Commit fb9aac4

Browse files
committedFeb 3, 2023
add example
1 parent 98c0ba6 commit fb9aac4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
 

‎contracts/utils/ShortStrings.sol

+19
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@ type ShortString is bytes32;
1111
* into a `ShortString` type that can be used as an immutable variable.
1212
* Strings of arbitrary length can be optimized if they are short enough by
1313
* the addition of a storage variable used as fallback.
14+
*
15+
* Usage example:
16+
*
17+
* ```solidity
18+
* contract Named {
19+
* using ShortStrings for *;
20+
*
21+
* ShortString private immutable _name;
22+
* string private _nameFallback;
23+
*
24+
* constructor(string memory contractName) {
25+
* _name = contractName.toShortStringWithFallback(_nameFallback);
26+
* }
27+
*
28+
* function name() external view returns (string memory) {
29+
* return _name.toStringWithFallback(_nameFallback);
30+
* }
31+
* }
32+
* ```
1433
*/
1534
library ShortStrings {
1635
error StringTooLong(string str);

0 commit comments

Comments
 (0)