in matcher.go [18:45]
func ContainsOnlyValidXChars(number *PhoneNumber, candidate string) bool {
// The characters 'x' and 'X' can be (1) a carrier code, in which
// case they always precede the national significant number or (2)
// an extension sign, in which case they always precede the extension
// number. We assume a carrier code is more than 1 digit, so the first
// case has to have more than 1 consecutive 'x' or 'X', whereas the
// second case can only have exactly 1 'x' or 'X'. We ignore the
// character if it appears as the last character of the string.
for index := 0; index < len(candidate)-1; index++ {
var charAtIndex = candidate[index]
if charAtIndex == 'x' || charAtIndex == 'X' {
var charAtNextIndex = candidate[index+1]
if charAtNextIndex == 'x' || charAtNextIndex == 'X' {
// This is the carrier code case, in which the 'X's
// always precede the national significant number.
index++
if IsNumberMatchWithOneNumber(number, candidate[index:]) != NSN_MATCH {
return false
}
// This is the extension sign case, in which the 'x'
// or 'X' should always precede the extension number.
} else if NormalizeDigitsOnly(candidate[index:]) != number.GetExtension() {
return false
}
}
}
return true
}