//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.21; contract SimpleStore { struct slice { uint _len; uint _ptr; } function startsWith(slice memory self, slice memory needle) internal pure returns (bool) { if (self._len < needle._len) { return false; } if (self._ptr == needle._ptr) { return true; } bool equal; assembly { let length := mload(needle) let selfptr := mload(add(self, 0x20)) let needleptr := mload(add(needle, 0x20)) equal := eq(keccak256(selfptr, length), keccak256(needleptr, length)) } return equal; } function toSlice(string memory self) internal pure returns (slice memory) { uint ptr; assembly { ptr := add(self, 0x20) } return slice(bytes(self).length, ptr); } function testStartsWith(string memory needle, string memory haystick) public pure returns (bool) { slice memory needleSlice = toSlice(needle); slice memory haystickSlice = toSlice(haystick); return startsWith(haystickSlice, needleSlice); } uint value; }
0.4.21