Modul:Citation/utilities: Unterschied zwischen den Versionen
+cu.getNbnDeCheckDigit( urn )
Keine Bearbeitungszusammenfassung |
(+cu.getNbnDeCheckDigit( urn )) |
||
| Zeile 277: | Zeile 277: | ||
function cu.templateStyles( frame ) | function cu.templateStyles( frame ) | ||
return frame:extensionTag( 'templatestyles', '', { src = ci.styleSrc } ); | return frame:extensionTag( 'templatestyles', '', { src = ci.styleSrc } ); | ||
end | |||
-- See: https://github.com/bohnelang/URN-Pruefziffer | |||
function cu.getNbnDeCheckDigit( urn ) | |||
local code='3947450102030405060708094117############1814191516212223242542262713282931123233113435363738########43' | |||
local sum = 0 | |||
local pos = 1 | |||
local digit1, digit2, x | |||
urn = urn:upper():sub( 1, -2 ) -- remove last character | |||
for i = 1, urn:len() do | |||
x = 2 * ( urn:byte( i ) - 45 ); -- - == '-' | |||
digit1 = tonumber( code:sub( x + 1, x + 1 ) ); | |||
digit2 = tonumber( code:sub( x + 2, x + 2 ) ); | |||
if digit1 == 0 then | |||
sum = sum + digit2 * pos | |||
pos = pos + 1 | |||
else | |||
sum = sum + digit1 * pos + digit2 * ( pos + 1 ) | |||
pos = pos + 2 | |||
end | |||
end | |||
return tostring( math.floor( sum / digit2 ) % 10 ); | |||
end | |||
function cu.checkUrnDe( urn ) | |||
return urn:sub( -1 ) == cu.getNbnDeCheckDigit( urn ) | |||
end | end | ||
return cu | return cu | ||