Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import re
- def rjust( s , n , c ):
- return c * ( n - len( s ) ) + s
- def u32( n ):
- return int( ''.join( rjust( hex( ord( _ ) )[2:] , 2 , '0' ) for _ in n[::-1] ) , 16 )
- def strcmp( str1 , str2 ):
- _str2 = [ u32( _ ) for _ in re.findall( '.' * 4 , str2 ) ]
- l = len( str1 )
- i = -4
- while not ( l <= 0 and l - 4 == -4 ):
- if l - 4 < 0:
- break
- i += 4
- tmp = u32( str1[ i : i + 4 ] )
- if tmp != _str2[ i / 4 ]:
- return -1 if tmp < _str2[ i / 4 ] else 1;
- l -= 4
- i += 4
- a = i - len( str1 )
- b = a < 0
- if ( b and str1[ i ] != str2[ i ] ) or ( b and str1[ i + 1 ] != str2[ i + 1 ] and a < -1 ) or ( b and str1[ i + 2 ] != str2[ i + 2 ] and a < -2 ):
- r = str1[ i ] < str2[ i ] if b and str1[ i ] != str2[ i ] else False
- r = str1[ i + 1 ] < str2[ i + 1 ] if b and str1[ i + 1 ] != str2[ i + 1 ] and a < -1 else r
- r = str1[ i + 2 ] < str2[ i + 2 ] if b and str1[ i + 2 ] != str2[ i + 2 ] and a < -2 else r
- r = 1 if r else 0
- r *= -1
- return r | 1
- return 0
Add Comment
Please, Sign In to add comment