50 lines
1.6 KiB
Plaintext
50 lines
1.6 KiB
Plaintext
include "NSLog.incl"
|
|
|
|
local fn VerifyCUSIP( cusipStr as CFStringRef ) as CFStringRef
|
|
NSUInteger i, v, sum = 0, count = len(cusipStr)
|
|
CFStringRef resultStr
|
|
|
|
if count != 9 then exit fn = @"Invalid length"
|
|
|
|
for i = 0 to 7
|
|
unichar x = fn StringCharacterAtIndex( cusipStr, i )
|
|
select x
|
|
case _"*" : v = 36
|
|
case _"@" : v = 37
|
|
case _"#" : v = 38
|
|
case else
|
|
if ( x >= _"0" and x <= _"9" )
|
|
v = x - _"0"
|
|
else
|
|
if ( x >= _"A" and x <= _"Z" )
|
|
v = x - _"A" + 10
|
|
else
|
|
exit fn = fn StringWithFormat( @"Invalid character: %c", x )
|
|
end if
|
|
end if
|
|
end select
|
|
|
|
if ( i and 1 ) then v = v * 2
|
|
|
|
sum += (v / 10) + (v mod 10)
|
|
next
|
|
sum = ((10-(sum mod 10)) mod 10)
|
|
|
|
if (sum == ( fn StringCharacterAtIndex( cusipStr, 8 ) - _"0" ))
|
|
resultStr = @"Valid"
|
|
else
|
|
resultStr = @"Invalid"
|
|
end If
|
|
end fn = resultStr
|
|
|
|
NSLog( @"0378331009: %@", fn VerifyCUSIP( @"0378331009" ) ) // Invalid length expected
|
|
NSLog( @"037833100: %@", fn VerifyCUSIP( @"037833100" ) ) // Valid expected
|
|
NSLog( @"17275R102: %@", fn VerifyCUSIP( @"17275R102" ) ) // Valid expected
|
|
NSLog( @"38259P508: %@", fn VerifyCUSIP( @"38259P508" ) ) // Valid expected
|
|
NSLog( @"594918104: %@", fn VerifyCUSIP( @"594918104" ) ) // Valid expected
|
|
NSLog( @"68389X106: %@", fn VerifyCUSIP( @"68389X106" ) ) // Invalid expected
|
|
NSLog( @"68389X105: %@", fn VerifyCUSIP( @"68389X105" ) ) // Valid expected
|
|
NSLog( @"683&9X105: %@", fn VerifyCUSIP( @"683&9X105" ) ) // Invalid character expected: &
|
|
|
|
HandleEvents
|