• 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 #include "securec.h"
13 
14 using icu::UnicodeString;
15 using i18n::phonenumbers::PhoneNumber;
16 using i18n::phonenumbers::PhoneNumberUtil;
17 using i18n::phonenumbers::PhoneNumberOfflineGeocoder;
18 using icu::Locale;
19 
exposeLocationName(const char * pNumber,const char * locale,char * res,const int resLength=128)20 extern "C" int exposeLocationName(const char* pNumber, const char* locale, char* res, const int resLength = 128) {
21     if(offlineGeocoder == NULL) {
22         offlineGeocoder = new PhoneNumberOfflineGeocoder();
23     }
24     if (util == NULL) {
25         util = PhoneNumberUtil::GetInstance();
26     }
27     icu::Locale uLocale = icu::Locale::createFromName(locale);
28     i18n::phonenumbers::PhoneNumber phoneNumber;
29     std::string number = pNumber;
30     PhoneNumberUtil::ErrorType type = util->Parse(number, uLocale.getCountry(), &phoneNumber);
31     if (type != PhoneNumberUtil::ErrorType::NO_PARSING_ERROR) {
32         std::string empty = "";
33         return strcpy_s(res, resLength, empty.c_str());
34     }
35     std::string result = offlineGeocoder->GetDescriptionForNumber(phoneNumber, uLocale);
36     return strcpy_s(res, resLength, result.c_str());
37 }
38 
39