cpp/src/phonenumbers/phonenumberutil.cc
// Strips any extension (as in, the part of the number dialled after the call is
// connected, usually indicated with extn, ext, x or similar) from the end of
// the number, and returns it. The number passed in should be non-normalized.
Strips any extension (as in, the part of the number dialled after the call is
connected, usually indicated with extn, ext, x or similar) from the end of
the number, and returns it. The number passed in should be non-normalized.
Strips any extension ( as in the part of the number dialled after the call is connected usually indicated with extn ext x or similar ) from the end of the number and returns it . The number passed in should be non - normalized .
bool PhoneNumberUtil::MaybeStripExtension(string* number,  std::string* extension)
    const {
  DCHECK(number);
  DCHECK(extension);
  string possible_extension_one;
  string possible_extension_two;
  string possible_extension_three;
  string possible_extension_four;
  string possible_extension_five;
  string possible_extension_six;
  string number_copy(*number);
  const scoped_ptr<RegExpInput> number_copy_as_regexp_input(
      reg_exps_->regexp_factory_->CreateInput(number_copy));
  if (reg_exps_->extn_pattern_->Consume(
          number_copy_as_regexp_input.get(), false, &possible_extension_one,
          &possible_extension_two, &possible_extension_three,
          &possible_extension_four, &possible_extension_five,
          &possible_extension_six)) {
    reg_exps_->extn_pattern_->Replace(&number_copy, "");
    if ((!possible_extension_one.empty() || !possible_extension_two.empty() ||
         !possible_extension_three.empty() ||
         !possible_extension_four.empty() || !possible_extension_five.empty() ||
         !possible_extension_six.empty()) &&
        IsViablePhoneNumber(number_copy)) {
      number->assign(number_copy);
      if (!possible_extension_one.empty()) {
        extension->assign(possible_extension_one);
      } else if (!possible_extension_two.empty()) {
        extension->assign(possible_extension_two);
      } else if (!possible_extension_three.empty()) {
        extension->assign(possible_extension_three);
      } else if (!possible_extension_four.empty()) {
        extension->assign(possible_extension_four);
      } else if (!possible_extension_five.empty()) {
        extension->assign(possible_extension_five);
      } else if (!possible_extension_six.empty()) {
        extension->assign(possible_extension_six);
      }
      return true;
    }
  }
  return false;
}
bool PhoneNumberUtil :: MaybeStripExtension ( string * number , std :: string * extension ) const { DCHECK ( number ) ; DCHECK ( extension ) ; string possible_extension_one ; string possible_extension_two ; string possible_extension_three ; string possible_extension_four ; string possible_extension_five ; string possible_extension_six ; string number_copy ( * number ) ; const scoped_ptr < RegExpInput > number_copy_as_regexp_input ( reg_exps_ -> regexp_factory_ -> CreateInput ( number_copy ) ) ; if ( reg_exps_ -> extn_pattern_ -> Consume ( number_copy_as_regexp_input . get ( ) , false , & possible_extension_one , & possible_extension_two , & possible_extension_three , & possible_extension_four , & possible_extension_five , & possible_extension_six ) ) { reg_exps_ -> extn_pattern_ -> Replace ( & number_copy , " " ) ; if ( ( ! possible_extension_one . empty ( ) || ! possible_extension_two . empty ( ) || ! possible_extension_three . empty ( ) || ! possible_extension_four . empty ( ) || ! possible_extension_five . empty ( ) || ! possible_extension_six . empty ( ) ) && IsViablePhoneNumber ( number_copy ) ) { number -> assign ( number_copy ) ; if ( ! possible_extension_one . empty ( ) ) { extension -> assign ( possible_extension_one ) ; } else if ( ! possible_extension_two . empty ( ) ) { extension -> assign ( possible_extension_two ) ; } else if ( ! possible_extension_three . empty ( ) ) { extension -> assign ( possible_extension_three ) ; } else if ( ! possible_extension_four . empty ( ) ) { extension -> assign ( possible_extension_four ) ; } else if ( ! possible_extension_five . empty ( ) ) { extension -> assign ( possible_extension_five ) ; } else if ( ! possible_extension_six . empty ( ) ) { extension -> assign ( possible_extension_six ) ; } return true ; } } return false ; }
Strips any extension (as in, the part of the number dialled after the call is
connected, usually indicated with extn, ext, x or similar) from the end of
the number, and returns it.
Strips any extension ( as in the part of the number dialled after the call is connected usually indicated with extn ext x or similar ) from the end of the number and returns it .
// There are six extension capturing groups in the regular expression. // Replace the extensions in the original string here. // If we find a potential extension, and the number preceding this is a // viable number, we assume it is an extension.