Detect and display countryname on it's countrycode

Hello all!
have the following task: I need to detect the country using it’s code in callerid(num) and then display callerid in format callerid(num)-CountryName on the internal phone calls will be routed to.
I’m going to use internal AstDB to store countries and their codes using following structure:

Country/Country1 Code1
Country/Country2 Code2

The question is how to perform parsing of incoming callerid(num) field using asterisk dialplan functions.
The difficulty is that country code lenght is not a constant…

I’d suggest using it as the extension field in in subroutine, although you could also use the called/caller notation to match it without making it an extension.

Do you mean:
DID/+{countrycode1}X.
Set (CALLERID(name)=country1)
Dial(SIP/internalextension)

DID/+{countrycode2}X.
Set (CALLERID(name)=country2)
Dial(SIP/internalextension)

?
Looks like this can solve my task, will try it.