@@ -12,101 +12,101 @@ library EnvUtils {
1212 string memory envPath = ".env " ;
1313 string memory addressString = vm.toString (value);
1414 string memory targetVar = string .concat (variableName, "= " );
15-
15+
1616 // Check if file exists
1717 if (! vm.exists (envPath)) {
1818 console.log (".env file not found " );
1919 return ;
2020 }
21-
21+
2222 // Read the entire file
2323 string memory content = vm.readFile (envPath);
2424 string [] memory lines = splitLines (content);
25-
25+
2626 // Process lines and make updates
2727 string memory newContent = "" ;
2828 bool found = false ;
29-
30- for (uint i = 0 ; i < lines.length ; i++ ) {
29+
30+ for (uint256 i = 0 ; i < lines.length ; i++ ) {
3131 string memory currentLine = lines[i];
32-
32+
3333 // Check if this is the line we want to replace
3434 if (startsWith (currentLine, targetVar)) {
3535 currentLine = string .concat (targetVar, addressString);
3636 found = true ;
3737 }
38-
38+
3939 // Add line to new content
4040 if (i > 0 ) {
4141 newContent = string .concat (newContent, "\n " );
4242 }
4343 newContent = string .concat (newContent, currentLine);
4444 }
45-
45+
4646 // If not found, append it
4747 if (! found) {
4848 newContent = string .concat (newContent, "\n " , targetVar, addressString);
4949 }
50-
50+
5151 // Write back to file
5252 vm.writeFile (envPath, newContent);
5353 console.log ("Updated .env file with new " , variableName, ": " , addressString);
5454 }
55-
55+
5656 // Helper function to split a string by newlines
5757 function splitLines (string memory _content ) internal pure returns (string [] memory ) {
5858 bytes memory content = bytes (_content);
59-
59+
6060 // Count the number of lines
61- uint lineCount = 1 ;
62- for (uint i = 0 ; i < content.length ; i++ ) {
61+ uint256 lineCount = 1 ;
62+ for (uint256 i = 0 ; i < content.length ; i++ ) {
6363 if (content[i] == bytes1 ("\n " )) {
6464 lineCount++ ;
6565 }
6666 }
67-
67+
6868 // Split the content
6969 string [] memory lines = new string [](lineCount);
70- uint lineStart = 0 ;
71- uint currentLine = 0 ;
72-
73- for (uint i = 0 ; i < content.length ; i++ ) {
70+ uint256 lineStart = 0 ;
71+ uint256 currentLine = 0 ;
72+
73+ for (uint256 i = 0 ; i < content.length ; i++ ) {
7474 if (content[i] == bytes1 ("\n " ) || i == content.length - 1 ) {
75- uint lineEnd = i;
75+ uint256 lineEnd = i;
7676 if (i == content.length - 1 && content[i] != bytes1 ("\n " )) {
7777 lineEnd = i + 1 ;
7878 }
79-
79+
8080 // Extract line
8181 bytes memory line = new bytes (lineEnd - lineStart);
82- for (uint j = lineStart; j < lineEnd; j++ ) {
82+ for (uint256 j = lineStart; j < lineEnd; j++ ) {
8383 line[j - lineStart] = content[j];
8484 }
85-
85+
8686 lines[currentLine] = string (line);
8787 currentLine++ ;
8888 lineStart = i + 1 ;
8989 }
9090 }
91-
91+
9292 return lines;
9393 }
94-
94+
9595 // Helper function to check if a string starts with a prefix
9696 function startsWith (string memory _str , string memory _prefix ) internal pure returns (bool ) {
9797 bytes memory str = bytes (_str);
9898 bytes memory prefix = bytes (_prefix);
99-
99+
100100 if (str.length < prefix.length ) {
101101 return false ;
102102 }
103-
104- for (uint i = 0 ; i < prefix.length ; i++ ) {
103+
104+ for (uint256 i = 0 ; i < prefix.length ; i++ ) {
105105 if (str[i] != prefix[i]) {
106106 return false ;
107107 }
108108 }
109-
109+
110110 return true ;
111111 }
112112}
0 commit comments