Created
September 15, 2016 05:13
-
-
Save bertani/1b63c8416e7f0bb6f618745d13905c76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract LCS { | |
function toLowerCase(string _in){// returns (string){ | |
bytes memory _out_b = bytes(_in); | |
byte tmp; | |
for (uint i=0; i<_out_b.length; i++){ | |
tmp = _out_b[i]; | |
if (tmp < 91) _out_b[i] = byte(int(tmp)+32); | |
} | |
//return string(_out_b); | |
} | |
function toLowerCase_asm(string _in){// returns (string){ | |
assembly { | |
let ptr := add(_in, 32) | |
let str := mload(ptr) | |
let offset := 0 | |
let char := 0 | |
loop: | |
char := byte(offset, str) | |
jumpi(end, eq(char, 0)) | |
jumpi(toLower, lt(char, 91)) | |
jump(skip) | |
toLower: | |
mstore8(add(ptr, offset), add(char, 32)) | |
skip: | |
offset := add(offset, 1) | |
jumpi(end, eq(offset, 32)) | |
jump(loop) | |
end: | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment