This function processes an input string that contains an ISBN (or a compound string
where the first element is the ISBN). It first removes unwanted characters (keeping only digits, commas, and spaces),
then uses the GoFish
function to further process the string. The function splits the cleaned string by spaces or commas
to extract a candidate ISBN. If the candidate ISBN is in ISBN10 format, it is converted to ISBN13 by prepending "978",
recalculating the check digit, and concatenating the result. Finally, the function validates that the resulting ISBN is a valid ISBN13,
i.e., it is 13 digits long and starts with either "978" or "979".
Value
A cleaned and validated ISBN string. If the resulting ISBN does not meet the expected criteria,
the function returns NULL
.
Details
The function performs the following steps:
Cleans the input
key
by removing all characters except digits, commas, and spaces.Processes the cleaned key using the
GoFish
function (which must be defined in your environment).Splits the resulting string by spaces and commas to extract the first candidate ISBN.
If the candidate is in ISBN10 format (10 characters), it converts it to ISBN13 by:
Converting the first 9 digits to numeric.
Prepending the ISBN13 prefix "978".
Calculating the ISBN13 check digit using alternating weights of 1 and 3.
Concatenating the digits to form the full ISBN13.
Validates that the final key is a valid ISBN13 (i.e., 13 digits long and starting with "978" or "979").