Skip to content

Instantly share code, notes, and snippets.

@0xKD
Created September 26, 2017 17:19
Show Gist options
  • Save 0xKD/8ce78109092c85ddec7602f3aae6ca5d to your computer and use it in GitHub Desktop.
Save 0xKD/8ce78109092c85ddec7602f3aae6ca5d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include "phonenumbers/phonenumberutil.h"
using i18n::phonenumbers::PhoneNumber;
using i18n::phonenumbers::PhoneNumberUtil;
using namespace std;
const PhoneNumberUtil &util = *PhoneNumberUtil::GetInstance();
string format_number(string phone) {
string formatted;
PhoneNumber number;
util.Parse(phone, "IN", &number);
util.Format(number, PhoneNumberUtil::E164, &formatted);
if (!util.IsValidNumber(number)) {
return "";
}
return formatted;
}
int main() {
for (string line; getline(cin, line);) {
cout<<format_number(line)<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment