• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SetProtocol / set-protocol-v2 / 95e257dc-e7fb-44d4-bde1-25abd89770a6

pending completion
95e257dc-e7fb-44d4-bde1-25abd89770a6

push

circleci

GitHub
Brian/apy rescue fix (#270)

1160 of 1160 branches covered (100.0%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

3213 of 3213 relevant lines covered (100.0%)

248.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/contracts/lib/StringArrayUtils.sol
1
/*
2
    Copyright 2021 Set Labs Inc.
3

4
    Licensed under the Apache License, Version 2.0 (the "License");
5
    you may not use this file except in compliance with the License.
6
    You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
    Unless required by applicable law or agreed to in writing, software
11
    distributed under the License is distributed on an "AS IS" BASIS,
12
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
    See the License for the specific language governing permissions and
14
    limitations under the License.
15

16
    SPDX-License-Identifier: Apache License, Version 2.0
17
*/
18

19
pragma solidity 0.6.10;
20

21
/**
22
 * @title StringArrayUtils
23
 * @author Set Protocol
24
 *
25
 * Utility functions to handle String Arrays
26
 */
27
library StringArrayUtils {
28

29
    /**
30
     * Finds the index of the first occurrence of the given element.
31
     * @param A The input string to search
32
     * @param a The value to find
33
     * @return Returns (index and isIn) for the first occurrence starting from index 0
34
     */
35
    function indexOf(string[] memory A, string memory a) internal pure returns (uint256, bool) {
36
        uint256 length = A.length;
5✔
37
        for (uint256 i = 0; i < length; i++) {
5✔
38
            if (keccak256(bytes(A[i])) == keccak256(bytes(a))) {
13✔
39
                return (i, true);
3✔
40
            }
41
        }
42
        return (uint256(-1), false);
2✔
43
    }
44

45
    /**
46
     * @param A The input array to search
47
     * @param a The string to remove
48
     */
49
    function removeStorage(string[] storage A, string memory a)
50
        internal
51
    {
52
        (uint256 index, bool isIn) = indexOf(A, a);
3✔
53
        if (!isIn) {
3✔
54
            revert("String not in array.");
1✔
55
        } else {
56
            uint256 lastIndex = A.length - 1; // If the array would be empty, the previous line would throw, so no underflow here
2✔
57
            if (index != lastIndex) { A[index] = A[lastIndex]; }
2✔
58
            A.pop();
2✔
59
        }
60
    }
61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc