Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/contracts/mixins/SemVerMixin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ abstract contract SemVerMixin is ISemVerMixin {
/// @return The major version string (e.g., "1" for version "1.2.3")
function _majorVersion() internal view returns (string memory) {
bytes memory v = bytes(_VERSION.toString());
return string(abi.encodePacked(v[0]));
uint256 start;

// Skip optional 'v'/'V' prefix to keep only the numeric major component.
if (v.length > 0 && (v[0] == 0x76 || v[0] == 0x56)) {
start = 1;
}

uint256 end = start;
while (end < v.length && v[end] != 0x2e) {
unchecked {
++end;
}
}

bytes memory major = new bytes(end - start);
for (uint256 i = start; i < end; ++i) {
major[i - start] = v[i];
}

return string(major);
}
}