From fb9aac41318402ebe7976fe7b9e5abc25fee8d9b Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Fri, 3 Feb 2023 22:57:42 +0100 Subject: [PATCH] add example --- contracts/utils/ShortStrings.sol | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/contracts/utils/ShortStrings.sol b/contracts/utils/ShortStrings.sol index 4cbef6d6d82..9f253df8267 100644 --- a/contracts/utils/ShortStrings.sol +++ b/contracts/utils/ShortStrings.sol @@ -11,6 +11,25 @@ type ShortString is bytes32; * into a `ShortString` type that can be used as an immutable variable. * Strings of arbitrary length can be optimized if they are short enough by * the addition of a storage variable used as fallback. + * + * Usage example: + * + * ```solidity + * contract Named { + * using ShortStrings for *; + * + * ShortString private immutable _name; + * string private _nameFallback; + * + * constructor(string memory contractName) { + * _name = contractName.toShortStringWithFallback(_nameFallback); + * } + * + * function name() external view returns (string memory) { + * return _name.toStringWithFallback(_nameFallback); + * } + * } + * ``` */ library ShortStrings { error StringTooLong(string str);