• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2012 The Libphonenumber Authors
2 
3 #include <algorithm>
4 #include "geocoding_warpper.h"
5 #include "phonenumbers/geocoding/phonenumber_offline_geocoder.h"
6 #include "phonenumbers/phonenumberutil.h"
7 #include <iostream>
8 #include <string>
9 #include <stdlib.h>
10 #include <unicode/unistr.h>  // NOLINT(build/include_order)
11 #include <unicode/locid.h>
12 
13 using icu::UnicodeString;
14 using i18n::phonenumbers::PhoneNumber;
15 using i18n::phonenumbers::PhoneNumberUtil;
16 using i18n::phonenumbers::PhoneNumberOfflineGeocoder;
17 using icu::Locale;
18 
exposeLocationName(const char * pNumber,const char * locale,char * res)19 extern "C" void exposeLocationName(const char* pNumber, const char* locale, char* res) {
20     if(offlineGeocoder == NULL) {
21         offlineGeocoder = new PhoneNumberOfflineGeocoder();
22     }
23     if (util == NULL) {
24         util = PhoneNumberUtil::GetInstance();
25     }
26     icu::Locale uLocale = icu::Locale::createFromName(locale);
27     i18n::phonenumbers::PhoneNumber phoneNumber;
28     std::string number = pNumber;
29     PhoneNumberUtil::ErrorType type = util->Parse(number, uLocale.getCountry(), &phoneNumber);
30     if (type != PhoneNumberUtil::ErrorType::NO_PARSING_ERROR) {
31         std::string empty = "";
32         std::strcpy(res, empty.c_str());
33     }
34     std::string result = offlineGeocoder->GetDescriptionForNumber(phoneNumber, uLocale);
35     std::strcpy(res, result.c_str());
36 }
37 
38